aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcharacter/llheadrotmotion.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:27 -0500
committerJacek Antonelli2008-08-15 23:45:27 -0500
commita8a62201ba762e98dff92cf49033e577fc34d8d4 (patch)
tree11f8513c5cdc222f2fac0c93eb724c089803c200 /linden/indra/llcharacter/llheadrotmotion.cpp
parentSecond Life viewer sources 1.18.6.4-RC (diff)
downloadmeta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.zip
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.gz
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.bz2
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.xz
Second Life viewer sources 1.19.0.0
Diffstat (limited to 'linden/indra/llcharacter/llheadrotmotion.cpp')
-rw-r--r--linden/indra/llcharacter/llheadrotmotion.cpp73
1 files changed, 42 insertions, 31 deletions
diff --git a/linden/indra/llcharacter/llheadrotmotion.cpp b/linden/indra/llcharacter/llheadrotmotion.cpp
index e8afb82..f01dfcc 100644
--- a/linden/indra/llcharacter/llheadrotmotion.cpp
+++ b/linden/indra/llcharacter/llheadrotmotion.cpp
@@ -12,12 +12,12 @@
12 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of 13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or 14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2 15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 * 16 *
17 * There are special exceptions to the terms and conditions of the GPL as 17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception 18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or 19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception 20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 * 21 *
22 * By copying, modifying or distributing this software, you acknowledge 22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above, 23 * that you have read and understood your obligations described above,
@@ -82,6 +82,10 @@ LLHeadRotMotion::LLHeadRotMotion(const LLUUID &id) :
82 mHeadJoint(NULL) 82 mHeadJoint(NULL)
83{ 83{
84 mName = "head_rot"; 84 mName = "head_rot";
85
86 mTorsoState = new LLJointState;
87 mNeckState = new LLJointState;
88 mHeadState = new LLJointState;
85} 89}
86 90
87 91
@@ -130,34 +134,34 @@ LLMotion::LLMotionInitStatus LLHeadRotMotion::onInitialize(LLCharacter *characte
130 return STATUS_FAILURE; 134 return STATUS_FAILURE;
131 } 135 }
132 136
133 mTorsoState.setJoint( character->getJoint("mTorso") ); 137 mTorsoState->setJoint( character->getJoint("mTorso") );
134 if ( ! mTorsoState.getJoint() ) 138 if ( ! mTorsoState->getJoint() )
135 { 139 {
136 llinfos << getName() << ": Can't get torso joint." << llendl; 140 llinfos << getName() << ": Can't get torso joint." << llendl;
137 return STATUS_FAILURE; 141 return STATUS_FAILURE;
138 } 142 }
139 143
140 mNeckState.setJoint( character->getJoint("mNeck") ); 144 mNeckState->setJoint( character->getJoint("mNeck") );
141 if ( ! mNeckState.getJoint() ) 145 if ( ! mNeckState->getJoint() )
142 { 146 {
143 llinfos << getName() << ": Can't get neck joint." << llendl; 147 llinfos << getName() << ": Can't get neck joint." << llendl;
144 return STATUS_FAILURE; 148 return STATUS_FAILURE;
145 } 149 }
146 150
147 mHeadState.setJoint( character->getJoint("mHead") ); 151 mHeadState->setJoint( character->getJoint("mHead") );
148 if ( ! mHeadState.getJoint() ) 152 if ( ! mHeadState->getJoint() )
149 { 153 {
150 llinfos << getName() << ": Can't get head joint." << llendl; 154 llinfos << getName() << ": Can't get head joint." << llendl;
151 return STATUS_FAILURE; 155 return STATUS_FAILURE;
152 } 156 }
153 157
154 mTorsoState.setUsage(LLJointState::ROT); 158 mTorsoState->setUsage(LLJointState::ROT);
155 mNeckState.setUsage(LLJointState::ROT); 159 mNeckState->setUsage(LLJointState::ROT);
156 mHeadState.setUsage(LLJointState::ROT); 160 mHeadState->setUsage(LLJointState::ROT);
157 161
158 addJointState( &mTorsoState ); 162 addJointState( mTorsoState );
159 addJointState( &mNeckState ); 163 addJointState( mNeckState );
160 addJointState( &mHeadState ); 164 addJointState( mHeadState );
161 165
162 mLastHeadRot.loadIdentity(); 166 mLastHeadRot.loadIdentity();
163 167
@@ -240,16 +244,16 @@ BOOL LLHeadRotMotion::onUpdate(F32 time, U8* joint_mask)
240 // Set torso target rotation such that it lags behind the head rotation 244 // Set torso target rotation such that it lags behind the head rotation
241 // by a fixed amount. 245 // by a fixed amount.
242 LLQuaternion torso_rot_local = nlerp(TORSO_LAG, LLQuaternion::DEFAULT, head_rot_local ); 246 LLQuaternion torso_rot_local = nlerp(TORSO_LAG, LLQuaternion::DEFAULT, head_rot_local );
243 mTorsoState.setRotation( nlerp(torso_slerp_amt, mTorsoState.getRotation(), torso_rot_local) ); 247 mTorsoState->setRotation( nlerp(torso_slerp_amt, mTorsoState->getRotation(), torso_rot_local) );
244 248
245 head_rot_local = nlerp(head_slerp_amt, mLastHeadRot, head_rot_local); 249 head_rot_local = nlerp(head_slerp_amt, mLastHeadRot, head_rot_local);
246 mLastHeadRot = head_rot_local; 250 mLastHeadRot = head_rot_local;
247 251
248 // Set the head rotation. 252 // Set the head rotation.
249 LLQuaternion torsoRotLocal = mNeckState.getJoint()->getParent()->getWorldRotation() * currentInvRootRotWorld; 253 LLQuaternion torsoRotLocal = mNeckState->getJoint()->getParent()->getWorldRotation() * currentInvRootRotWorld;
250 head_rot_local = head_rot_local * ~torsoRotLocal; 254 head_rot_local = head_rot_local * ~torsoRotLocal;
251 mNeckState.setRotation( nlerp(NECK_LAG, LLQuaternion::DEFAULT, head_rot_local) ); 255 mNeckState->setRotation( nlerp(NECK_LAG, LLQuaternion::DEFAULT, head_rot_local) );
252 mHeadState.setRotation( nlerp(1.f - NECK_LAG, LLQuaternion::DEFAULT, head_rot_local)); 256 mHeadState->setRotation( nlerp(1.f - NECK_LAG, LLQuaternion::DEFAULT, head_rot_local));
253 257
254 return TRUE; 258 return TRUE;
255} 259}
@@ -284,6 +288,9 @@ LLEyeMotion::LLEyeMotion(const LLUUID &id) : LLMotion(id)
284 mHeadJoint = NULL; 288 mHeadJoint = NULL;
285 289
286 mName = "eye_rot"; 290 mName = "eye_rot";
291
292 mLeftEyeState = new LLJointState;
293 mRightEyeState = new LLJointState;
287} 294}
288 295
289 296
@@ -309,25 +316,25 @@ LLMotion::LLMotionInitStatus LLEyeMotion::onInitialize(LLCharacter *character)
309 return STATUS_FAILURE; 316 return STATUS_FAILURE;
310 } 317 }
311 318
312 mLeftEyeState.setJoint( character->getJoint("mEyeLeft") ); 319 mLeftEyeState->setJoint( character->getJoint("mEyeLeft") );
313 if ( ! mLeftEyeState.getJoint() ) 320 if ( ! mLeftEyeState->getJoint() )
314 { 321 {
315 llinfos << getName() << ": Can't get left eyeball joint." << llendl; 322 llinfos << getName() << ": Can't get left eyeball joint." << llendl;
316 return STATUS_FAILURE; 323 return STATUS_FAILURE;
317 } 324 }
318 325
319 mRightEyeState.setJoint( character->getJoint("mEyeRight") ); 326 mRightEyeState->setJoint( character->getJoint("mEyeRight") );
320 if ( ! mRightEyeState.getJoint() ) 327 if ( ! mRightEyeState->getJoint() )
321 { 328 {
322 llinfos << getName() << ": Can't get Right eyeball joint." << llendl; 329 llinfos << getName() << ": Can't get Right eyeball joint." << llendl;
323 return STATUS_FAILURE; 330 return STATUS_FAILURE;
324 } 331 }
325 332
326 mLeftEyeState.setUsage(LLJointState::ROT); 333 mLeftEyeState->setUsage(LLJointState::ROT);
327 mRightEyeState.setUsage(LLJointState::ROT); 334 mRightEyeState->setUsage(LLJointState::ROT);
328 335
329 addJointState( &mLeftEyeState ); 336 addJointState( mLeftEyeState );
330 addJointState( &mRightEyeState ); 337 addJointState( mRightEyeState );
331 338
332 return STATUS_SUCCESS; 339 return STATUS_SUCCESS;
333} 340}
@@ -443,11 +450,15 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
443 target_eye_rot = LLQuaternion(eye_look_at, left, up); 450 target_eye_rot = LLQuaternion(eye_look_at, left, up);
444 // convert target rotation to head-local coordinates 451 // convert target rotation to head-local coordinates
445 target_eye_rot *= ~mHeadJoint->getWorldRotation(); 452 target_eye_rot *= ~mHeadJoint->getWorldRotation();
453 // eliminate any Euler roll - we're lucky that roll is applied last.
454 F32 roll, pitch, yaw;
455 target_eye_rot.getEulerAngles(&roll, &pitch, &yaw);
456 target_eye_rot.setQuat(0.0f, pitch, yaw);
446 // constrain target orientation to be in front of avatar's face 457 // constrain target orientation to be in front of avatar's face
447 target_eye_rot.constrain(EYE_ROT_LIMIT_ANGLE); 458 target_eye_rot.constrain(EYE_ROT_LIMIT_ANGLE);
448 459
449 // calculate vergence 460 // calculate vergence
450 F32 interocular_dist = (mLeftEyeState.getJoint()->getWorldPosition() - mRightEyeState.getJoint()->getWorldPosition()).magVec(); 461 F32 interocular_dist = (mLeftEyeState->getJoint()->getWorldPosition() - mRightEyeState->getJoint()->getWorldPosition()).magVec();
451 vergence = -atan2((interocular_dist / 2.f), lookAtDistance); 462 vergence = -atan2((interocular_dist / 2.f), lookAtDistance);
452 llclamp(vergence, -F_PI_BY_TWO, 0.f); 463 llclamp(vergence, -F_PI_BY_TWO, 0.f);
453 } 464 }
@@ -495,8 +506,8 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
495 vergence_quat.transQuat(); 506 vergence_quat.transQuat();
496 right_eye_rot = vergence_quat * eye_jitter_rot * right_eye_rot; 507 right_eye_rot = vergence_quat * eye_jitter_rot * right_eye_rot;
497 508
498 mLeftEyeState.setRotation( left_eye_rot ); 509 mLeftEyeState->setRotation( left_eye_rot );
499 mRightEyeState.setRotation( right_eye_rot ); 510 mRightEyeState->setRotation( right_eye_rot );
500 511
501 return TRUE; 512 return TRUE;
502} 513}
@@ -507,13 +518,13 @@ BOOL LLEyeMotion::onUpdate(F32 time, U8* joint_mask)
507//----------------------------------------------------------------------------- 518//-----------------------------------------------------------------------------
508void LLEyeMotion::onDeactivate() 519void LLEyeMotion::onDeactivate()
509{ 520{
510 LLJoint* joint = mLeftEyeState.getJoint(); 521 LLJoint* joint = mLeftEyeState->getJoint();
511 if (joint) 522 if (joint)
512 { 523 {
513 joint->setRotation(LLQuaternion::DEFAULT); 524 joint->setRotation(LLQuaternion::DEFAULT);
514 } 525 }
515 526
516 joint = mRightEyeState.getJoint(); 527 joint = mRightEyeState->getJoint();
517 if (joint) 528 if (joint)
518 { 529 {
519 joint->setRotation(LLQuaternion::DEFAULT); 530 joint->setRotation(LLQuaternion::DEFAULT);