llcharacter.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLCHARACTER_H
00033 #define LL_LLCHARACTER_H
00034 
00035 //-----------------------------------------------------------------------------
00036 // Header Files
00037 //-----------------------------------------------------------------------------
00038 #include <string>
00039 
00040 #include "lljoint.h"
00041 #include "llmotioncontroller.h"
00042 #include "llvisualparam.h"
00043 #include "string_table.h"
00044 #include "llmemory.h"
00045 #include "llthread.h"
00046 
00047 class LLPolyMesh;
00048 
00049 class LLPauseRequestHandle : public LLThreadSafeRefCount
00050 {
00051 public:
00052         LLPauseRequestHandle() {};
00053 };
00054 
00055 typedef LLPointer<LLPauseRequestHandle> LLAnimPauseRequest;
00056 
00057 //-----------------------------------------------------------------------------
00058 // class LLCharacter
00059 //-----------------------------------------------------------------------------
00060 class LLCharacter
00061 {
00062 public:
00063         // Constructor
00064         LLCharacter();
00065 
00066         // Destructor
00067         virtual ~LLCharacter();
00068 
00069         //-------------------------------------------------------------------------
00070         // LLCharacter Interface
00071         // These functions must be implemented by subclasses.
00072         //-------------------------------------------------------------------------
00073 
00074         // get the prefix to be used to lookup motion data files
00075         // from the viewer data directory
00076         virtual const char *getAnimationPrefix() = 0;
00077 
00078         // get the root joint of the character
00079         virtual LLJoint *getRootJoint() = 0;
00080 
00081         // get the specified joint
00082         // default implementation does recursive search,
00083         // subclasses may optimize/cache results.
00084         virtual LLJoint *getJoint( const std::string &name );
00085 
00086         // get the position of the character
00087         virtual LLVector3 getCharacterPosition() = 0;
00088 
00089         // get the rotation of the character
00090         virtual LLQuaternion getCharacterRotation() = 0;
00091 
00092         // get the velocity of the character
00093         virtual LLVector3 getCharacterVelocity() = 0;
00094 
00095         // get the angular velocity of the character
00096         virtual LLVector3 getCharacterAngularVelocity() = 0;
00097 
00098         // get the height & normal of the ground under a point
00099         virtual void getGround(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm) = 0;
00100 
00101         // allocate an array of joints for the character skeleton
00102         // this must be overloaded to support joint subclasses,
00103         // and is called implicitly from buildSkeleton().
00104         // Note this must handle reallocation as it will be called
00105         // each time buildSkeleton() is called.
00106         virtual BOOL allocateCharacterJoints( U32 num ) = 0;
00107 
00108         // skeleton joint accessor to support joint subclasses
00109         virtual LLJoint *getCharacterJoint( U32 i ) = 0;
00110 
00111         // get the physics time dilation for the simulator
00112         virtual F32 getTimeDilation() = 0;
00113 
00114         // gets current pixel area of this character
00115         virtual F32 getPixelArea() const = 0;
00116 
00117         // gets the head mesh of the character
00118         virtual LLPolyMesh*     getHeadMesh() = 0;
00119 
00120         // gets the upper body mesh of the character
00121         virtual LLPolyMesh*     getUpperBodyMesh() = 0;
00122 
00123         // gets global coordinates from agent local coordinates
00124         virtual LLVector3d      getPosGlobalFromAgent(const LLVector3 &position) = 0;
00125 
00126         // gets agent local coordinates from global coordinates
00127         virtual LLVector3       getPosAgentFromGlobal(const LLVector3d &position) = 0;
00128 
00129         // updates all visual parameters for this character
00130         virtual void updateVisualParams();
00131 
00132         virtual void addDebugText( const std::string& text ) = 0;
00133 
00134         virtual const LLUUID&   getID() = 0;
00135         //-------------------------------------------------------------------------
00136         // End Interface
00137         //-------------------------------------------------------------------------
00138         // registers a motion with the character
00139         // returns true if successfull
00140         BOOL addMotion( const LLUUID& id, LLMotionConstructor create );
00141 
00142         void removeMotion( const LLUUID& id );
00143 
00144         // returns an instance of a registered motion
00145         LLMotion* createMotion( const LLUUID &id );
00146 
00147         // start a motion
00148         // returns true if successful, false if an error occurred
00149         virtual BOOL startMotion( const LLUUID& id, F32 start_offset = 0.f);
00150 
00151         // stop a motion
00152         virtual BOOL stopMotion( const LLUUID& id, BOOL stop_immediate = FALSE );
00153 
00154         // is this motion active?
00155         BOOL isMotionActive( const LLUUID& id );
00156 
00157         // Event handler for motion deactivation.
00158         // Called when a motion has completely stopped and has been deactivated.
00159         // Subclasses may optionally override this.
00160         // The default implementation does nothing.
00161         virtual void requestStopMotion( LLMotion* motion );
00162         
00163         // periodic update function, steps the motion controller
00164         void updateMotion(BOOL force_update = FALSE);
00165 
00166         LLAnimPauseRequest requestPause();
00167         BOOL areAnimationsPaused() { return mMotionController.isPaused(); }
00168         void setAnimTimeFactor(F32 factor) { mMotionController.setTimeFactor(factor); }
00169         void setTimeStep(F32 time_step) { mMotionController.setTimeStep(time_step); }
00170         // Releases all motion instances which should result in
00171         // no cached references to character joint data.  This is 
00172         // useful if a character wants to rebuild it's skeleton.
00173         virtual void flushAllMotions();
00174         
00175         // Flush only wipes active animations. 
00176         virtual void deactivateAllMotions();
00177 
00178         // dumps information for debugging
00179         virtual void dumpCharacter( LLJoint *joint = NULL );
00180 
00181         virtual F32 getPreferredPelvisHeight() { return mPreferredPelvisHeight; }
00182 
00183         virtual LLVector3 getVolumePos(S32 joint_index, LLVector3& volume_offset) { return LLVector3::zero; }
00184         
00185         virtual LLJoint* findCollisionVolume(U32 volume_id) { return NULL; }
00186 
00187         virtual S32 getCollisionVolumeID(std::string &name) { return -1; }
00188 
00189         void setAnimationData(std::string name, void *data);
00190         
00191         void *getAnimationData(std::string name);
00192 
00193         void removeAnimationData(std::string name);
00194         
00195         void addVisualParam(LLVisualParam *param);
00196         void addSharedVisualParam(LLVisualParam *param);
00197 
00198         BOOL setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL set_by_user = FALSE );
00199         BOOL setVisualParamWeight(const char* param_name, F32 weight, BOOL set_by_user = FALSE );
00200         BOOL setVisualParamWeight(S32 index, F32 weight, BOOL set_by_user = FALSE );
00201 
00202         // get visual param weight by param or name
00203         F32 getVisualParamWeight(LLVisualParam *distortion);
00204         F32 getVisualParamWeight(const char* param_name);
00205         F32 getVisualParamWeight(S32 index);
00206 
00207         // set all morph weights to 0
00208         void clearVisualParamWeights();
00209 
00210         // see if all the weights are default
00211         BOOL visualParamWeightsAreDefault();
00212 
00213         // visual parameter accessors
00214         LLVisualParam*  getFirstVisualParam()
00215         {
00216                 mCurIterator = mVisualParamIndexMap.begin();
00217                 return getNextVisualParam();
00218         }
00219         LLVisualParam*  getNextVisualParam()
00220         {
00221                 if (mCurIterator == mVisualParamIndexMap.end())
00222                         return 0;
00223                 return (mCurIterator++)->second;
00224         }
00225 
00226         LLVisualParam*  getVisualParam(S32 id)
00227         {
00228                 VisualParamIndexMap_t::iterator iter = mVisualParamIndexMap.find(id);
00229                 return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second;
00230         }
00231         S32 getVisualParamID(LLVisualParam *id)
00232         {
00233                 VisualParamIndexMap_t::iterator iter;
00234                 for (iter = mVisualParamIndexMap.begin(); iter != mVisualParamIndexMap.end(); iter++)
00235                 {
00236                         if (iter->second == id)
00237                                 return iter->first;
00238                 }
00239                 return 0;
00240         }
00241         S32                             getVisualParamCount() { return (S32)mVisualParamIndexMap.size(); }
00242         LLVisualParam*  getVisualParam(const char *name);
00243 
00244 
00245         ESex getSex()                           { return mSex; }
00246         void setSex( ESex sex )         { mSex = sex; }
00247 
00248         U32                             getAppearanceSerialNum() const          { return mAppearanceSerialNum; }
00249         void                    setAppearanceSerialNum( U32 num )       { mAppearanceSerialNum = num; }
00250         
00251         U32                             getSkeletonSerialNum() const            { return mSkeletonSerialNum; }
00252         void                    setSkeletonSerialNum( U32 num ) { mSkeletonSerialNum = num; }
00253 
00254         static std::vector< LLCharacter* > sInstances;
00255 
00256 protected:
00257         LLMotionController      mMotionController;
00258 
00259         typedef std::map<std::string, void *> animation_data_map_t;
00260         animation_data_map_t mAnimationData;
00261 
00262         F32                                     mPreferredPelvisHeight;
00263         ESex                            mSex;
00264         U32                                     mAppearanceSerialNum;
00265         U32                                     mSkeletonSerialNum;
00266         LLAnimPauseRequest      mPauseRequest;
00267 
00268 
00269 private:
00270         // visual parameter stuff
00271         typedef std::map<S32, LLVisualParam *>    VisualParamIndexMap_t;
00272         VisualParamIndexMap_t mVisualParamIndexMap;
00273         VisualParamIndexMap_t::iterator mCurIterator;
00274         typedef std::map<char *, LLVisualParam *> VisualParamNameMap_t;
00275         VisualParamNameMap_t  mVisualParamNameMap;
00276 
00277         static LLStringTable sVisualParamNames; 
00278 };
00279 
00280 #endif // LL_LLCHARACTER_H
00281 

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