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

Generated on Thu Jul 1 06:08:21 2010 for Second Life Viewer by  doxygen 1.4.7