00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 // $Id: de6f22bb028716b8ee80cd0baf4928b3521009a1 $ 00013 // 00018 #ifndef _H_HBhvBehaviorManager_H 00019 #define _H_HBhvBehaviorManager_H 00020 00021 #ifdef H_PACK_8 00022 #pragma pack(push) 00023 #pragma pack(8) 00024 #endif 00025 00026 #include "HTools.h" 00027 #include "HTManager.h" 00028 #include "HBhvUtility.h" 00029 #include "HBhvInterpolator.h" 00030 00031 class HBhvTimeline; 00032 class HBhvInterpolator; 00033 class HBhvAnimation; 00034 class HUtilityXMLGenerator; 00035 class HUtilityXMLTag; 00036 class HBaseModel; 00037 00038 00039 class HBhvBehaviorManager; 00040 class HBhvSensor; 00041 class HBaseView; 00042 00044 enum HBhvCameraType 00045 { 00046 NoCamera, 00047 CameraTarget, 00048 CameraPosition, 00049 CameraTargetFree, 00050 CameraPositionFree, 00051 CameraPositionTarget 00052 }; 00053 00054 00056 00086 class MVO_API HBhvTargetObject 00087 { 00088 public: 00096 HBhvTargetObject(HBhvBehaviorManager *behaviourmanager, const char *name, const char *path, HPoint *pivot = 0); 00097 00098 00100 const char *GetName() { return m_Name; } 00101 00103 const char *GetPath() { return m_Path; } 00104 00106 HC_KEY GetTargetKey(); 00107 00108 void SetTargetKey(HC_KEY key) { m_key = key; } 00109 00111 const char *GetResolvedPath() { return m_ResolvedPath; } 00112 00115 const char *GetType() { return m_Type; } 00116 00122 bool IsEqual(const char *target); 00123 00125 HBhvCameraType GetCameraType() { return m_CameraType; } 00126 00136 static void ResolveTarget(const char *in, char *result, char *targettype, HBaseModel *model, HBhvCameraType &ctype); 00137 00138 static void CreateTargetString(const char *type, const char *path, char *result, bool addquotes = false); 00149 00153 void SetPivot(HPoint pv) { m_Pivot = pv; } 00154 00162 void SetCollision(bool collision) { m_bCollision = collision; } 00163 00165 bool GetCollision() { return m_bCollision; } 00166 00172 void SetPivot(float x, float y, float z) { m_Pivot.Set(x,y,z); } 00173 00175 void GetPivot(HPoint &pv) { pv = m_Pivot; } 00176 00178 HPoint * GetPivot() { return &m_Pivot; } 00179 00184 void Serialize(HUtilityXMLGenerator *xmlgen); 00185 00189 static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData); 00190 /* 00191 void CalculateAdjustedPosition(HBhvTargetObject *parent); 00192 void AdjustChildTargets(); 00193 void AddChildTarget(HBhvTargetObject *child); 00194 void GetTranslationFromMatrix(HPoint &t); 00195 void AddRotationToMatrix(float rot[16], float outrot[16]); 00196 void AddPositionToMatrix(HPoint &trans); 00197 void SetConstraintPoint(float x, float y, float z) { m_constrainpoint.Set(x,y,z); } 00198 void SetLimitAxis(float x, float y, float z) { m_limitaxis.Set(x,y,z); } 00199 */ 00200 00203 void FlagForCollision() { m_bHasMoved = true; } 00206 void ResetForCollision() { m_bHasMoved = false; } 00208 bool HasMoved() { return m_bHasMoved; } 00209 void SetSerializeFromKey( bool sfk ) { m_bSerializeFromKey = sfk; } 00210 00211 00212 protected: 00214 static void CollapseTarget(const char *target, char *collapsedtarget); 00215 00216 char m_Name[MVO_SMALL_BUFFER_SIZE]; 00217 char m_Path[MVO_SEGMENT_PATHNAME_BUFFER]; 00218 char m_ResolvedPath[MVO_SEGMENT_PATHNAME_BUFFER]; 00219 char m_Type[MVO_SMALL_BUFFER_SIZE]; 00220 HC_KEY m_key; 00221 HBhvBehaviorManager * m_pBehaviorManager; 00222 HBhvCameraType m_CameraType; 00223 HPoint m_Pivot; 00224 bool m_bCollision; 00225 bool m_bHasMoved; 00226 // struct vlist_s * m_ChildTargetList; 00227 // HPoint m_limitaxis; 00228 // HPoint m_constrainpoint; 00229 // HBhvTargetObject* m_ParentTarget; 00230 bool m_bSerializeFromKey; 00231 }; 00232 00233 00234 00236 00241 class MVO_API HBhvBehaviorManager : public HTClient 00242 { 00243 public: 00254 HBhvBehaviorManager(HBaseModel *model, int tps = 10, int delay = 0, const char *name = 0, const char *version = 0, const char *vendor = 0); 00255 virtual ~HBhvBehaviorManager(); 00256 00260 void SetTicksPerSecond(int tps) { m_Tps = tps; } 00263 int GetTicksPerSecond() { return m_Tps; } 00264 00269 void Serialize(HUtilityXMLGenerator *xmlgen); 00270 00276 void ScheduleAnimation(HBhvAnimation* animation, float currenttime); 00277 00287 HBhvAnimation * AddAnimation(const char *name, const char *target , HBhvTimeline *timeline, HBhvInterpolator *interpolator); 00288 00293 void AddAnimation(HBhvAnimation *animation); 00294 00299 virtual bool Tick( float request_time, float actual_time ); 00300 00303 vlist_s * GetAnimationList() { return m_AnimationList; } 00304 00305 00309 int GetFreeName(); 00310 00312 void DeleteAllAnimations(); 00313 00321 HBhvAnimation * FindAnimation(const char *target, const char *interpolatortype); 00322 00328 HBhvAnimation * FindAnimationByName(const char *name); 00329 00333 void ScheduleAllAnimations(bool reset = false); 00334 00339 void DeleteAnimation(HBhvAnimation *animation); 00340 00349 HBhvTargetObject * CreateTargetObjectByPath(const char *name, const char *path); 00350 00355 void AddTargetObject(HBhvTargetObject *targetobject); 00356 00363 HBhvTargetObject * FindTargetObjectByName(const char *name); 00364 00370 HBhvTargetObject * FindTargetObjectByPath(const char *path); 00371 00376 void WriteToFile(const __wchar_t *filename); 00377 #ifdef _MSC_VER 00378 void WriteToFile(const unsigned short *filename); 00379 #endif 00380 void WriteToFile(const char *filename); 00381 00387 static void ReadFromFile(HBaseModel *model, const __wchar_t *filename); 00388 #ifdef _MSC_VER 00389 static void ReadFromFile(HBaseModel *model, const unsigned short *filename); 00390 #endif 00391 static void ReadFromFile(HBaseModel *model, const char *filename); 00392 00398 static void ProcessXMLData(HBaseModel *model, const char *buffer); 00399 00403 static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData); 00404 00406 HBaseModel * GetModel() { return m_pModel; } 00407 00411 void SetCurrentTickByTime(float t) { m_CurrentTick = (t - m_StartTime) * m_Tps; } 00412 00416 void SetCurrentTick(float tick); 00417 00419 void SetCurrentTick(); 00420 00422 float GetCurrentTick() { return m_CurrentTick; } 00423 00426 void SetCurrentTickByPercentage(float percentage); 00427 00429 float GetCurrentTickByPercentage(); 00430 00432 void Rewind(); 00433 00435 bool IsPlaying() { return m_bPlaying; } 00436 00438 HC_KEY GetActiveSceneKey(); 00439 00442 void SetActiveView(HBaseView *view); 00443 00445 HBaseView * GetActiveView() { return m_pView; } 00446 00448 bool GetRenderEveryTick() { return m_bRenderEveryFrame; } 00449 00452 void SetRenderEveryTick(bool everytick) { m_bRenderEveryFrame = everytick; } 00453 00455 bool GetUpdateCamera() { return m_bUpdateCamera; } 00456 00458 bool IsAtFinalTick(); 00459 00462 void SetUpdateCamera(bool updatecamera) { m_bUpdateCamera = updatecamera; } 00463 00469 int GetNextKeyframe(int ticknum, bool forward); 00470 00473 void AddSensor(HBhvSensor *sensor); 00474 00477 void RemoveScheduledAnimation(HBhvAnimation *animation); 00478 00480 bool HasAnimations(); 00481 00483 int GetLastTick(); 00484 00488 HBhvSensor * FindSensorByName(const char *name); 00489 00493 void ExecuteAnimations(float currenttick, float starttick); 00494 00499 void SetContinuousPlay(bool cont) { m_bContinuousPlay = cont; } 00500 00506 void SetInfinitePlay(bool inf) { m_bInfinitePlay = inf; } 00507 00511 bool GetContinuousPlay() { return m_bContinuousPlay; } 00512 00514 void CameraUpdated() { m_bCameraUpdated = true; } 00515 00517 bool GetCameraUpdated() { return m_bCameraUpdated; } 00518 00521 void Play(); 00522 00524 void Stop(); 00525 00527 void Continue(); 00528 00531 void SetPositionMatrix(float *mat) { for (int i=0;i<16;i++) m_positionmatrix[i] = mat[i]; } 00533 void GetPositionMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_positionmatrix[i]; } 00537 void SetTargetMatrix(float *mat) { for (int i=0;i<16;i++) m_targetmatrix[i] = mat[i]; } 00540 void GetTargetMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_targetmatrix[i]; } 00543 void SetFov(float fov) { m_fov = fov; } 00545 void GetFov(float fov) { UNREFERENCED(fov); } 00546 00548 void Reset(); 00549 00552 void DeactivateAllAnimations(); 00555 void ActivateAllAnimations(); 00560 void ActivateAnimationByName(const char *name, bool AllowPartial = true); 00565 void DeactivateAnimationByName(const char *name, bool AllowPartial = true); 00566 00567 00571 void SetStartTime(float time) { m_StartTime = time; } 00572 00576 void SetMerge(bool merge) { m_bMerge = merge; } 00578 bool GetMerge() { return m_bMerge; } 00579 00585 HBhvAnimation * AddAnimation(const char *name, const char *targetpath, HPoint *pivot); 00586 00594 void AddPositionKeyframe(const char *animname, int tick, HPoint pos, bool linear); 00601 void AddQuatSquadKeyframe(const char *animname, int tick, HQuat rot, bool linear); 00607 void AddMatrixKeyframe(const char *animname, int tick, float *matrix); 00615 void AddSegmentMoveKeyframe(const char *animname, int tick, char *path); 00626 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); 00633 void AddAxisRotateKeyframe(const char *animname, int tick, float rot, HPoint *axis = 0); 00640 void AddColorKeyframe(const char *animname, int tick, HPoint color, const char *colorcomponent = 0, const char *geomtype = 0); 00645 void AddScaleKeyframe(const char *animname, int tick, HPoint scale); 00651 void AddAttributeSwitchKeyframe(const char *animname, int tick, const char *att); 00658 void AddVertexMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete); 00666 void AddColorMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete); 00672 void AddSegmentSwitchKeyframe(const char *animname, int tick, const char *ss); 00678 void AddInstanceCreateKeyframe(const char *animname, int tick, const char *instance); 00679 00688 void AddVertexMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1); 00697 void AddColorMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1); 00698 00699 00700 protected: 00701 00705 void ResolveInstances(); 00706 00710 bool EvaluateCollision(HBhvTargetObject *tob); 00716 HBhvInterpolator * AddKeyframe(const char *animname, const char *IntType, HKeyframe *keyframe, int tick); 00717 00718 char m_Name[BHV_MAX_NAME_LENGTH]; 00719 char m_Version[BHV_MAX_VERSION_LENGTH]; 00720 char m_Vendor[BHV_MAX_VENDOR_LENGTH]; 00721 int m_Tps; 00722 int m_Delay; 00723 float m_StartTime; 00724 float m_CurrentTick; 00725 int m_LastTick; 00727 struct vlist_s * m_AnimationList; 00728 struct vlist_s * m_ScheduledAnimationList; 00729 struct vlist_s * m_TargetObjectList; 00730 struct vlist_s * m_SensorList; 00732 HBaseModel * m_pModel; 00733 bool m_bPlaying; 00734 HBaseView * m_pView; 00735 bool m_bRenderEveryFrame; 00736 bool m_bUpdateCamera; 00737 bool m_bContinuousPlay; 00738 bool m_bCameraUpdated; 00739 float m_positionmatrix[16]; 00740 float m_targetmatrix[16]; 00741 float m_fov; 00742 bool m_bInfinitePlay; 00743 bool m_bMerge; 00745 bool m_bShellSelectionActive; 00746 }; 00747 00748 00749 00750 #ifdef H_PACK_8 00751 #pragma pack(pop) 00752 #endif 00753 00754 #endif