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/llcharacter/lltargetingmotion.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/llcharacter/lltargetingmotion.cpp')
-rw-r--r-- | linden/indra/llcharacter/lltargetingmotion.cpp | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/lltargetingmotion.cpp b/linden/indra/llcharacter/lltargetingmotion.cpp new file mode 100644 index 0000000..799e4d0 --- /dev/null +++ b/linden/indra/llcharacter/lltargetingmotion.cpp | |||
@@ -0,0 +1,170 @@ | |||
1 | /** | ||
2 | * @file lltargetingmotion.cpp | ||
3 | * @brief Implementation of LLTargetingMotion class. | ||
4 | * | ||
5 | * Copyright (c) 2001-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 | //----------------------------------------------------------------------------- | ||
29 | // Header Files | ||
30 | //----------------------------------------------------------------------------- | ||
31 | #include "linden_common.h" | ||
32 | |||
33 | #include "lltargetingmotion.h" | ||
34 | #include "llcharacter.h" | ||
35 | #include "v3dmath.h" | ||
36 | #include "llcriticaldamp.h" | ||
37 | |||
38 | //----------------------------------------------------------------------------- | ||
39 | // Constants | ||
40 | //----------------------------------------------------------------------------- | ||
41 | const F32 TORSO_TARGET_HALF_LIFE = 0.25f; | ||
42 | const F32 MAX_TIME_DELTA = 2.f; //max two seconds a frame for calculating interpolation | ||
43 | const F32 TARGET_PLANE_THRESHOLD_DOT = 0.6f; | ||
44 | const F32 TORSO_ROT_FRACTION = 0.5f; | ||
45 | |||
46 | //----------------------------------------------------------------------------- | ||
47 | // LLTargetingMotion() | ||
48 | // Class Constructor | ||
49 | //----------------------------------------------------------------------------- | ||
50 | LLTargetingMotion::LLTargetingMotion(const LLUUID &id) : LLMotion(id) | ||
51 | { | ||
52 | mCharacter = NULL; | ||
53 | mName = "targeting"; | ||
54 | } | ||
55 | |||
56 | |||
57 | //----------------------------------------------------------------------------- | ||
58 | // ~LLTargetingMotion() | ||
59 | // Class Destructor | ||
60 | //----------------------------------------------------------------------------- | ||
61 | LLTargetingMotion::~LLTargetingMotion() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | //----------------------------------------------------------------------------- | ||
66 | // LLTargetingMotion::onInitialize(LLCharacter *character) | ||
67 | //----------------------------------------------------------------------------- | ||
68 | LLMotion::LLMotionInitStatus LLTargetingMotion::onInitialize(LLCharacter *character) | ||
69 | { | ||
70 | // save character for future use | ||
71 | mCharacter = character; | ||
72 | |||
73 | mPelvisJoint = mCharacter->getJoint("mPelvis"); | ||
74 | mTorsoJoint = mCharacter->getJoint("mTorso"); | ||
75 | mRightHandJoint = mCharacter->getJoint("mWristRight"); | ||
76 | |||
77 | // make sure character skeleton is copacetic | ||
78 | if (!mPelvisJoint || | ||
79 | !mTorsoJoint || | ||
80 | !mRightHandJoint) | ||
81 | { | ||
82 | llwarns << "Invalid skeleton for targeting motion!" << llendl; | ||
83 | return STATUS_FAILURE; | ||
84 | } | ||
85 | |||
86 | mTorsoState.setJoint( mTorsoJoint ); | ||
87 | |||
88 | // add joint states to the pose | ||
89 | mTorsoState.setUsage(LLJointState::ROT); | ||
90 | addJointState( &mTorsoState ); | ||
91 | |||
92 | return STATUS_SUCCESS; | ||
93 | } | ||
94 | |||
95 | //----------------------------------------------------------------------------- | ||
96 | // LLTargetingMotion::onActivate() | ||
97 | //----------------------------------------------------------------------------- | ||
98 | BOOL LLTargetingMotion::onActivate() | ||
99 | { | ||
100 | return TRUE; | ||
101 | } | ||
102 | |||
103 | //----------------------------------------------------------------------------- | ||
104 | // LLTargetingMotion::onUpdate() | ||
105 | //----------------------------------------------------------------------------- | ||
106 | BOOL LLTargetingMotion::onUpdate(F32 time, U8* joint_mask) | ||
107 | { | ||
108 | F32 slerp_amt = LLCriticalDamp::getInterpolant(TORSO_TARGET_HALF_LIFE); | ||
109 | |||
110 | LLVector3 target; | ||
111 | LLVector3* lookAtPoint = (LLVector3*)mCharacter->getAnimationData("LookAtPoint"); | ||
112 | |||
113 | BOOL result = TRUE; | ||
114 | |||
115 | if (!lookAtPoint) | ||
116 | { | ||
117 | return TRUE; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | target = *lookAtPoint; | ||
122 | target.normVec(); | ||
123 | } | ||
124 | |||
125 | //LLVector3 target_plane_normal = LLVector3(1.f, 0.f, 0.f) * mPelvisJoint->getWorldRotation(); | ||
126 | //LLVector3 torso_dir = LLVector3(1.f, 0.f, 0.f) * (mTorsoJoint->getWorldRotation() * mTorsoState.getRotation()); | ||
127 | |||
128 | LLVector3 skyward(0.f, 0.f, 1.f); | ||
129 | LLVector3 left(skyward % target); | ||
130 | left.normVec(); | ||
131 | LLVector3 up(target % left); | ||
132 | up.normVec(); | ||
133 | LLQuaternion target_aim_rot(target, left, up); | ||
134 | |||
135 | LLQuaternion cur_torso_rot = mTorsoJoint->getWorldRotation(); | ||
136 | |||
137 | LLVector3 right_hand_at = LLVector3(0.f, -1.f, 0.f) * mRightHandJoint->getWorldRotation(); | ||
138 | left.setVec(skyward % right_hand_at); | ||
139 | left.normVec(); | ||
140 | up.setVec(right_hand_at % left); | ||
141 | up.normVec(); | ||
142 | LLQuaternion right_hand_rot(right_hand_at, left, up); | ||
143 | |||
144 | LLQuaternion new_torso_rot = (cur_torso_rot * ~right_hand_rot) * target_aim_rot; | ||
145 | |||
146 | // find ideal additive rotation to make torso point in correct direction | ||
147 | new_torso_rot = new_torso_rot * ~cur_torso_rot; | ||
148 | |||
149 | // slerp from current additive rotation to ideal additive rotation | ||
150 | new_torso_rot = nlerp(slerp_amt, mTorsoState.getRotation(), new_torso_rot); | ||
151 | |||
152 | // constraint overall torso rotation | ||
153 | LLQuaternion total_rot = new_torso_rot * mTorsoJoint->getRotation(); | ||
154 | total_rot.constrain(F_PI_BY_TWO * 0.8f); | ||
155 | new_torso_rot = total_rot * ~mTorsoJoint->getRotation(); | ||
156 | |||
157 | mTorsoState.setRotation(new_torso_rot); | ||
158 | |||
159 | return result; | ||
160 | } | ||
161 | |||
162 | //----------------------------------------------------------------------------- | ||
163 | // LLTargetingMotion::onDeactivate() | ||
164 | //----------------------------------------------------------------------------- | ||
165 | void LLTargetingMotion::onDeactivate() | ||
166 | { | ||
167 | } | ||
168 | |||
169 | |||
170 | // End | ||