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