HBhvBehaviorManager.h
Go to the documentation of this file.
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
14 #ifndef _H_HBhvBehaviorManager_H
15 #define _H_HBhvBehaviorManager_H
16 
17 #ifdef H_PACK_8
18 #pragma pack(push)
19 #pragma pack(8)
20 #endif
21 
22 #include "HTools.h"
23 #include "HTManager.h"
24 #include "HBhvUtility.h"
25 #include "HBhvInterpolator.h"
26 
27 class HBhvTimeline;
28 class HBhvInterpolator;
29 class HBhvAnimation;
30 class HUtilityXMLGenerator;
31 class HUtilityXMLTag;
32 class HBaseModel;
33 
34 
36 class HBhvSensor;
37 class HBaseView;
38 
41 {
48 };
49 
50 
52 
82 class MVO_API HBhvTargetObject
83 {
84 public:
92  HBhvTargetObject(HBhvBehaviorManager *behaviourmanager, const char *name, const char *path, HPoint *pivot = 0);
93 
94 
96  const char *GetName() { return m_Name; }
97 
99  const char *GetPath() { return m_Path; }
100 
102  HC_KEY GetTargetKey();
103 
104  void SetTargetKey(HC_KEY key) { m_key = key; }
105 
107  const char *GetResolvedPath() { return m_ResolvedPath; }
108 
111  const char *GetType() { return m_Type; }
112 
118  bool IsEqual(const char *target);
119 
121  HBhvCameraType GetCameraType() { return m_CameraType; }
122 
132  static void ResolveTarget(const char *in, char *result, char *targettype, HBaseModel *model, HBhvCameraType &ctype);
133 
134  static void CreateTargetString(const char *type, const char *path, char *result, bool addquotes = false);
145 
149  void SetPivot(HPoint pv) { m_Pivot = pv; }
150 
158  void SetCollision(bool collision) { m_bCollision = collision; }
159 
161  bool GetCollision() { return m_bCollision; }
162 
168  void SetPivot(float x, float y, float z) { m_Pivot.Set(x,y,z); }
169 
171  void GetPivot(HPoint &pv) { pv = m_Pivot; }
172 
174  HPoint * GetPivot() { return &m_Pivot; }
175 
180  void Serialize(HUtilityXMLGenerator *xmlgen);
181 
185  static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData);
186  /*
187  void CalculateAdjustedPosition(HBhvTargetObject *parent);
188  void AdjustChildTargets();
189  void AddChildTarget(HBhvTargetObject *child);
190  void GetTranslationFromMatrix(HPoint &t);
191  void AddRotationToMatrix(float rot[16], float outrot[16]);
192  void AddPositionToMatrix(HPoint &trans);
193  void SetConstraintPoint(float x, float y, float z) { m_constrainpoint.Set(x,y,z); }
194  void SetLimitAxis(float x, float y, float z) { m_limitaxis.Set(x,y,z); }
195  */
196 
199  void FlagForCollision() { m_bHasMoved = true; }
202  void ResetForCollision() { m_bHasMoved = false; }
204  bool HasMoved() { return m_bHasMoved; }
205  void SetSerializeFromKey( bool sfk ) { m_bSerializeFromKey = sfk; }
206 
207 
208 protected:
210  static void CollapseTarget(const char *target, char *collapsedtarget);
211 
212  char m_Name[MVO_SMALL_BUFFER_SIZE];
213  char m_Path[MVO_SEGMENT_PATHNAME_BUFFER];
214  char m_ResolvedPath[MVO_SEGMENT_PATHNAME_BUFFER];
215  char m_Type[MVO_SMALL_BUFFER_SIZE];
216  HC_KEY m_key;
221  bool m_bHasMoved;
222 // struct vlist_s * m_ChildTargetList;
223 // HPoint m_limitaxis;
224 // HPoint m_constrainpoint;
225 // HBhvTargetObject* m_ParentTarget;
226  bool m_bSerializeFromKey;
227 };
228 
229 
230 
232 
237 class MVO_API HBhvBehaviorManager : public HTClient
238 {
239 public:
250  HBhvBehaviorManager(HBaseModel *model, int tps = 10, int delay = 0, const char *name = 0, const char *version = 0, const char *vendor = 0);
251  virtual ~HBhvBehaviorManager();
252 
256  void SetTicksPerSecond(int tps) { m_Tps = tps; }
259  int GetTicksPerSecond() { return m_Tps; }
260 
265  void Serialize(HUtilityXMLGenerator *xmlgen);
266 
272  void ScheduleAnimation(HBhvAnimation* animation, float currenttime);
273 
283  HBhvAnimation * AddAnimation(const char *name, const char *target , HBhvTimeline *timeline, HBhvInterpolator *interpolator);
284 
289  void AddAnimation(HBhvAnimation *animation);
290 
295  virtual bool Tick( float request_time, float actual_time );
296 
299  vlist_s * GetAnimationList() { return m_AnimationList; }
300 
301 
305  int GetFreeName();
306 
308  void DeleteAllAnimations();
309 
317  HBhvAnimation * FindAnimation(const char *target, const char *interpolatortype);
318 
324  HBhvAnimation * FindAnimationByName(const char *name);
325 
329  void ScheduleAllAnimations(bool reset = false);
330 
335  void DeleteAnimation(HBhvAnimation *animation);
336 
345  HBhvTargetObject * CreateTargetObjectByPath(const char *name, const char *path);
346 
351  void AddTargetObject(HBhvTargetObject *targetobject);
352 
359  HBhvTargetObject * FindTargetObjectByName(const char *name);
360 
366  HBhvTargetObject * FindTargetObjectByPath(const char *path);
367 
372  void WriteToFile(const __wchar_t *filename);
373 #ifdef _MSC_VER
374  void WriteToFile(const unsigned short *filename);
375 #endif
376  void WriteToFile(const char *filename);
377 
383  static void ReadFromFile(HBaseModel *model, const __wchar_t *filename);
384 #ifdef _MSC_VER
385  static void ReadFromFile(HBaseModel *model, const unsigned short *filename);
386 #endif
387  static void ReadFromFile(HBaseModel *model, const char *filename);
388 
394  static void ProcessXMLData(HBaseModel *model, const char *buffer);
395 
399  static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData);
400 
402  HBaseModel * GetModel() { return m_pModel; }
403 
407  void SetCurrentTickByTime(float t) { m_CurrentTick = (t - m_StartTime) * m_Tps; }
408 
412  void SetCurrentTick(float tick);
413 
415  void SetCurrentTick();
416 
418  float GetCurrentTick() { return m_CurrentTick; }
419 
422  void SetCurrentTickByPercentage(float percentage);
423 
425  float GetCurrentTickByPercentage();
426 
428  void Rewind();
429 
431  bool IsPlaying() { return m_bPlaying; }
432 
434  HC_KEY GetActiveSceneKey();
435 
438  void SetActiveView(HBaseView *view);
439 
441  HBaseView * GetActiveView() { return m_pView; }
442 
444  bool GetRenderEveryTick() { return m_bRenderEveryFrame; }
445 
448  void SetRenderEveryTick(bool everytick) { m_bRenderEveryFrame = everytick; }
449 
451  bool GetUpdateCamera() { return m_bUpdateCamera; }
452 
454  bool IsAtFinalTick();
455 
458  void SetUpdateCamera(bool updatecamera) { m_bUpdateCamera = updatecamera; }
459 
465  int GetNextKeyframe(int ticknum, bool forward);
466 
469  void AddSensor(HBhvSensor *sensor);
470 
473  void RemoveScheduledAnimation(HBhvAnimation *animation);
474 
476  bool HasAnimations();
477 
479  int GetLastTick();
480 
484  HBhvSensor * FindSensorByName(const char *name);
485 
489  void ExecuteAnimations(float currenttick, float starttick);
490 
495  void SetContinuousPlay(bool cont) { m_bContinuousPlay = cont; }
496 
502  void SetInfinitePlay(bool inf) { m_bInfinitePlay = inf; }
503 
507  bool GetContinuousPlay() { return m_bContinuousPlay; }
508 
510  void CameraUpdated() { m_bCameraUpdated = true; }
511 
513  bool GetCameraUpdated() { return m_bCameraUpdated; }
514 
517  void Play();
518 
520  void Stop();
521 
523  void Continue();
524 
527  void SetPositionMatrix(float *mat) { for (int i=0;i<16;i++) m_positionmatrix[i] = mat[i]; }
529  void GetPositionMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_positionmatrix[i]; }
533  void SetTargetMatrix(float *mat) { for (int i=0;i<16;i++) m_targetmatrix[i] = mat[i]; }
536  void GetTargetMatrix(float *mat) { for (int i=0;i<16;i++) mat[i] = m_targetmatrix[i]; }
539  void SetFov(float fov) { m_fov = fov; }
541  void GetFov(float fov) { UNREFERENCED(fov); }
542 
544  void Reset();
545 
548  void DeactivateAllAnimations();
551  void ActivateAllAnimations();
556  void ActivateAnimationByName(const char *name, bool AllowPartial = true);
561  void DeactivateAnimationByName(const char *name, bool AllowPartial = true);
562 
563 
567  void SetStartTime(float time) { m_StartTime = time; }
568 
572  void SetMerge(bool merge) { m_bMerge = merge; }
574  bool GetMerge() { return m_bMerge; }
575 
581  HBhvAnimation * AddAnimation(const char *name, const char *targetpath, HPoint *pivot);
582 
590  void AddPositionKeyframe(const char *animname, int tick, HPoint pos, bool linear);
597  void AddQuatSquadKeyframe(const char *animname, int tick, HQuat rot, bool linear);
603  void AddMatrixKeyframe(const char *animname, int tick, float matrix[]);
611  void AddSegmentMoveKeyframe(const char *animname, int tick, char *path);
622  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);
629  void AddAxisRotateKeyframe(const char *animname, int tick, float rot, HPoint *axis = 0);
636  void AddColorKeyframe(const char *animname, int tick, HPoint color, const char *colorcomponent = 0, const char *geomtype = 0);
641  void AddScaleKeyframe(const char *animname, int tick, HPoint scale);
647  void AddAttributeSwitchKeyframe(const char *animname, int tick, const char *att);
654  void AddVertexMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete);
662  void AddColorMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete);
668  void AddSegmentSwitchKeyframe(const char *animname, int tick, const char *ss);
674  void AddInstanceCreateKeyframe(const char *animname, int tick, const char *instance);
675 
684  void AddVertexMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1);
693  void AddColorMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1);
694 
695 
696 protected:
697 
701  void ResolveInstances();
702 
706  bool EvaluateCollision(HBhvTargetObject *tob);
712  HBhvInterpolator * AddKeyframe(const char *animname, const char *IntType, HKeyframe *keyframe, int tick);
713 
714  char m_Name[BHV_MAX_NAME_LENGTH];
715  char m_Version[BHV_MAX_VERSION_LENGTH];
716  char m_Vendor[BHV_MAX_VENDOR_LENGTH];
717  int m_Tps;
718  int m_Delay;
719  float m_StartTime;
723  struct vlist_s * m_AnimationList;
724  struct vlist_s * m_ScheduledAnimationList;
725  struct vlist_s * m_TargetObjectList;
726  struct vlist_s * m_SensorList;
729  bool m_bPlaying;
735  float m_positionmatrix[16];
736  float m_targetmatrix[16];
737  float m_fov;
739  bool m_bMerge;
741  bool m_bShellSelectionActive;
742 };
743 
744 
745 
746 #ifdef H_PACK_8
747 #pragma pack(pop)
748 #endif
749 
750 #endif
void SetStartTime(float time)
Definition: HBhvBehaviorManager.h:567
void SetCurrentTickByTime(float t)
Definition: HBhvBehaviorManager.h:407
void GetPositionMatrix(float *mat)
Definition: HBhvBehaviorManager.h:529
The HBhvTimeline class encpasulates an animation timeline.
Definition: HBhvTimeline.h:38
The HKeyframe class is the base class for all keyframe types.
Definition: HBhvUtility.h:257
const char * GetResolvedPath()
Definition: HBhvBehaviorManager.h:107
void SetMerge(bool merge)
Definition: HBhvBehaviorManager.h:572
int m_LastTick
Definition: HBhvBehaviorManager.h:721
The HQuat class defines the data type of a Quaternion.
Definition: HBhvUtility.h:83
const char * GetName()
Definition: HBhvBehaviorManager.h:96
const char * GetPath()
Definition: HBhvBehaviorManager.h:99
void SetPositionMatrix(float *mat)
Definition: HBhvBehaviorManager.h:527
bool m_bCollision
Definition: HBhvBehaviorManager.h:220
The HBhvBehaviorManager class stores and manages all animation related data.
Definition: HBhvBehaviorManager.h:237
bool m_bInfinitePlay
Definition: HBhvBehaviorManager.h:738
void GetPivot(HPoint &pv)
Definition: HBhvBehaviorManager.h:171
void FlagForCollision()
Definition: HBhvBehaviorManager.h:199
HBhvBehaviorManager * m_pBehaviorManager
Definition: HBhvBehaviorManager.h:217
HPoint m_Pivot
Definition: HBhvBehaviorManager.h:219
bool m_bHasMoved
Definition: HBhvBehaviorManager.h:221
struct vlist_s * m_TargetObjectList
Definition: HBhvBehaviorManager.h:725
HBaseModel * GetModel()
Definition: HBhvBehaviorManager.h:402
#define BHV_MAX_NAME_LENGTH
Maximum Length of "Names" in animations.
Definition: HBhvUtility.h:41
bool m_bMerge
Definition: HBhvBehaviorManager.h:739
void CameraUpdated()
Definition: HBhvBehaviorManager.h:510
float m_fov
Definition: HBhvBehaviorManager.h:737
int m_Tps
Definition: HBhvBehaviorManager.h:717
void SetInfinitePlay(bool inf)
Definition: HBhvBehaviorManager.h:502
void GetTargetMatrix(float *mat)
Definition: HBhvBehaviorManager.h:536
Definition: HTManager.h:157
bool m_bContinuousPlay
Definition: HBhvBehaviorManager.h:733
int GetTicksPerSecond()
Definition: HBhvBehaviorManager.h:259
void SetRenderEveryTick(bool everytick)
Definition: HBhvBehaviorManager.h:448
vlist_s * GetAnimationList()
Definition: HBhvBehaviorManager.h:299
void ResetForCollision()
Definition: HBhvBehaviorManager.h:202
HPoint * GetPivot()
Definition: HBhvBehaviorManager.h:174
struct vlist_s * m_SensorList
Definition: HBhvBehaviorManager.h:726
int m_Delay
Definition: HBhvBehaviorManager.h:718
HBaseView * m_pView
Definition: HBhvBehaviorManager.h:730
The HBhvTargetObject class encapsulates various target types for animations and sensors.
Definition: HBhvBehaviorManager.h:82
There is no camera animation.
Definition: HBhvBehaviorManager.h:42
bool m_bCameraUpdated
Definition: HBhvBehaviorManager.h:734
The HBhvInterpolator class is the abstract base class for all interpolator types. ...
Definition: HBhvInterpolator.h:64
float GetCurrentTick()
Definition: HBhvBehaviorManager.h:418
The camera target is independently defined but works in conjunction with CameraPositionFree.
Definition: HBhvBehaviorManager.h:45
bool GetRenderEveryTick()
Definition: HBhvBehaviorManager.h:444
bool m_bRenderEveryFrame
Definition: HBhvBehaviorManager.h:731
The HBhvSensor class encapsulates an animation sensor.
Definition: HBhvSensor.h:33
bool GetContinuousPlay()
Definition: HBhvBehaviorManager.h:507
The HBaseModel class is used to store and manage model information.
Definition: HBaseModel.h:47
void SetPivot(float x, float y, float z)
Definition: HBhvBehaviorManager.h:168
void GetFov(float fov)
Definition: HBhvBehaviorManager.h:541
bool IsPlaying()
Definition: HBhvBehaviorManager.h:431
The HPoint class is the data type of a three-dimensional point.
Definition: HGlobals.h:121
float m_CurrentTick
Definition: HBhvBehaviorManager.h:720
void SetFov(float fov)
Definition: HBhvBehaviorManager.h:539
The HBaseView class defines and manages a view of model information.
Definition: HBaseView.h:332
HBhvCameraType m_CameraType
Definition: HBhvBehaviorManager.h:218
bool GetMerge()
Definition: HBhvBehaviorManager.h:574
Animation keyframe defines the camera target and position.
Definition: HBhvBehaviorManager.h:47
bool GetCameraUpdated()
Definition: HBhvBehaviorManager.h:513
The HBhvAnimation class defines an animation.
Definition: HBhvAnimation.h:43
bool GetUpdateCamera()
Definition: HBhvBehaviorManager.h:451
virtual bool Tick(float request_time, float actual_time)
Definition: HTManager.h:186
HBhvCameraType GetCameraType()
Definition: HBhvBehaviorManager.h:121
struct vlist_s * m_AnimationList
Definition: HBhvBehaviorManager.h:723
Animation is position driven. The target location is derived from the position location.
Definition: HBhvBehaviorManager.h:44
HBaseModel * m_pModel
Definition: HBhvBehaviorManager.h:728
bool m_bUpdateCamera
Definition: HBhvBehaviorManager.h:732
The camera position is independently defined but works in conjunction with CameraTargetFree.
Definition: HBhvBehaviorManager.h:46
HBhvCameraType
Definition: HBhvBehaviorManager.h:40
#define BHV_MAX_VENDOR_LENGTH
Maximum Length of "Vendor" string.
Definition: HBhvUtility.h:43
void SetContinuousPlay(bool cont)
Definition: HBhvBehaviorManager.h:495
bool m_bPlaying
Definition: HBhvBehaviorManager.h:729
float m_StartTime
Definition: HBhvBehaviorManager.h:719
HBaseView * GetActiveView()
Definition: HBhvBehaviorManager.h:441
Animation is target driven. The position location is derived from the target location.
Definition: HBhvBehaviorManager.h:43
void SetTicksPerSecond(int tps)
Definition: HBhvBehaviorManager.h:256
void SetCollision(bool collision)
Definition: HBhvBehaviorManager.h:158
struct vlist_s * m_ScheduledAnimationList
Definition: HBhvBehaviorManager.h:724
void SetPivot(HPoint pv)
Definition: HBhvBehaviorManager.h:149
bool GetCollision()
Definition: HBhvBehaviorManager.h:161
bool HasMoved()
Definition: HBhvBehaviorManager.h:204
void SetTargetMatrix(float *mat)
Definition: HBhvBehaviorManager.h:533
const char * GetType()
Definition: HBhvBehaviorManager.h:111
HC_KEY m_key
Definition: HBhvBehaviorManager.h:216
void SetUpdateCamera(bool updatecamera)
Definition: HBhvBehaviorManager.h:458
#define BHV_MAX_VERSION_LENGTH
Maximum Length of "Version" string.
Definition: HBhvUtility.h:42