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/llkeyframefallmotion.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 '')
-rw-r--r-- | linden/indra/llcharacter/llkeyframefallmotion.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llkeyframefallmotion.cpp b/linden/indra/llcharacter/llkeyframefallmotion.cpp new file mode 100644 index 0000000..2fca225 --- /dev/null +++ b/linden/indra/llcharacter/llkeyframefallmotion.cpp | |||
@@ -0,0 +1,142 @@ | |||
1 | /** | ||
2 | * @file llkeyframefallmotion.cpp | ||
3 | * @brief Implementation of LLKeyframeFallMotion 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 "llkeyframefallmotion.h" | ||
34 | #include "llcharacter.h" | ||
35 | #include "m3math.h" | ||
36 | |||
37 | //----------------------------------------------------------------------------- | ||
38 | // Macros | ||
39 | //----------------------------------------------------------------------------- | ||
40 | #define GO_TO_KEY_POSE 1 | ||
41 | #define MIN_TRACK_SPEED 0.01f | ||
42 | |||
43 | //----------------------------------------------------------------------------- | ||
44 | // LLKeyframeFallMotion() | ||
45 | // Class Constructor | ||
46 | //----------------------------------------------------------------------------- | ||
47 | LLKeyframeFallMotion::LLKeyframeFallMotion(const LLUUID &id) : LLKeyframeMotion(id) | ||
48 | { | ||
49 | mVelocityZ = 0.f; | ||
50 | mCharacter = NULL; | ||
51 | } | ||
52 | |||
53 | |||
54 | //----------------------------------------------------------------------------- | ||
55 | // ~LLKeyframeFallMotion() | ||
56 | // Class Destructor | ||
57 | //----------------------------------------------------------------------------- | ||
58 | LLKeyframeFallMotion::~LLKeyframeFallMotion() | ||
59 | { | ||
60 | } | ||
61 | |||
62 | |||
63 | //----------------------------------------------------------------------------- | ||
64 | // LLKeyframeFallMotion::onInitialize() | ||
65 | //----------------------------------------------------------------------------- | ||
66 | LLMotion::LLMotionInitStatus LLKeyframeFallMotion::onInitialize(LLCharacter *character) | ||
67 | { | ||
68 | // save character pointer for later use | ||
69 | mCharacter = character; | ||
70 | |||
71 | // load keyframe data, setup pose and joint states | ||
72 | LLMotion::LLMotionInitStatus result = LLKeyframeMotion::onInitialize(character); | ||
73 | |||
74 | for (U32 jm=0; jm<mJointMotionList->mNumJointMotions; jm++) | ||
75 | { | ||
76 | if (!mJointStates[jm].getJoint()) | ||
77 | continue; | ||
78 | if (mJointStates[jm].getJoint()->getName() == std::string("mPelvis")) | ||
79 | { | ||
80 | mPelvisStatep = &mJointStates[jm]; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return result; | ||
85 | } | ||
86 | |||
87 | //----------------------------------------------------------------------------- | ||
88 | // LLKeyframeFallMotion::onActivate() | ||
89 | //----------------------------------------------------------------------------- | ||
90 | BOOL LLKeyframeFallMotion::onActivate() | ||
91 | { | ||
92 | LLVector3 ground_pos; | ||
93 | LLVector3 ground_normal; | ||
94 | LLQuaternion inverse_pelvis_rot; | ||
95 | LLVector3 fwd_axis(1.f, 0.f, 0.f); | ||
96 | |||
97 | mVelocityZ = -mCharacter->getCharacterVelocity().mV[VZ]; | ||
98 | mCharacter->getGround( mCharacter->getCharacterPosition(), ground_pos, ground_normal); | ||
99 | ground_normal.normVec(); | ||
100 | |||
101 | inverse_pelvis_rot = mCharacter->getCharacterRotation(); | ||
102 | inverse_pelvis_rot.transQuat(); | ||
103 | |||
104 | // find ground normal in pelvis space | ||
105 | ground_normal = ground_normal * inverse_pelvis_rot; | ||
106 | |||
107 | // calculate new foward axis | ||
108 | fwd_axis = fwd_axis - (ground_normal * (ground_normal * fwd_axis)); | ||
109 | fwd_axis.normVec(); | ||
110 | mRotationToGroundNormal = LLQuaternion(fwd_axis, ground_normal % fwd_axis, ground_normal); | ||
111 | |||
112 | return LLKeyframeMotion::onActivate(); | ||
113 | } | ||
114 | |||
115 | //----------------------------------------------------------------------------- | ||
116 | // LLKeyframeFallMotion::onUpdate() | ||
117 | //----------------------------------------------------------------------------- | ||
118 | BOOL LLKeyframeFallMotion::onUpdate(F32 activeTime, U8* joint_mask) | ||
119 | { | ||
120 | BOOL result = LLKeyframeMotion::onUpdate(activeTime, joint_mask); | ||
121 | F32 slerp_amt = clamp_rescale(activeTime / getDuration(), 0.5f, 0.75f, 0.f, 1.f); | ||
122 | |||
123 | mPelvisStatep->setRotation(mPelvisStatep->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion())); | ||
124 | |||
125 | return result; | ||
126 | } | ||
127 | |||
128 | //----------------------------------------------------------------------------- | ||
129 | // LLKeyframeFallMotion::getEaseInDuration() | ||
130 | //----------------------------------------------------------------------------- | ||
131 | F32 LLKeyframeFallMotion::getEaseInDuration() | ||
132 | { | ||
133 | if (mVelocityZ == 0.f) | ||
134 | { | ||
135 | // we've already hit the ground | ||
136 | return 0.4f; | ||
137 | } | ||
138 | |||
139 | return mCharacter->getPreferredPelvisHeight() / mVelocityZ; | ||
140 | } | ||
141 | |||
142 | // End | ||