aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcharacter/llhandmotion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcharacter/llhandmotion.cpp')
-rw-r--r--linden/indra/llcharacter/llhandmotion.cpp221
1 files changed, 221 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llhandmotion.cpp b/linden/indra/llcharacter/llhandmotion.cpp
new file mode 100644
index 0000000..12ef070
--- /dev/null
+++ b/linden/indra/llcharacter/llhandmotion.cpp
@@ -0,0 +1,221 @@
1/**
2 * @file llhandmotion.cpp
3 * @brief Implementation of LLHandMotion 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 "llhandmotion.h"
34#include "llcharacter.h"
35#include "m3math.h"
36
37//-----------------------------------------------------------------------------
38// Constants
39//-----------------------------------------------------------------------------
40
41const char *gHandPoseNames[LLHandMotion::NUM_HAND_POSES] = /* Flawfinder: ignore */
42{
43 "",
44 "Hands_Relaxed",
45 "Hands_Point",
46 "Hands_Fist",
47 "Hands_Relaxed_L",
48 "Hands_Point_L",
49 "Hands_Fist_L",
50 "Hands_Relaxed_R",
51 "Hands_Point_R",
52 "Hands_Fist_R",
53 "Hands_Salute_R",
54 "Hands_Typing",
55 "Hands_Peace_R",
56 "Hands_Spread_R"
57};
58
59const F32 HAND_MORPH_BLEND_TIME = 0.2f;
60
61//-----------------------------------------------------------------------------
62// LLHandMotion()
63// Class Constructor
64//-----------------------------------------------------------------------------
65LLHandMotion::LLHandMotion(const LLUUID &id) : LLMotion(id)
66{
67 mCharacter = NULL;
68 mLastTime = 0.f;
69 mCurrentPose = HAND_POSE_RELAXED;
70 mNewPose = HAND_POSE_RELAXED;
71 mName = "hand_motion";
72
73 //RN: flag hand joint as highest priority for now, until we implement a proper animation track
74 mJointSignature[0][LL_HAND_JOINT_NUM] = 0xff;
75 mJointSignature[1][LL_HAND_JOINT_NUM] = 0xff;
76 mJointSignature[2][LL_HAND_JOINT_NUM] = 0xff;
77}
78
79
80//-----------------------------------------------------------------------------
81// ~LLHandMotion()
82// Class Destructor
83//-----------------------------------------------------------------------------
84LLHandMotion::~LLHandMotion()
85{
86}
87
88//-----------------------------------------------------------------------------
89// LLHandMotion::onInitialize(LLCharacter *character)
90//-----------------------------------------------------------------------------
91LLMotion::LLMotionInitStatus LLHandMotion::onInitialize(LLCharacter *character)
92{
93 mCharacter = character;
94
95 return STATUS_SUCCESS;
96}
97
98
99//-----------------------------------------------------------------------------
100// LLHandMotion::onActivate()
101//-----------------------------------------------------------------------------
102BOOL LLHandMotion::onActivate()
103{
104 LLPolyMesh *upperBodyMesh = mCharacter->getUpperBodyMesh();
105
106 if (upperBodyMesh)
107 {
108 // Note: 0 is the default
109 for (S32 i = 1; i < LLHandMotion::NUM_HAND_POSES; i++)
110 {
111 mCharacter->setVisualParamWeight(gHandPoseNames[i], 0.f);
112 }
113 mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], 1.f);
114 mCharacter->updateVisualParams();
115 }
116 return TRUE;
117}
118
119
120//-----------------------------------------------------------------------------
121// LLHandMotion::onUpdate()
122//-----------------------------------------------------------------------------
123BOOL LLHandMotion::onUpdate(F32 time, U8* joint_mask)
124{
125 eHandPose *requestedHandPose;
126
127 F32 timeDelta = time - mLastTime;
128 mLastTime = time;
129
130 requestedHandPose = (eHandPose *)mCharacter->getAnimationData("Hand Pose");
131 // check to see if requested pose has changed
132 if (!requestedHandPose)
133 {
134 if (mNewPose != HAND_POSE_RELAXED && mNewPose != mCurrentPose)
135 {
136 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
137 }
138 mNewPose = HAND_POSE_RELAXED;
139 }
140 else
141 {
142 // this is a new morph we didn't know about before
143 if (*requestedHandPose != mNewPose && mNewPose != mCurrentPose && mNewPose != HAND_POSE_SPREAD)
144 {
145 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
146 }
147 mNewPose = *requestedHandPose;
148 }
149
150 mCharacter->removeAnimationData("Hand Pose");
151 mCharacter->removeAnimationData("Hand Pose Priority");
152
153// if (requestedHandPose)
154// llinfos << "Hand Pose " << *requestedHandPose << llendl;
155
156 // if we are still blending...
157 if (mCurrentPose != mNewPose)
158 {
159 F32 incomingWeight = 1.f;
160 F32 outgoingWeight = 0.f;
161
162 if (mNewPose != HAND_POSE_SPREAD)
163 {
164 incomingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mNewPose]);
165 incomingWeight += (timeDelta / HAND_MORPH_BLEND_TIME);
166 incomingWeight = llclamp(incomingWeight, 0.f, 1.f);
167 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], incomingWeight);
168 }
169
170 if (mCurrentPose != HAND_POSE_SPREAD)
171 {
172 outgoingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mCurrentPose]);
173 outgoingWeight -= (timeDelta / HAND_MORPH_BLEND_TIME);
174 outgoingWeight = llclamp(outgoingWeight, 0.f, 1.f);
175 mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], outgoingWeight);
176 }
177
178 mCharacter->updateVisualParams();
179
180 if (incomingWeight == 1.f && outgoingWeight == 0.f)
181 {
182 mCurrentPose = mNewPose;
183 }
184 }
185
186 return TRUE;
187}
188
189
190//-----------------------------------------------------------------------------
191// LLHandMotion::onDeactivate()
192//-----------------------------------------------------------------------------
193void LLHandMotion::onDeactivate()
194{
195}
196
197//-----------------------------------------------------------------------------
198// LLHandMotion::getHandPoseName()
199//-----------------------------------------------------------------------------
200LLString LLHandMotion::getHandPoseName(eHandPose pose)
201{
202 if ((S32)pose < LLHandMotion::NUM_HAND_POSES && (S32)pose >= 0)
203 {
204 return gHandPoseNames[pose];
205 }
206 return "";
207}
208
209LLHandMotion::eHandPose LLHandMotion::getHandPose(LLString posename)
210{
211 for (S32 pose = 0; pose < LLHandMotion::NUM_HAND_POSES; ++pose)
212 {
213 if (gHandPoseNames[pose] == posename)
214 {
215 return (eHandPose)pose;
216 }
217 }
218 return (eHandPose)0;
219}
220
221// End