llmotion.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLMOTION_H
00033 #define LL_LLMOTION_H
00034 
00035 //-----------------------------------------------------------------------------
00036 // Header files
00037 //-----------------------------------------------------------------------------
00038 #include <string>
00039 
00040 #include "llerror.h"
00041 #include "llpose.h"
00042 #include "lluuid.h"
00043 
00044 class LLCharacter;
00045 
00046 //-----------------------------------------------------------------------------
00047 // class LLMotion
00048 //-----------------------------------------------------------------------------
00049 class LLMotion
00050 {
00051 public:
00052         typedef enum LLMotionBlendType
00053         {
00054                 NORMAL_BLEND,
00055                 ADDITIVE_BLEND
00056         };
00057 
00058         typedef enum LLMotionInitStatus
00059         {
00060                 STATUS_FAILURE,
00061                 STATUS_SUCCESS,
00062                 STATUS_HOLD
00063         };
00064 
00065         // Constructor
00066         LLMotion(const LLUUID &id);
00067 
00068         // Destructor
00069         virtual ~LLMotion();
00070 
00071 public:
00072         //-------------------------------------------------------------------------
00073         // functions to support MotionController and MotionRegistry
00074         //-------------------------------------------------------------------------
00075 
00076         // static constructor
00077         // all subclasses must implement such a function and register it
00078         static LLMotion *create(const LLUUID &id) { return NULL; }
00079 
00080         // get the name of this instance
00081         const std::string &getName() const { return mName; }
00082 
00083         // set the name of this instance
00084         void setName(const std::string &name) { mName = name; }
00085 
00086         const LLUUID& getID() const { return mID; }
00087 
00088         // returns the pose associated with the current state of this motion
00089         virtual LLPose* getPose() { return &mPose;}
00090 
00091         void fadeOut();
00092 
00093         void fadeIn();
00094 
00095         F32 getFadeWeight() const { return mFadeWeight; }
00096 
00097         F32 getStopTime() const { return mStopTimestamp; }
00098 
00099         virtual void setStopTime(F32 time) { mStopTimestamp = time; mStopped = TRUE; }
00100 
00101         BOOL isStopped() const { return mStopped; }
00102 
00103         void setStopped(BOOL stopped) { mStopped = stopped; }
00104 
00105         BOOL isBlending();
00106 
00107         void activate();
00108 
00109         void deactivate();
00110 
00111         BOOL isActive() { return mActive; }
00112 
00113 public:
00114         //-------------------------------------------------------------------------
00115         // animation callbacks to be implemented by subclasses
00116         //-------------------------------------------------------------------------
00117 
00118         // motions must specify whether or not they loop
00119         virtual BOOL getLoop() = 0;
00120 
00121         // motions must report their total duration
00122         virtual F32 getDuration() = 0;
00123 
00124         // motions must report their "ease in" duration
00125         virtual F32 getEaseInDuration() = 0;
00126 
00127         // motions must report their "ease out" duration.
00128         virtual F32 getEaseOutDuration() = 0;
00129 
00130         // motions must report their priority level
00131         virtual LLJoint::JointPriority getPriority() = 0;
00132 
00133         // motions must report their blend type
00134         virtual LLMotionBlendType getBlendType() = 0;
00135 
00136         // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
00137         virtual F32 getMinPixelArea() = 0;
00138 
00139         // run-time (post constructor) initialization,
00140         // called after parameters have been set
00141         // must return true to indicate success and be available for activation
00142         virtual LLMotionInitStatus onInitialize(LLCharacter *character) = 0;
00143 
00144         // called per time step
00145         // must return TRUE while it is active, and
00146         // must return FALSE when the motion is completed.
00147         virtual BOOL onUpdate(F32 activeTime, U8* joint_mask) = 0;
00148 
00149         // called when a motion is deactivated
00150         virtual void onDeactivate() = 0;
00151 
00152         // can we crossfade this motion with a new instance when restarted?
00153         // should ultimately always be TRUE, but lack of emote blending, etc
00154         // requires this
00155         virtual BOOL canDeprecate();
00156 
00157         // optional callback routine called when animation deactivated.
00158         void    setDeactivateCallback( void (*cb)(void *), void* userdata );
00159 
00160 protected:
00161         // called when a motion is activated
00162         // must return TRUE to indicate success, or else
00163         // it will be deactivated
00164         virtual BOOL onActivate() = 0;
00165 
00166         void addJointState(const LLPointer<LLJointState>& jointState);
00167 
00168 protected:
00169         LLPose          mPose;
00170         BOOL            mStopped;               // motion has been stopped;
00171         BOOL            mActive;                // motion is on active list (can be stopped or not stopped)
00172 
00173 public:
00174         //-------------------------------------------------------------------------
00175         // these are set implicitly by the motion controller and
00176         // may be referenced (read only) in the above handlers.
00177         //-------------------------------------------------------------------------
00178         std::string             mName;                  // instance name assigned by motion controller
00179         LLUUID                  mID;
00180 
00181         F32 mActivationTimestamp;       // time when motion was activated
00182         F32 mStopTimestamp;                     // time when motion was told to stop
00183         F32 mSendStopTimestamp;         // time when simulator should be told to stop this motion
00184         F32 mResidualWeight;            // blend weight at beginning of stop motion phase
00185         F32 mFadeWeight;                        // for fading in and out based on LOD
00186         U8      mJointSignature[3][LL_CHARACTER_MAX_JOINTS];    // signature of which joints are animated at what priority
00187         void (*mDeactivateCallback)(void* data);
00188         void* mDeactivateCallbackUserData;
00189 };
00190 
00191 
00192 //-----------------------------------------------------------------------------
00193 // LLTestMotion
00194 //-----------------------------------------------------------------------------
00195 class LLTestMotion : public LLMotion
00196 {
00197 public:
00198         LLTestMotion(const LLUUID &id) : LLMotion(id){}
00199         ~LLTestMotion() {}
00200         static LLMotion *create(const LLUUID& id) { return new LLTestMotion(id); }
00201         BOOL getLoop() { return FALSE; }
00202         F32 getDuration() { return 0.0f; }
00203         F32 getEaseInDuration() { return 0.0f; }
00204         F32 getEaseOutDuration() { return 0.0f; }
00205         LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
00206         LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
00207         F32 getMinPixelArea() { return 0.f; }
00208         
00209         LLMotionInitStatus onInitialize(LLCharacter*) { llinfos << "LLTestMotion::onInitialize()" << llendl; return STATUS_SUCCESS; }
00210         BOOL onActivate() { llinfos << "LLTestMotion::onActivate()" << llendl; return TRUE; }
00211         BOOL onUpdate(F32 time, U8* joint_mask) { llinfos << "LLTestMotion::onUpdate(" << time << ")" << llendl; return TRUE; }
00212         void onDeactivate() { llinfos << "LLTestMotion::onDeactivate()" << llendl; }
00213 };
00214 
00215 
00216 //-----------------------------------------------------------------------------
00217 // LLNullMotion
00218 //-----------------------------------------------------------------------------
00219 class LLNullMotion : public LLMotion
00220 {
00221 public:
00222         LLNullMotion(const LLUUID &id) : LLMotion(id) {}
00223         ~LLNullMotion() {}
00224         static LLMotion *create(const LLUUID &id) { return new LLNullMotion(id); }
00225 
00226         // motions must specify whether or not they loop
00227         /*virtual*/ BOOL getLoop() { return TRUE; }
00228 
00229         // motions must report their total duration
00230         /*virtual*/ F32 getDuration() { return 1.f; }
00231 
00232         // motions must report their "ease in" duration
00233         /*virtual*/ F32 getEaseInDuration() { return 0.f; }
00234 
00235         // motions must report their "ease out" duration.
00236         /*virtual*/ F32 getEaseOutDuration() { return 0.f; }
00237 
00238         // motions must report their priority level
00239         /*virtual*/ LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
00240 
00241         // motions must report their blend type
00242         /*virtual*/ LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
00243 
00244         // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
00245         /*virtual*/ F32 getMinPixelArea() { return 0.f; }
00246 
00247         // run-time (post constructor) initialization,
00248         // called after parameters have been set
00249         // must return true to indicate success and be available for activation
00250         /*virtual*/ LLMotionInitStatus onInitialize(LLCharacter *character) { return STATUS_SUCCESS; }
00251 
00252         // called when a motion is activated
00253         // must return TRUE to indicate success, or else
00254         // it will be deactivated
00255         /*virtual*/ BOOL onActivate() { return TRUE; }
00256 
00257         // called per time step
00258         // must return TRUE while it is active, and
00259         // must return FALSE when the motion is completed.
00260         /*virtual*/ BOOL onUpdate(F32 activeTime, U8* joint_mask) { return TRUE; }
00261 
00262         // called when a motion is deactivated
00263         /*virtual*/ void onDeactivate() {}
00264 };
00265 #endif // LL_LLMOTION_H
00266 

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