llmotion.cpp

Go to the documentation of this file.
00001 
00032 //-----------------------------------------------------------------------------
00033 // Header Files
00034 //-----------------------------------------------------------------------------
00035 #include "linden_common.h"
00036 
00037 #include "llmotion.h"
00038 #include "llcriticaldamp.h"
00039 
00040 //-----------------------------------------------------------------------------
00041 //-----------------------------------------------------------------------------
00042 // LLMotion class
00043 //-----------------------------------------------------------------------------
00044 //-----------------------------------------------------------------------------
00045 
00046 //-----------------------------------------------------------------------------
00047 // LLMotion()
00048 // Class Constructor
00049 //-----------------------------------------------------------------------------
00050 LLMotion::LLMotion( const LLUUID &id ) :
00051         mStopped(TRUE),
00052         mActive(FALSE),
00053         mID(id),
00054         mActivationTimestamp(0.f),
00055         mStopTimestamp(0.f),
00056         mSendStopTimestamp(F32_MAX),
00057         mResidualWeight(0.f),
00058         mFadeWeight(1.f),
00059         mDeactivateCallback(NULL),
00060         mDeactivateCallbackUserData(NULL)
00061 {
00062         for (int i=0; i<3; ++i)
00063                 memset(&mJointSignature[i][0], 0, sizeof(U8) * LL_CHARACTER_MAX_JOINTS);
00064 }
00065 
00066 //-----------------------------------------------------------------------------
00067 // ~LLMotion()
00068 // Class Destructor
00069 //-----------------------------------------------------------------------------
00070 LLMotion::~LLMotion()
00071 {
00072 }
00073 
00074 //-----------------------------------------------------------------------------
00075 // fadeOut()
00076 //-----------------------------------------------------------------------------
00077 void LLMotion::fadeOut()
00078 {
00079         if (mFadeWeight > 0.01f)
00080         {
00081                 mFadeWeight = lerp(mFadeWeight, 0.f, LLCriticalDamp::getInterpolant(0.15f));
00082         }
00083         else
00084         {
00085                 mFadeWeight = 0.f;
00086         }
00087 }
00088 
00089 //-----------------------------------------------------------------------------
00090 // fadeIn()
00091 //-----------------------------------------------------------------------------
00092 void LLMotion::fadeIn()
00093 {
00094         if (mFadeWeight < 0.99f)
00095         {
00096                 mFadeWeight = lerp(mFadeWeight, 1.f, LLCriticalDamp::getInterpolant(0.15f));
00097         }
00098         else
00099         {
00100                 mFadeWeight = 1.f;
00101         }
00102 }
00103 
00104 //-----------------------------------------------------------------------------
00105 // addJointState()
00106 //-----------------------------------------------------------------------------
00107 void LLMotion::addJointState(const LLPointer<LLJointState>& jointState)
00108 {
00109         mPose.addJointState(jointState);
00110         S32 priority = jointState->getPriority();
00111         if (priority == LLJoint::USE_MOTION_PRIORITY)
00112         {
00113                 priority = getPriority();       
00114         }
00115 
00116         U32 usage = jointState->getUsage();
00117 
00118         // for now, usage is everything
00119         mJointSignature[0][jointState->getJoint()->getJointNum()] = (usage & LLJointState::POS) ? (0xff >> (7 - priority)) : 0;
00120         mJointSignature[1][jointState->getJoint()->getJointNum()] = (usage & LLJointState::ROT) ? (0xff >> (7 - priority)) : 0;
00121         mJointSignature[2][jointState->getJoint()->getJointNum()] = (usage & LLJointState::SCALE) ? (0xff >> (7 - priority)) : 0;
00122 }
00123 
00124 void LLMotion::setDeactivateCallback( void (*cb)(void *), void* userdata )
00125 {
00126         mDeactivateCallback = cb;
00127         mDeactivateCallbackUserData = userdata;
00128 }
00129 
00130 BOOL LLMotion::isBlending()
00131 {
00132         return mPose.getWeight() < 1.f;
00133 }
00134 
00135 //-----------------------------------------------------------------------------
00136 // activate()
00137 //-----------------------------------------------------------------------------
00138 void LLMotion::activate()
00139 {
00140         mStopped = FALSE;
00141         mActive = TRUE;
00142         onActivate();
00143 }
00144 
00145 //-----------------------------------------------------------------------------
00146 // deactivate()
00147 //-----------------------------------------------------------------------------
00148 void LLMotion::deactivate()
00149 {
00150         mActive = FALSE;
00151         mPose.setWeight(0.f);
00152 
00153         if (mDeactivateCallback) (*mDeactivateCallback)(mDeactivateCallbackUserData);
00154 
00155         onDeactivate();
00156 }
00157 
00158 BOOL LLMotion::canDeprecate()
00159 {
00160         return TRUE;
00161 }
00162 
00163 // End

Generated on Fri May 16 08:31:59 2008 for SecondLife by  doxygen 1.5.5