diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llanimalcontrols.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llanimalcontrols.cpp')
-rw-r--r-- | linden/indra/newview/llanimalcontrols.cpp | 454 |
1 files changed, 454 insertions, 0 deletions
diff --git a/linden/indra/newview/llanimalcontrols.cpp b/linden/indra/newview/llanimalcontrols.cpp new file mode 100644 index 0000000..8bafe86 --- /dev/null +++ b/linden/indra/newview/llanimalcontrols.cpp | |||
@@ -0,0 +1,454 @@ | |||
1 | /** | ||
2 | * @file llanimalcontrols.cpp | ||
3 | * @brief LLAnimalControl class implementation | ||
4 | * | ||
5 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llanimalcontrols.h" | ||
31 | #include "llglheaders.h" | ||
32 | #include "llsphere.h" | ||
33 | #include "llrand.h" | ||
34 | #include "llviewerobject.h" | ||
35 | |||
36 | /* | ||
37 | //const F32 ANIMAL_CONTROLS_MAX_TENSION_FORCE = 0.99f;// I'll explain in a minute... | ||
38 | //const F32 ANIMAL_CONTROLS_MINIMUM_RADIUS = 0.005f; | ||
39 | |||
40 | const F32 OPACITY = 1.0f; | ||
41 | const int _X_ = 0; | ||
42 | const int _Y_ = 1; | ||
43 | const int _Z_ = 2; | ||
44 | const F32 BODY_RADIUS = 0.2f; | ||
45 | const F32 HEAD_RADIUS = 0.1f; | ||
46 | const F32 ONE_HALF = 0.5f; | ||
47 | |||
48 | //----------------------------------------------- | ||
49 | // constructor | ||
50 | //----------------------------------------------- | ||
51 | LLHUDAnimalControls::LLHUDAnimalControls() | ||
52 | : LLHUDObject( LL_HUD_ANIMAL_CONTROLS )// cal the base class and pass this in, K? | ||
53 | { | ||
54 | mParentObject = NULL; | ||
55 | |||
56 | }//------------------------------------------------------------------------------ | ||
57 | |||
58 | |||
59 | |||
60 | |||
61 | //--------------------------------------------------------------------------------- | ||
62 | //--------------------------------------------------------------------------------- | ||
63 | // Virtual Server methods... | ||
64 | //--------------------------------------------------------------------------------- | ||
65 | //--------------------------------------------------------------------------------- | ||
66 | LLAnimalControlsVirtualServer::LLAnimalControlsVirtualServer() | ||
67 | { | ||
68 | focusPosition.setVec( 0.0f, 0.0f, 0.0f ); | ||
69 | animalPosition.setVec( 0.0f, 0.0f, 0.0f ); | ||
70 | animalRotation = LLQuaternion::DEFAULT; | ||
71 | fakeClock = 0; | ||
72 | settingFocusPosition = false; | ||
73 | |||
74 | }//--------------------------------------------------------------------------------- | ||
75 | |||
76 | |||
77 | |||
78 | //--------------------------------------------------------------------------------- | ||
79 | void LLAnimalControlsVirtualServer::update() | ||
80 | { | ||
81 | fakeClock ++; | ||
82 | |||
83 | if ( settingFocusPosition ) | ||
84 | { | ||
85 | settingFocusPosition = false; | ||
86 | } | ||
87 | |||
88 | if ( fakeClock == 20 ) | ||
89 | { | ||
90 | fakeClock = 0; | ||
91 | |||
92 | settingFocusPosition = true; | ||
93 | |||
94 | LLMatrix3 bodyRotationMatrix = animalRotation.getMatrix3(); | ||
95 | |||
96 | LLVector3 forwardDirection = bodyRotationMatrix.getLeftRow(); | ||
97 | LLVector3 leftDirection = bodyRotationMatrix.getFwdRow(); | ||
98 | |||
99 | forwardDirection.mV[_Z_] = 0.0f; | ||
100 | forwardDirection.normVec(); | ||
101 | |||
102 | focusPosition = animalPosition + forwardDirection * 5.0f; | ||
103 | |||
104 | F32 leftRightSpan = 5.0f; | ||
105 | |||
106 | F32 randomSpan = gLindenLabRandomNumber.llfrand( leftRightSpan ); | ||
107 | |||
108 | focusPosition += leftDirection * ( - leftRightSpan * ONE_HALF + randomSpan ); | ||
109 | } | ||
110 | |||
111 | }//------------------------------------------------------------------------------ | ||
112 | |||
113 | |||
114 | |||
115 | //--------------------------------------------------------------------------------- | ||
116 | bool LLAnimalControlsVirtualServer::getSettingFocusPosition() | ||
117 | { | ||
118 | return settingFocusPosition; | ||
119 | |||
120 | }//------------------------------------------------------------------------------ | ||
121 | |||
122 | //--------------------------------------------------------------------------------- | ||
123 | LLVector3 LLAnimalControlsVirtualServer::getFocusPosition() | ||
124 | { | ||
125 | return focusPosition; | ||
126 | |||
127 | }//------------------------------------------------------------------------------ | ||
128 | |||
129 | |||
130 | //--------------------------------------------------------------------------------- | ||
131 | void LLAnimalControlsVirtualServer::setParentPositionAndRotation( LLVector3 p, LLQuaternion r ) | ||
132 | { | ||
133 | animalPosition = p; | ||
134 | animalRotation = r; | ||
135 | |||
136 | }//------------------------------------------------------------------------------ | ||
137 | |||
138 | //--------------------------------------------------------------------------------- | ||
139 | //--------------------------------------------------------------------------------- | ||
140 | // End of Virtual Server methods... | ||
141 | //--------------------------------------------------------------------------------- | ||
142 | //--------------------------------------------------------------------------------- | ||
143 | |||
144 | |||
145 | |||
146 | |||
147 | //--------------------------------------------------------------------------------- | ||
148 | //--------------------------------------------------------------------------------- | ||
149 | // Head behavior methods... | ||
150 | //--------------------------------------------------------------------------------- | ||
151 | //--------------------------------------------------------------------------------- | ||
152 | LLAnimalControlsHeadBehavior::LLAnimalControlsHeadBehavior() | ||
153 | { | ||
154 | mPosition.setVec ( 0.0f, 0.0f, 0.0f ); | ||
155 | mFocusPosition.setVec ( 0.0f, 0.0f, 0.0f ); | ||
156 | mBodyPosition.setVec ( 0.0f, 0.0f, 0.0f ); | ||
157 | mRotation = LLQuaternion::DEFAULT; | ||
158 | mEyesBlinking = true; | ||
159 | mEyeBlinkRate = 0.1f; | ||
160 | mBodyRotation = LLQuaternion::DEFAULT; | ||
161 | |||
162 | LLFlexibleObjectAttributes headFeatherAttributes; | ||
163 | headFeatherAttributes.mAnchorPositionOffset.setVec( 0.0f, 0.0f, 0.1f ); | ||
164 | headFeatherAttributes.mAnchorDirection.setVec( 0.0f, 1.0f, 1.0f ); | ||
165 | headFeatherAttributes.mAnchorDirection.normVec(); | ||
166 | headFeatherAttributes.mColor = LLColor4( 1.0f, 0.4f, 0.0f, 1.0f ); | ||
167 | headFeatherAttributes.mAnchorRadius = 0.01f; | ||
168 | headFeatherAttributes.mLength = 0.4f; | ||
169 | headFeatherAttributes.mEndRadius = 0.06f; | ||
170 | headFeatherAttributes.mRenderStyle = "tube"; | ||
171 | |||
172 | mFeather.setAttributes( headFeatherAttributes ); | ||
173 | |||
174 | }//------------------------------------------------------------------ | ||
175 | |||
176 | //------------------------------------------------------------------ | ||
177 | void LLAnimalControlsHeadBehavior::setBodyPositionAndRotation( LLVector3 p, LLQuaternion r ) | ||
178 | { | ||
179 | mBodyPosition = p; | ||
180 | mBodyRotation = r; | ||
181 | |||
182 | }//------------------------------------------------------------------ | ||
183 | |||
184 | //------------------------------------------------------------------ | ||
185 | void LLAnimalControlsHeadBehavior::setFocusPosition( LLVector3 f ) | ||
186 | { | ||
187 | mFocusPosition = f; | ||
188 | |||
189 | }//------------------------------------------------------------------ | ||
190 | |||
191 | |||
192 | //------------------------------------------------------------------ | ||
193 | void LLAnimalControlsHeadBehavior::update() | ||
194 | { | ||
195 | //-------------------------------------------------------------------------- | ||
196 | // Let's get the parent orientation and associated components | ||
197 | //-------------------------------------------------------------------------- | ||
198 | LLQuaternion parentOrientation = mBodyRotation; | ||
199 | LLMatrix3 parentMatrix = parentOrientation.getMatrix3(); | ||
200 | LLVector3 parentForwardDirection = parentMatrix.getLeftRow(); | ||
201 | LLVector3 parentUpwardDirection = parentMatrix.getUpRow(); | ||
202 | |||
203 | //-------------------------------------------------------------------------- | ||
204 | // head position is based on this | ||
205 | //-------------------------------------------------------------------------- | ||
206 | mPosition = mBodyPosition + parentForwardDirection * 0.5f + parentUpwardDirection * 0.5f; | ||
207 | |||
208 | //-------------------------------------------------------------------------------------------------- | ||
209 | // let's figure out how the head would have to rotate in order to aim in the focus direction | ||
210 | //-------------------------------------------------------------------------------------------------- | ||
211 | LLVector3 headFocusDirection = mFocusPosition - mPosition; | ||
212 | LLQuaternion headRotationToFocusDirection; | ||
213 | headRotationToFocusDirection.shortestArc( parentForwardDirection, headFocusDirection ); | ||
214 | |||
215 | //-------------------------------------------------------------------------------------------------- | ||
216 | // Now we rotate the head towards its focus direction | ||
217 | //-------------------------------------------------------------------------------------------------- | ||
218 | mRotation = parentOrientation * headRotationToFocusDirection; | ||
219 | |||
220 | //-------------------------------------------------------------------------------------------------- | ||
221 | // now, setting the head feather position and orientation, and updating it... | ||
222 | //-------------------------------------------------------------------------------------------------- | ||
223 | mFeather.setParentPositionAndRotationDirectly( mPosition, mRotation ); | ||
224 | mFeather.update(); | ||
225 | |||
226 | }//------------------------------------------------------------------ | ||
227 | |||
228 | //------------------------------------------------------------------ | ||
229 | |||
230 | |||
231 | { | ||
232 | //-------------------------------------------------------------------------------------------------- | ||
233 | // let's get the head rotation components... | ||
234 | //-------------------------------------------------------------------------------------------------- | ||
235 | LLMatrix3 headMatrix = mRotation.getMatrix3(); | ||
236 | LLVector3 headForwardDirection = headMatrix.getLeftRow(); | ||
237 | LLVector3 headUpwardDirection = headMatrix.getUpRow(); | ||
238 | LLVector3 headLeftDirection = headMatrix.getFwdRow(); | ||
239 | |||
240 | //------------------------------------------------------ | ||
241 | // show head ball | ||
242 | //------------------------------------------------------ | ||
243 | glColor4fv( LLColor4( 1.0f, 1.0f, 1.0f, OPACITY ).mV ); | ||
244 | glPushMatrix(); | ||
245 | glTranslatef( mPosition.mV[_X_], mPosition.mV[_Y_], mPosition.mV[_Z_] ); | ||
246 | glScalef( HEAD_RADIUS, HEAD_RADIUS, HEAD_RADIUS ); | ||
247 | gSphere.render(); | ||
248 | glPopMatrix(); | ||
249 | |||
250 | //------------------------------------------------------ | ||
251 | // show head direction | ||
252 | //------------------------------------------------------ | ||
253 | LLVector3 end = mPosition + headForwardDirection * 0.4f; | ||
254 | glBegin( GL_LINES ); | ||
255 | glVertex3fv( mPosition.mV ); | ||
256 | glVertex3fv( end.mV ); | ||
257 | glEnd(); | ||
258 | |||
259 | |||
260 | //------------------------------------------------------ | ||
261 | // show eye behavior | ||
262 | //------------------------------------------------------ | ||
263 | LLVector3 leftEyePosition = mPosition + headForwardDirection * HEAD_RADIUS + headUpwardDirection * HEAD_RADIUS + headLeftDirection * HEAD_RADIUS * ONE_HALF; | ||
264 | LLVector3 rightEyePosition = mPosition + headForwardDirection * HEAD_RADIUS + headUpwardDirection * HEAD_RADIUS - headLeftDirection * HEAD_RADIUS * ONE_HALF; | ||
265 | glColor4fv( LLColor4( 0.0f, 0.0f, 0.0f, 1.0f ).mV ); | ||
266 | |||
267 | glPushMatrix(); | ||
268 | glTranslatef( leftEyePosition.mV[_X_], leftEyePosition.mV[_Y_], leftEyePosition.mV[_Z_] ); | ||
269 | glScalef( 0.03f, 0.03f, 0.03f ); | ||
270 | gSphere.render(); | ||
271 | glPopMatrix(); | ||
272 | |||
273 | glPushMatrix(); | ||
274 | glTranslatef( rightEyePosition.mV[_X_], rightEyePosition.mV[_Y_], rightEyePosition.mV[_Z_] ); | ||
275 | glScalef( 0.03f, 0.03f, 0.03f ); | ||
276 | gSphere.render(); | ||
277 | glPopMatrix(); | ||
278 | |||
279 | //------------------------------------------------------------------ | ||
280 | // render feather | ||
281 | //------------------------------------------------------------------ | ||
282 | mFeather.render(); | ||
283 | |||
284 | }//------------------------------------------------------------------ | ||
285 | |||
286 | //--------------------------------------------------------------------------------- | ||
287 | //--------------------------------------------------------------------------------- | ||
288 | // End of head behavior methods... | ||
289 | //--------------------------------------------------------------------------------- | ||
290 | //--------------------------------------------------------------------------------- | ||
291 | |||
292 | |||
293 | |||
294 | |||
295 | //--------------------------------------------------------------------------------- | ||
296 | //--------------------------------------------------------------------------------- | ||
297 | // Leg behavior methods... | ||
298 | //--------------------------------------------------------------------------------- | ||
299 | //--------------------------------------------------------------------------------- | ||
300 | LLAnimalControlsLegBehavior::LLAnimalControlsLegBehavior() | ||
301 | { | ||
302 | mBodyPosition.setVec ( 0.0f, 0.0f, 0.0f ); | ||
303 | mHipAnchorPosition.setVec ( 0.0f, 0.0f, 0.0f ); | ||
304 | mBodyRotation = LLQuaternion::DEFAULT; | ||
305 | mWalking = false; | ||
306 | mIsLeft = true; | ||
307 | |||
308 | }//------------------------------------------------------------- | ||
309 | |||
310 | |||
311 | //------------------------------------------------------------------ | ||
312 | void LLAnimalControlsLegBehavior::setBodyPositionAndRotation( LLVector3 p, LLQuaternion r ) | ||
313 | { | ||
314 | mBodyPosition = p; | ||
315 | mBodyRotation = r; | ||
316 | |||
317 | }//------------------------------------------------------------------ | ||
318 | |||
319 | |||
320 | //--------------------------------------------------------------------------------- | ||
321 | void LLAnimalControlsLegBehavior::update() | ||
322 | { | ||
323 | |||
324 | }//------------------------------------------------------------- | ||
325 | |||
326 | |||
327 | //--------------------------------------------------------------------------------- | ||
328 | void LLAnimalControlsLegBehavior::render() | ||
329 | { | ||
330 | }//------------------------------------------------------------- | ||
331 | |||
332 | |||
333 | |||
334 | |||
335 | |||
336 | |||
337 | |||
338 | |||
339 | //--------------------------------------------------------------------------------- | ||
340 | void LLHUDAnimalControls::update() | ||
341 | { | ||
342 | if ( ! mParentObject ) | ||
343 | { | ||
344 | return; | ||
345 | } | ||
346 | |||
347 | //----------------------------------------------------------------------------------- | ||
348 | // To help in development of this client-side functionality, | ||
349 | // we are pretending that the server is periodically sending us information, | ||
350 | // such as focus position (what we want the animal head to look at) | ||
351 | //----------------------------------------------------------------------------------- | ||
352 | mVirtualServer.setParentPositionAndRotation( mParentObject->getRenderPosition(), mParentObject->getRenderRotation() ); // fake, hacky, temporary, just ignore this. | ||
353 | mVirtualServer.update(); | ||
354 | |||
355 | // here is where we ask the virtual server stuff. | ||
356 | if ( mVirtualServer.getSettingFocusPosition() ) | ||
357 | { | ||
358 | mHeadBehavior.setFocusPosition( mVirtualServer.getFocusPosition() ); | ||
359 | } | ||
360 | |||
361 | updateBodyBehavior(); | ||
362 | |||
363 | mHeadBehavior.setBodyPositionAndRotation ( mParentObject->getPosition(), mParentObject->getRenderRotation() ); | ||
364 | mLeftLegBehavior.setBodyPositionAndRotation ( mParentObject->getPosition(), mParentObject->getRenderRotation() ); | ||
365 | mRightLegBehavior.setBodyPositionAndRotation( mParentObject->getPosition(), mParentObject->getRenderRotation() ); | ||
366 | |||
367 | mHeadBehavior.update(); | ||
368 | mLeftLegBehavior.update(); | ||
369 | mRightLegBehavior.update(); | ||
370 | |||
371 | }//------------------------------------------------------------------ | ||
372 | |||
373 | |||
374 | |||
375 | |||
376 | |||
377 | //------------------------------------------------------------------ | ||
378 | void LLHUDAnimalControls::updateBodyBehavior() | ||
379 | { | ||
380 | |||
381 | }//------------------------------------------------------------------ | ||
382 | |||
383 | |||
384 | |||
385 | |||
386 | //------------------------------------------------------------------ | ||
387 | void LLHUDAnimalControls::render() | ||
388 | { | ||
389 | mHeadBehavior.render(); | ||
390 | mLeftLegBehavior.render(); | ||
391 | mRightLegBehavior.render(); | ||
392 | |||
393 | }//------------------------------------------------------------------ | ||
394 | |||
395 | |||
396 | |||
397 | |||
398 | |||
399 | |||
400 | |||
401 | |||
402 | |||
403 | //------------------------------------------------------------------ | ||
404 | void LLHUDAnimalControls::setAttributes( LLAnimalControlsAttributes a ) | ||
405 | { | ||
406 | //mAttributes = a; // ???? // how do I do this? | ||
407 | |||
408 | //mAttributes.mAnchorPositionOffset = a.mAnchorPositionOffset; | ||
409 | //mAttributes.mAnchorDirection = a.mAnchorDirection; | ||
410 | //mAttributes.mAnchorRadius = a.mAnchorRadius; | ||
411 | //mAttributes.mNumSections = a.mNumSections; | ||
412 | //mAttributes.mLength = a.mLength; | ||
413 | //mAttributes.mGravity = a.mGravity; | ||
414 | //mAttributes.mAirFriction = a.mAirFriction; | ||
415 | //mAttributes.mTension = a.mTension; | ||
416 | //mAttributes.mRadiusChange = a.mRadiusChange; | ||
417 | |||
418 | }//------------------------------------------------------------------ | ||
419 | |||
420 | |||
421 | |||
422 | //------------------------------------------------------------------ | ||
423 | void LLHUDAnimalControls::setParentObject( LLViewerObject * p ) | ||
424 | { | ||
425 | printf( "Setting parent of animal controls %x to object %x \n", this, p ); | ||
426 | mParentObject = p; | ||
427 | |||
428 | }//------------------------------------------------------------------ | ||
429 | |||
430 | |||
431 | //------------------------------------------------------------------ | ||
432 | LLViewerObject * LLHUDAnimalControls::getParentObject() | ||
433 | { | ||
434 | return mParentObject; | ||
435 | |||
436 | }//------------------------------------------------------------------ | ||
437 | |||
438 | |||
439 | |||
440 | //------------------------------------------------------------------ | ||
441 | void LLHUDAnimalControls::markAsDead() | ||
442 | { | ||
443 | mDead = TRUE; | ||
444 | mParentObject = NULL; | ||
445 | |||
446 | }//------------------------------------------------------------------ | ||
447 | |||
448 | |||
449 | |||
450 | |||
451 | */ | ||
452 | |||
453 | |||
454 | |||