00001
00032
00033
00034
00035 #include "linden_common.h"
00036
00037 #include "llkeyframefallmotion.h"
00038 #include "llcharacter.h"
00039 #include "m3math.h"
00040
00041
00042
00043
00044 #define GO_TO_KEY_POSE 1
00045 #define MIN_TRACK_SPEED 0.01f
00046
00047
00048
00049
00050
00051 LLKeyframeFallMotion::LLKeyframeFallMotion(const LLUUID &id) : LLKeyframeMotion(id)
00052 {
00053 mVelocityZ = 0.f;
00054 mCharacter = NULL;
00055 }
00056
00057
00058
00059
00060
00061
00062 LLKeyframeFallMotion::~LLKeyframeFallMotion()
00063 {
00064 }
00065
00066
00067
00068
00069
00070 LLMotion::LLMotionInitStatus LLKeyframeFallMotion::onInitialize(LLCharacter *character)
00071 {
00072
00073 mCharacter = character;
00074
00075
00076 LLMotion::LLMotionInitStatus result = LLKeyframeMotion::onInitialize(character);
00077
00078 for (U32 jm=0; jm<mJointMotionList->mNumJointMotions; jm++)
00079 {
00080 if (!mJointStates[jm].getJoint())
00081 continue;
00082 if (mJointStates[jm].getJoint()->getName() == std::string("mPelvis"))
00083 {
00084 mPelvisStatep = &mJointStates[jm];
00085 }
00086 }
00087
00088 return result;
00089 }
00090
00091
00092
00093
00094 BOOL LLKeyframeFallMotion::onActivate()
00095 {
00096 LLVector3 ground_pos;
00097 LLVector3 ground_normal;
00098 LLQuaternion inverse_pelvis_rot;
00099 LLVector3 fwd_axis(1.f, 0.f, 0.f);
00100
00101 mVelocityZ = -mCharacter->getCharacterVelocity().mV[VZ];
00102 mCharacter->getGround( mCharacter->getCharacterPosition(), ground_pos, ground_normal);
00103 ground_normal.normVec();
00104
00105 inverse_pelvis_rot = mCharacter->getCharacterRotation();
00106 inverse_pelvis_rot.transQuat();
00107
00108
00109 ground_normal = ground_normal * inverse_pelvis_rot;
00110
00111
00112 fwd_axis = fwd_axis - (ground_normal * (ground_normal * fwd_axis));
00113 fwd_axis.normVec();
00114 mRotationToGroundNormal = LLQuaternion(fwd_axis, ground_normal % fwd_axis, ground_normal);
00115
00116 return LLKeyframeMotion::onActivate();
00117 }
00118
00119
00120
00121
00122 BOOL LLKeyframeFallMotion::onUpdate(F32 activeTime, U8* joint_mask)
00123 {
00124 BOOL result = LLKeyframeMotion::onUpdate(activeTime, joint_mask);
00125 F32 slerp_amt = clamp_rescale(activeTime / getDuration(), 0.5f, 0.75f, 0.f, 1.f);
00126
00127 mPelvisStatep->setRotation(mPelvisStatep->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion()));
00128
00129 return result;
00130 }
00131
00132
00133
00134
00135 F32 LLKeyframeFallMotion::getEaseInDuration()
00136 {
00137 if (mVelocityZ == 0.f)
00138 {
00139
00140 return 0.4f;
00141 }
00142
00143 return mCharacter->getPreferredPelvisHeight() / mVelocityZ;
00144 }
00145
00146