PageRenderTime 580ms CodeModel.GetById 478ms app.highlight 12ms RepoModel.GetById 88ms app.codeStats 0ms

/indra/llcharacter/llmotion.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 171 lines | 93 code | 19 blank | 59 comment | 6 complexity | e05ec8677a694aca7c6e7348227abb50 MD5 | raw file
  1/** 
  2 * @file llmotion.cpp
  3 * @brief Implementation of LLMotion 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 "llmotion.h"
 33#include "llcriticaldamp.h"
 34
 35//-----------------------------------------------------------------------------
 36//-----------------------------------------------------------------------------
 37// LLMotion class
 38//-----------------------------------------------------------------------------
 39//-----------------------------------------------------------------------------
 40
 41//-----------------------------------------------------------------------------
 42// LLMotion()
 43// Class Constructor
 44//-----------------------------------------------------------------------------
 45LLMotion::LLMotion( const LLUUID &id ) :
 46	mStopped(TRUE),
 47	mActive(FALSE),
 48	mID(id),
 49	mActivationTimestamp(0.f),
 50	mStopTimestamp(0.f),
 51	mSendStopTimestamp(F32_MAX),
 52	mResidualWeight(0.f),
 53	mFadeWeight(1.f),
 54	mDeactivateCallback(NULL),
 55	mDeactivateCallbackUserData(NULL)
 56{
 57	for (int i=0; i<3; ++i)
 58		memset(&mJointSignature[i][0], 0, sizeof(U8) * LL_CHARACTER_MAX_JOINTS);
 59}
 60
 61//-----------------------------------------------------------------------------
 62// ~LLMotion()
 63// Class Destructor
 64//-----------------------------------------------------------------------------
 65LLMotion::~LLMotion()
 66{
 67}
 68
 69//-----------------------------------------------------------------------------
 70// fadeOut()
 71//-----------------------------------------------------------------------------
 72void LLMotion::fadeOut()
 73{
 74	if (mFadeWeight > 0.01f)
 75	{
 76		mFadeWeight = lerp(mFadeWeight, 0.f, LLCriticalDamp::getInterpolant(0.15f));
 77	}
 78	else
 79	{
 80		mFadeWeight = 0.f;
 81	}
 82}
 83
 84//-----------------------------------------------------------------------------
 85// fadeIn()
 86//-----------------------------------------------------------------------------
 87void LLMotion::fadeIn()
 88{
 89	if (mFadeWeight < 0.99f)
 90	{
 91		mFadeWeight = lerp(mFadeWeight, 1.f, LLCriticalDamp::getInterpolant(0.15f));
 92	}
 93	else
 94	{
 95		mFadeWeight = 1.f;
 96	}
 97}
 98
 99//-----------------------------------------------------------------------------
100// addJointState()
101//-----------------------------------------------------------------------------
102void LLMotion::addJointState(const LLPointer<LLJointState>& jointState)
103{
104	mPose.addJointState(jointState);
105	S32 priority = jointState->getPriority();
106	if (priority == LLJoint::USE_MOTION_PRIORITY)
107	{
108		priority = getPriority();	
109	}
110
111	U32 usage = jointState->getUsage();
112
113	// for now, usage is everything
114	mJointSignature[0][jointState->getJoint()->getJointNum()] = (usage & LLJointState::POS) ? (0xff >> (7 - priority)) : 0;
115	mJointSignature[1][jointState->getJoint()->getJointNum()] = (usage & LLJointState::ROT) ? (0xff >> (7 - priority)) : 0;
116	mJointSignature[2][jointState->getJoint()->getJointNum()] = (usage & LLJointState::SCALE) ? (0xff >> (7 - priority)) : 0;
117}
118
119void LLMotion::setDeactivateCallback( void (*cb)(void *), void* userdata )
120{
121	mDeactivateCallback = cb;
122	mDeactivateCallbackUserData = userdata;
123}
124
125//virtual
126void LLMotion::setStopTime(F32 time)
127{
128	mStopTimestamp = time;
129	mStopped = TRUE;
130}
131
132BOOL LLMotion::isBlending()
133{
134	return mPose.getWeight() < 1.f;
135}
136
137//-----------------------------------------------------------------------------
138// activate()
139//-----------------------------------------------------------------------------
140void LLMotion::activate(F32 time)
141{
142	mActivationTimestamp = time;
143	mStopped = FALSE;
144	mActive = TRUE;
145	onActivate();
146}
147
148//-----------------------------------------------------------------------------
149// deactivate()
150//-----------------------------------------------------------------------------
151void LLMotion::deactivate()
152{
153	mActive = FALSE;
154	mPose.setWeight(0.f);
155
156	if (mDeactivateCallback)
157	{
158		(*mDeactivateCallback)(mDeactivateCallbackUserData);
159		mDeactivateCallback = NULL; // only call callback once
160		mDeactivateCallbackUserData = NULL;
161	}
162
163	onDeactivate();
164}
165
166BOOL LLMotion::canDeprecate()
167{
168	return TRUE;
169}
170
171// End