PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llcharacter/llkeyframefallmotion.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 144 lines | 64 code | 23 blank | 57 comment | 7 complexity | d1f9735eac8cd355cc310ee634411f28 MD5 | raw file
  1/** 
  2 * @file llkeyframefallmotion.cpp
  3 * @brief Implementation of LLKeyframeFallMotion class.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27//-----------------------------------------------------------------------------
 28// Header Files
 29//-----------------------------------------------------------------------------
 30#include "linden_common.h"
 31
 32#include "llkeyframefallmotion.h"
 33#include "llcharacter.h"
 34#include "m3math.h"
 35
 36//-----------------------------------------------------------------------------
 37// Macros
 38//-----------------------------------------------------------------------------
 39#define GO_TO_KEY_POSE	1
 40#define MIN_TRACK_SPEED 0.01f
 41
 42//-----------------------------------------------------------------------------
 43// LLKeyframeFallMotion()
 44// Class Constructor
 45//-----------------------------------------------------------------------------
 46LLKeyframeFallMotion::LLKeyframeFallMotion(const LLUUID &id) : LLKeyframeMotion(id)
 47{
 48	mVelocityZ = 0.f;
 49	mCharacter = NULL;
 50}
 51
 52
 53//-----------------------------------------------------------------------------
 54// ~LLKeyframeFallMotion()
 55// Class Destructor
 56//-----------------------------------------------------------------------------
 57LLKeyframeFallMotion::~LLKeyframeFallMotion()
 58{
 59}
 60
 61
 62//-----------------------------------------------------------------------------
 63// LLKeyframeFallMotion::onInitialize()
 64//-----------------------------------------------------------------------------
 65LLMotion::LLMotionInitStatus LLKeyframeFallMotion::onInitialize(LLCharacter *character)
 66{
 67	// save character pointer for later use
 68	mCharacter = character;
 69
 70	// load keyframe data, setup pose and joint states
 71	LLMotion::LLMotionInitStatus result = LLKeyframeMotion::onInitialize(character);
 72
 73	for (U32 jm=0; jm<mJointMotionList->getNumJointMotions(); jm++)
 74	{
 75		if (!mJointStates[jm]->getJoint())
 76			continue;
 77		if (mJointStates[jm]->getJoint()->getName() == std::string("mPelvis"))
 78		{
 79			mPelvisState = mJointStates[jm];
 80		}
 81	}
 82
 83	return result;
 84}
 85
 86//-----------------------------------------------------------------------------
 87// LLKeyframeFallMotion::onActivate()
 88//-----------------------------------------------------------------------------
 89BOOL LLKeyframeFallMotion::onActivate()
 90{
 91	LLVector3 ground_pos;
 92	LLVector3 ground_normal;
 93	LLQuaternion inverse_pelvis_rot;
 94	LLVector3 fwd_axis(1.f, 0.f, 0.f);
 95
 96	mVelocityZ = -mCharacter->getCharacterVelocity().mV[VZ];
 97	mCharacter->getGround( mCharacter->getCharacterPosition(), ground_pos, ground_normal);
 98	ground_normal.normVec();
 99
100	inverse_pelvis_rot = mCharacter->getCharacterRotation();
101	inverse_pelvis_rot.transQuat();
102
103	// find ground normal in pelvis space
104	ground_normal = ground_normal * inverse_pelvis_rot;
105
106	// calculate new foward axis
107	fwd_axis = fwd_axis - (ground_normal * (ground_normal * fwd_axis));
108	fwd_axis.normVec();
109	mRotationToGroundNormal = LLQuaternion(fwd_axis, ground_normal % fwd_axis, ground_normal);
110
111	return LLKeyframeMotion::onActivate();
112}
113
114//-----------------------------------------------------------------------------
115// LLKeyframeFallMotion::onUpdate()
116//-----------------------------------------------------------------------------
117BOOL LLKeyframeFallMotion::onUpdate(F32 activeTime, U8* joint_mask)
118{
119	BOOL result = LLKeyframeMotion::onUpdate(activeTime, joint_mask);
120	F32  slerp_amt = clamp_rescale(activeTime / getDuration(), 0.5f, 0.75f, 0.f, 1.f);
121
122	if (mPelvisState.notNull())
123	{
124		mPelvisState->setRotation(mPelvisState->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion()));
125	}
126	
127	return result;
128}
129
130//-----------------------------------------------------------------------------
131// LLKeyframeFallMotion::getEaseInDuration()
132//-----------------------------------------------------------------------------
133F32 LLKeyframeFallMotion::getEaseInDuration()
134{
135	if (mVelocityZ == 0.f)
136	{
137		// we've already hit the ground
138		return 0.4f;
139	}
140
141	return mCharacter->getPreferredPelvisHeight() / mVelocityZ;
142}
143
144// End