Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HBhvBehaviorManager.h
Go to the documentation of this file.
00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
00002 //
00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
00004 // and considered a trade secret as defined under civil and criminal statutes.
00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
00006 // unauthorized use or misappropriation of its trade secrets.  Use of this information
00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
00009 
00014 #ifndef _H_HBhvBehaviorManager_H
00015 #define _H_HBhvBehaviorManager_H
00016 
00017 #ifdef H_PACK_8
00018 #pragma pack(push)
00019 #pragma pack(8)
00020 #endif
00021 
00022 #include "HTools.h"
00023 #include "HTManager.h"
00024 #include "HBhvUtility.h"
00025 #include "HBhvInterpolator.h"
00026 
00027 class HBhvTimeline;
00028 class HBhvInterpolator;
00029 class HBhvAnimation;
00030 class HUtilityXMLGenerator;
00031 class HUtilityXMLTag;
00032 class HBaseModel;
00033 
00034 
00035 class HBhvBehaviorManager;
00036 class HBhvSensor;
00037 class HBaseView;
00038 
00040 enum HBhvCameraType
00041 {
00042     NoCamera,        
00043     CameraTarget,    
00044     CameraPosition,  
00045     CameraTargetFree,    
00046     CameraPositionFree,  
00047     CameraPositionTarget     
00048 };
00049 
00050 
00052 
00082 class MVO_API HBhvTargetObject
00083 {
00084 public:
00092     HBhvTargetObject(HBhvBehaviorManager *behaviourmanager, const char *name, const char *path, HPoint *pivot = 0);
00093 
00094  
00096     const char *GetName() { return m_Name; }
00097 
00099     const char *GetPath() { return m_Path; }
00100 
00102     HC_KEY GetTargetKey();
00103 
00104     void SetTargetKey(HC_KEY key) { m_key = key; }
00105 
00107     const char *GetResolvedPath() { return m_ResolvedPath; }
00108 
00111     const char *GetType() { return m_Type; }
00112 
00118     bool IsEqual(const char *target);
00119 
00121     HBhvCameraType GetCameraType() { return m_CameraType; }
00122 
00132     static void ResolveTarget(const char *in, char *result, char *targettype, HBaseModel *model, HBhvCameraType &ctype);
00133 
00134     static void CreateTargetString(const char *type, const char *path, char *result, bool addquotes = false);
00145 
00149     void SetPivot(HPoint pv) { m_Pivot = pv; }
00150 
00158     void SetCollision(bool collision) { m_bCollision = collision; }
00159 
00161     bool GetCollision() { return m_bCollision; }
00162 
00168     void SetPivot(float x, float y, float z) { m_Pivot.Set(x,y,z); }
00169 
00171     void GetPivot(HPoint &pv) { pv = m_Pivot; }
00172 
00174     HPoint * GetPivot() { return &m_Pivot; }
00175 
00180     void Serialize(HUtilityXMLGenerator *xmlgen);
00181 
00185     static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData);
00186     /*
00187     void CalculateAdjustedPosition(HBhvTargetObject *parent);
00188     void AdjustChildTargets();
00189     void AddChildTarget(HBhvTargetObject *child);
00190     void GetTranslationFromMatrix(HPoint &t);
00191     void AddRotationToMatrix(float rot[16], float outrot[16]);
00192     void AddPositionToMatrix(HPoint &trans);
00193     void SetConstraintPoint(float x, float y, float z) { m_constrainpoint.Set(x,y,z); }
00194     void SetLimitAxis(float x, float y, float z) { m_limitaxis.Set(x,y,z); }
00195     */
00196 
00199     void FlagForCollision() { m_bHasMoved = true; }
00202     void ResetForCollision() { m_bHasMoved = false; }
00204     bool HasMoved() { return m_bHasMoved; }
00205     void SetSerializeFromKey( bool sfk ) { m_bSerializeFromKey = sfk; }
00206     
00207  
00208 protected:
00210     static void CollapseTarget(const char *target, char *collapsedtarget);
00211 
00212     char                    m_Name[MVO_SMALL_BUFFER_SIZE];              
00213     char                    m_Path[MVO_SEGMENT_PATHNAME_BUFFER];        
00214     char                    m_ResolvedPath[MVO_SEGMENT_PATHNAME_BUFFER];
00215     char                    m_Type[MVO_SMALL_BUFFER_SIZE];              
00216     HC_KEY                  m_key;                                      
00217     HBhvBehaviorManager *   m_pBehaviorManager;                         
00218     HBhvCameraType          m_CameraType;                               
00219     HPoint                  m_Pivot;                                    
00220     bool                    m_bCollision;                               
00221     bool                    m_bHasMoved;                                
00222 //  struct vlist_s *        m_ChildTargetList;
00223 //  HPoint                  m_limitaxis;
00224 //  HPoint                  m_constrainpoint;
00225 //  HBhvTargetObject*       m_ParentTarget;
00226     bool m_bSerializeFromKey;
00227 };
00228 
00229 
00230 
00232 
00237 class MVO_API HBhvBehaviorManager : public HTClient
00238 {
00239 public:
00250     HBhvBehaviorManager(HBaseModel *model, int tps = 10, int delay = 0, const char *name = 0, const char *version = 0, const char *vendor = 0);
00251     virtual ~HBhvBehaviorManager();
00252 
00256     void  SetTicksPerSecond(int tps) { m_Tps =  tps; }
00259     int  GetTicksPerSecond() { return m_Tps; }
00260 
00265     void Serialize(HUtilityXMLGenerator *xmlgen);
00266  
00272     void ScheduleAnimation(HBhvAnimation* animation, float currenttime);
00273 
00283     HBhvAnimation * AddAnimation(const char *name, const char *target , HBhvTimeline *timeline, HBhvInterpolator *interpolator);
00284 
00289     void AddAnimation(HBhvAnimation *animation);
00290 
00295     virtual bool Tick( float request_time, float actual_time );
00296 
00299     vlist_s * GetAnimationList() { return m_AnimationList; }
00300 
00301  
00305     int GetFreeName();
00306 
00308     void DeleteAllAnimations();
00309 
00317     HBhvAnimation * FindAnimation(const char *target, const char *interpolatortype);
00318 
00324     HBhvAnimation * FindAnimationByName(const char *name);
00325 
00329     void ScheduleAllAnimations(bool reset = false);
00330 
00335     void DeleteAnimation(HBhvAnimation *animation);
00336     
00345     HBhvTargetObject * CreateTargetObjectByPath(const char *name, const char *path);
00346 
00351     void AddTargetObject(HBhvTargetObject *targetobject);
00352 
00359     HBhvTargetObject * FindTargetObjectByName(const char *name);
00360 
00366     HBhvTargetObject * FindTargetObjectByPath(const char *path);
00367 
00372     void WriteToFile(const __wchar_t *filename);
00373 #ifdef _MSC_VER
00374     void WriteToFile(const unsigned short *filename);
00375 #endif
00376     void WriteToFile(const char *filename);
00377 
00383     static void ReadFromFile(HBaseModel *model, const __wchar_t *filename);
00384 #ifdef _MSC_VER
00385     static void ReadFromFile(HBaseModel *model, const unsigned short *filename);
00386 #endif
00387     static void ReadFromFile(HBaseModel *model, const char *filename);
00388 
00394     static void ProcessXMLData(HBaseModel *model, const char *buffer);
00395 
00399     static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData);
00400 
00402     HBaseModel * GetModel() { return m_pModel; }
00403 
00407     void  SetCurrentTickByTime(float t) { m_CurrentTick =  (t - m_StartTime) * m_Tps; }
00408 
00412     void  SetCurrentTick(float tick);
00413 
00415     void  SetCurrentTick();
00416 
00418     float GetCurrentTick() { return m_CurrentTick; }    
00419 
00422     void SetCurrentTickByPercentage(float percentage); 
00423 
00425     float GetCurrentTickByPercentage();
00426 
00428     void Rewind();
00429 
00431     bool IsPlaying() { return m_bPlaying; }
00432 
00434     HC_KEY GetActiveSceneKey();
00435 
00438     void SetActiveView(HBaseView *view);
00439 
00441     HBaseView * GetActiveView() { return m_pView; }
00442 
00444     bool GetRenderEveryTick() { return m_bRenderEveryFrame; }
00445 
00448     void SetRenderEveryTick(bool everytick) { m_bRenderEveryFrame = everytick; }
00449 
00451     bool GetUpdateCamera() { return m_bUpdateCamera; }
00452 
00454     bool IsAtFinalTick();
00455 
00458     void SetUpdateCamera(bool updatecamera) { m_bUpdateCamera = updatecamera; }
00459 
00465     int GetNextKeyframe(int ticknum, bool forward);
00466 
00469     void AddSensor(HBhvSensor *sensor);
00470 
00473     void RemoveScheduledAnimation(HBhvAnimation *animation);
00474 
00476     bool HasAnimations();
00477 
00479     int GetLastTick();
00480 
00484     HBhvSensor * FindSensorByName(const char *name);
00485 
00489     void ExecuteAnimations(float currenttick, float starttick);
00490 
00495     void SetContinuousPlay(bool cont) { m_bContinuousPlay = cont; }
00496 
00502     void SetInfinitePlay(bool inf) { m_bInfinitePlay = inf; }
00503     
00507     bool GetContinuousPlay() { return m_bContinuousPlay; }
00508     
00510     void CameraUpdated() { m_bCameraUpdated = true; }
00511 
00513     bool GetCameraUpdated() { return m_bCameraUpdated; }
00514 
00517     void Play();
00518 
00520     void Stop();
00521 
00523     void Continue();
00524     
00527     void SetPositionMatrix(float *mat) { for (int i=0;i<16;i++) m_positionmatrix[i] = mat[i]; }
00529     void GetPositionMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_positionmatrix[i]; }
00533     void SetTargetMatrix(float *mat) { for (int i=0;i<16;i++) m_targetmatrix[i] = mat[i]; }
00536     void GetTargetMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_targetmatrix[i]; }
00539     void SetFov(float fov) { m_fov = fov; }
00541     void GetFov(float fov) { UNREFERENCED(fov); }
00542 
00544     void Reset();
00545 
00548     void DeactivateAllAnimations();
00551     void ActivateAllAnimations();
00556     void ActivateAnimationByName(const char *name, bool AllowPartial = true);
00561     void DeactivateAnimationByName(const char *name, bool AllowPartial = true);
00562 
00563     
00567     void SetStartTime(float time) { m_StartTime = time; }
00568 
00572     void SetMerge(bool merge) { m_bMerge = merge; }
00574     bool GetMerge() { return m_bMerge; }
00575 
00581     HBhvAnimation * AddAnimation(const char *name, const char *targetpath, HPoint *pivot);
00582     
00590     void AddPositionKeyframe(const char *animname, int tick, HPoint pos, bool linear);
00597     void AddQuatSquadKeyframe(const char *animname, int tick, HQuat rot, bool linear);
00603     void AddMatrixKeyframe(const char *animname, int tick, float *matrix);
00611     void AddSegmentMoveKeyframe(const char *animname, int tick, char *path);
00622     void AddTrailKeyframe(const char *animname, int tick, HPoint pos, bool linear, TrailInterpolatorType *trailtype = 0, int *weight = 0, const char *style =0, const char *color = 0);
00629     void AddAxisRotateKeyframe(const char *animname, int tick, float rot, HPoint *axis = 0);
00636     void AddColorKeyframe(const char *animname, int tick, HPoint color, const char *colorcomponent = 0, const char *geomtype = 0);
00641     void AddScaleKeyframe(const char *animname, int tick, HPoint scale);
00647     void AddAttributeSwitchKeyframe(const char *animname, int tick, const char *att);
00654     void AddVertexMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete);
00662     void AddColorMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete);
00668     void AddSegmentSwitchKeyframe(const char *animname, int tick, const char *ss);
00674     void AddInstanceCreateKeyframe(const char *animname, int tick, const char *instance);
00675     
00684     void AddVertexMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1);
00693     void AddColorMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1);
00694 
00695 
00696 protected:
00697 
00701     void    ResolveInstances();
00702 
00706     bool EvaluateCollision(HBhvTargetObject *tob);
00712     HBhvInterpolator * AddKeyframe(const char *animname, const char *IntType, HKeyframe *keyframe, int tick);
00713 
00714     char                m_Name[BHV_MAX_NAME_LENGTH];                
00715     char                m_Version[BHV_MAX_VERSION_LENGTH];              
00716     char                m_Vendor[BHV_MAX_VENDOR_LENGTH];                
00717     int                 m_Tps;                      
00718     int                 m_Delay;                    
00719     float               m_StartTime;                
00720     float               m_CurrentTick;              
00721     int                 m_LastTick;                 
00723     struct vlist_s *    m_AnimationList;            
00724     struct vlist_s *    m_ScheduledAnimationList;   
00725     struct vlist_s *    m_TargetObjectList;         
00726     struct vlist_s *    m_SensorList;               
00728     HBaseModel *        m_pModel;                   
00729     bool                m_bPlaying;                 
00730     HBaseView *         m_pView;                    
00731     bool                m_bRenderEveryFrame;        
00732     bool                m_bUpdateCamera;            
00733     bool                m_bContinuousPlay;          
00734     bool                m_bCameraUpdated;           
00735     float m_positionmatrix[16];                     
00736     float m_targetmatrix[16];                       
00737     float m_fov;                                
00738     bool                m_bInfinitePlay;            
00739     bool                m_bMerge;                   
00741     bool                m_bShellSelectionActive;
00742 };
00743 
00744 
00745 
00746 #ifdef H_PACK_8
00747 #pragma pack(pop)
00748 #endif
00749 
00750 #endif