# HBhvBehaviorManager

## Functions

| `HBhvBehaviorManager`
| `~HBhvBehaviorManager`
void | `SetTicksPerSecond`
int | `GetTicksPerSecond`
void | `Serialize`
void | `ScheduleAnimation`
HBhvAnimation * | `AddAnimation`
void | `AddAnimation`
bool | `Tick`
vlist_s * | `GetAnimationList`
int | `GetFreeName`
void | `DeleteAllAnimations`
HBhvAnimation * | `FindAnimation`
HBhvAnimation * | `FindAnimationByName`
void | `ScheduleAllAnimations`
void | `DeleteAnimation`
HBhvTargetObject * | `CreateTargetObjectByPath`
void | `AddTargetObject`
HBhvTargetObject * | `FindTargetObjectByName`
HBhvTargetObject * | `FindTargetObjectByPath`
void | `WriteToFile`
void | `WriteToFile`
HBaseModel * | `GetModel`
void | `SetCurrentTickByTime`
void | `SetCurrentTick`
void | `SetCurrentTick`
float | `GetCurrentTick`
void | `SetCurrentTickByPercentage`
float | `GetCurrentTickByPercentage`
void | `Rewind`
bool | `IsPlaying`
HC_KEY | `GetActiveSceneKey`
void | `SetActiveView`
HBaseView * | `GetActiveView`
bool | `GetRenderEveryTick`
void | `SetRenderEveryTick`
bool | `GetUpdateCamera`
bool | `IsAtFinalTick`
void | `SetUpdateCamera`
int | `GetNextKeyframe`
void | `AddSensor`
void | `RemoveScheduledAnimation`
bool | `HasAnimations`
int | `GetLastTick`
HBhvSensor * | `FindSensorByName`
void | `ExecuteAnimations`
void | `SetContinuousPlay`
void | `SetInfinitePlay`
bool | `GetContinuousPlay`
void | `CameraUpdated`
bool | `GetCameraUpdated`
void | `Play`
void | `Stop`
void | `Continue`
void | `SetPositionMatrix`
void | `GetPositionMatrix`
void | `SetTargetMatrix`
void | `GetTargetMatrix`
void | `SetFov`
void | `GetFov`
void | `Reset`
void | `DeactivateAllAnimations`
void | `ActivateAllAnimations`
void | `ActivateAnimationByName`
void | `DeactivateAnimationByName`
void | `SetStartTime`
void | `SetMerge`
bool | `GetMerge`
HBhvAnimation * | `AddAnimation`
void | `AddPositionKeyframe`
void | `AddQuatSquadKeyframe`
void | `AddMatrixKeyframe`
void | `AddSegmentMoveKeyframe`
void | `AddTrailKeyframe`
void | `AddAxisRotateKeyframe`
void | `AddColorKeyframe`
void | `AddScaleKeyframe`
void | `AddAttributeSwitchKeyframe`
void | `AddVertexMorphInterpolator`
void | `AddColorMorphInterpolator`
void | `AddSegmentSwitchKeyframe`
void | `AddInstanceCreateKeyframe`
void | `AddVertexMorphDataToAnimation`
void | `AddColorMorphDataToAnimation`
void | `ReadFromFile`
void | `ReadFromFile`
void | `ProcessXMLData`
void * | `XMLCallback`

## Detailed Description

class HBhvBehaviorManager : public HTClient

  The HBhvBehaviorManager class stores and manages all animation related data.

  The HBhvBehaviorManager class stores a list of animations, sensors and target objects and manages them on a frame by frame basis. The animation logic assumes that it will be the only logic manipulating modelling matrices for any segment that it is operating on. If such segments already have modelling matrices, they will be replaced, and this may produce unexpected results. To address this, you could have the geometric primitives in any of these segments first be transformed through the modelling matrices.

  Public Functions

  HBhvBehaviorManager(HBaseModel *model, int tps = 10, int delay = 0, const char *name = 0, const char *version = 0, const char *vendor = 0)

    Constructs an HBhvBehaviorManager object.

    Parameters

      - model – A pointer to HBaseModel object that this BehaviorManager object belongs to.

      - tps – The ticks per second value for measuring time.

      - delay – The initial delay for this HBhvBehaviorManager object.

      - name – The name of the behavior manager.

      - version – Additional Version Information.

      - vendor – Additional Vendor Information.

  virtual ~HBhvBehaviorManager()
  inline void SetTicksPerSecond(int tps)

    This method set the number of ticks that will occur per second.

    Parameters

      tps – The number of ticks per second.

  inline int GetTicksPerSecond()
    Returns

      The number of ticks per second.

  void Serialize(HUtilityXMLGenerator *xmlgen)

    This method writes XML data to a buffer.

    Parameters

      xmlgen – A pointer to an XML generator that creates valid XML blocks.

  void ScheduleAnimation(HBhvAnimation *animation, float currenttime)

    This method schedules the given animation for immediate execution.

    Parameters

      - animation – A pointer to the animation you want to schedule for execution

      - currenttime – The start time for the animation in ticks.

  HBhvAnimation *AddAnimation(const char *name, const char *target, HBhvTimeline *timeline, HBhvInterpolator *interpolator)

    This method creates a new animation based on given name, target, timeline and interpolator. Then it adds the new animation to the animation list.

    Parameters

      - name – The name of the new animation.

      - target – A pointer to the target for the new animation.

      - timeline – A pointer to the timeline for the new animation.

      - interpolator – A pointer to the interpolator for the new animation.

    Returns

      A pointer to the newly created animation.

  void AddAnimation(HBhvAnimation *animation)

    This method adds a given animation to the animation list.

    Parameters

      animation – Animation to add to animation list

  virtual bool Tick(float request_time, float actual_time)

    The timer method that gets called from the HTManager::Tick() function. This method updates the current time and executes animations that are scheduled for the current time.

  inline vlist_s *GetAnimationList()
    Returns

      A pointer to the current animation list. Note this information is for read-only purpose. To modify any information in animation list, please use the methods provided by this class.

  int GetFreeName()

    This utility method finds a unique animation name. This method only works if you are using an incremented naming scheme.

    Returns

      Unused int value indicating free name for a new animation.

  void DeleteAllAnimations()

    This method deletes all animations and associated objects

  HBhvAnimation *FindAnimation(const char *target, const char *interpolatortype)

    Searches for an animation that matches the given target string and interpolator type.

    Parameters

      - target – The target descriptor to search for in animation instance. You can use HBhvTargetObject::CreateTargetSting() to generate this string.

      - interpolatortype – The interpolator type to search for in animation instance.

    Returns

      A pointer to the matching animation or null if no animation was found.

  HBhvAnimation *FindAnimationByName(const char *name)

    Searches for an animation by name.

    Parameters

      name – The name of the animation instance.

    Returns

      A pointer to the matching animation or null if no animation was found.

  void ScheduleAllAnimations(bool reset = false)

    Places all animations in the scheduled animation list.

  void DeleteAnimation(HBhvAnimation *animation)

    Removes the given animation from the animation list and then deletes it.

    Parameters

      animation – Pass a pointer to the animation you want to delete.

  HBhvTargetObject *CreateTargetObjectByPath(const char *name, const char *path)

    This method takes the given name and target and searches through the target object list. If a target object corresponding to the name and path exists, it returns that target object. If there are no matches, it creates a new one with the given name and path and adds it to the target object list.

    Parameters

      - name – The name of the new target object.

      - path – The path of the new target object.

    Returns

      A newly created target object or an already existing target object.

  void AddTargetObject(HBhvTargetObject *targetobject)

    This method adds the given target object to the target object list.

    Parameters

      targetobject – The target object to added.

  HBhvTargetObject *FindTargetObjectByName(const char *name)

    This method searches the target object list for target object by name.

    Parameters

      name – The name of the target object.

    Returns

      A pointer to the target object with the given name or null if no target. object corresponding to the given name was found.

  HBhvTargetObject *FindTargetObjectByPath(const char *path)

    Searches for a target object given a path.

    Parameters

      path – The path of the target object.

    Returns

      A pointer to the target object with the given name or null if no target object was found.

  void WriteToFile(const __wchar_t *filename)

    Serializes all animation data to buffer and writes the buffer to a file.

    Parameters

      filename – The filename you want to create.

  void WriteToFile(const char *filename)
  inline HBaseModel *GetModel()
    Returns

      A pointer to the model object

  inline void SetCurrentTickByTime(float t)

    Sets the current tick based on a given time.

    Parameters

      t – The time in seconds.

  void SetCurrentTick(float tick)

    Set the current ticks. If the animation is currently playing, it will make an adjustment to m_StartTime based on the difference between old and new tick values.

    Parameters

      tick – The tick value.

  void SetCurrentTick()

    Set current tick based on current time.

  inline float GetCurrentTick()
    Returns

      The current tick value.

  void SetCurrentTickByPercentage(float percentage)

    Calculates the current tick based on a given percentage of total length of all animations.

    Parameters

      percentage – The percentage value used to calculate the current tick.

  float GetCurrentTickByPercentage()
    Returns

      The percentage value of the currrent tick in relation to the total length of all animations.

  void Rewind()

    Stops the execution of all animations and rewinds to the start.

  inline bool IsPlaying()
    Returns

      True if animations are currently playing or false if no animations are playing.

  HC_KEY GetActiveSceneKey()
    Returns

      The key to active scene. This key will be used for camera manipulation.

  void SetActiveView(HBaseView *view)

    Use this method to determine which view to apply camera manipulations.

    Parameters

      view – A pointer to the HBaseView object.

  inline HBaseView *GetActiveView()
    Returns

      A pointer to the HBaseView object which camera manipulations will be applied to.

  inline bool GetRenderEveryTick()
    Returns

      True if HOOPS will not interpolate between ticks and false if HOOPS will interpolate between ticks.

  inline void SetRenderEveryTick(bool everytick)

    Enables/disables interpolation between ticks.

    Parameters

      everytick – Pass true if you do not want interpolation between ticks and false if you want to interpolate between ticks.

  inline bool GetUpdateCamera()
    Returns

      True if HOOPS will update camera during animation and false if HOOPS will not update camera.

  bool IsAtFinalTick()
    Returns

      True if the current tick is greater than or equal to the last tick in the animation timeline.

  inline void SetUpdateCamera(bool updatecamera)

    Use this method to indicate if the camera should be updated during animations.

    Parameters

      updatecamera – Pass True to update camera or false if otherwise.

  int GetNextKeyframe(int ticknum, bool forward)

    Given a tick number, this method finds the next closest keyframe.

    Parameters

      - ticknum – The tick to calculate next keyframe from.

      - forward – Pass true to find next closest keyframe or false to find the previous closest keyframe.

    Returns

      The keyframe location in tick if a keyframe is found or the given ticknum if no keyframe was found.

  void AddSensor(HBhvSensor *sensor)

    This method adds a given sensor to the sensor list.

    Parameters

      sensor – Sensor to add to sensor list.

  void RemoveScheduledAnimation(HBhvAnimation *animation)

    Removes the specified animation from the animation list.

    Parameters

      animation – A pointer to the animation that you want removed.

  bool HasAnimations()
    Returns

      True if at least one animation exists or false if no animation exists.

  int GetLastTick()
    Returns

      The last tick of all items in the animation list.

  HBhvSensor *FindSensorByName(const char *name)

    Searches for a sensor by name.

    Parameters

      name – The name of the sensor to search for.

    Returns

      A pointer to the matching sensor or null if no sensor was found.

  void ExecuteAnimations(float currenttick, float starttick)

    Executes all the scheduled animations.

    Parameters

      - currenttick – The current time in ticks.

      - starttick – The start time in ticks. If you pass -1, currenttick will be the start time.

  inline void SetContinuousPlay(bool cont)

    Enables/disables continuous playing of the animation list. In other words, if continuous play is on, when the last tick is reached, everything is rewound and starts playing from the beginning again. Note that if infinite play is active, it will override the continuous play behavior.

    Parameters

      cont – Pass true to enable continuous play or false to play animations once.

  inline void SetInfinitePlay(bool inf)

    Enables/disables infinite play. If infinite play is active, then once the animation begins playing, it will continue to play pass the last tick of the timeline. This means that animations that are looped will continue to play while animations that are not looped will stop. Note that if inifinite play is active, it will override continuous play.

    Parameters

      inf – Pass true to set infinite play to active or false to set infinite play to inactive.

  inline bool GetContinuousPlay()
    Returns

      True if the animation list loops continuously and false if the animation will only play through once and then stop. Note that if infinite play is active, it will override the continuous play behavior.

  inline void CameraUpdated()

    Use this method to indicate that camera was updated during animation.

  inline bool GetCameraUpdated()
    Returns

      True if camera has been changed during animation and false if the camera has not been changed.

  void Play()

    Starts the execution of items on the animation list, registers with MVO timer and starts playing at the start time.

  void Stop()

    Pauses the execution of the items on the scheduled animation list.

  void Continue()

    Reactivates the execution of items on the schedule animation list.

  inline void SetPositionMatrix(float *mat)

    Sets temporary position matrix used by interpolators for camera interpolation.

    Parameters

      mat – The position matrix.

  inline void GetPositionMatrix(float *mat)

    Returns the position matrix used by interpolators for camera interpolation.

  inline void SetTargetMatrix(float *mat)

    Sets the temporary modelling matrix for the target object. This matrix is used by interpolators for camera interpolation.

    Parameters

      mat – The modelling matrix.

  inline void GetTargetMatrix(float *mat)
    Returns

      The temporary modelling matrix for the target object. This matrix is used by interpolators for camera interpolation.

  inline void SetFov(float fov)

    This method has not been implemented yet.

    Parameters

      fov –

  inline void GetFov(float fov)

    This method has not been implemented yet.

  void Reset()

    Resets all animations.

  void DeactivateAllAnimations()

    This method deactivates all the items in the animation list. If an animation is deactivated, it can only be triggered by a sensor.

  void ActivateAllAnimations()

    This method activates all items on the animation list. When animations are not active, they can only be triggered by sensors.

  void ActivateAnimationByName(const char *name, bool AllowPartial = true)

    This method activates an animation given its partial or full name. When an animation is deactivated, it can only be triggered by a sensor.

    Parameters

      - name – The name of the animation.

      - AllowPartial – Pass true if you want to allow a partial name to be used for determining animation.

  void DeactivateAnimationByName(const char *name, bool AllowPartial = true)

    This method deactivates an animation given its full or partial name. When an animation is deactivated, it can only be triggered by a sensor.

    Parameters

      - name – The name of the animation.

      - AllowPartial – Pass true if you want to allow a partial name to be used for determining animation.

  inline void SetStartTime(float time)

    Sets the animation start time. The HBhvBehaviorManager will use this time as a referenced start time for all its calculations as it iterates through the timeline’s array of keyframes.

    Parameters

      time – The start time of the animation.

  inline void SetMerge(bool merge)

    Determines if loaded animation data is merged into existing animation.

    Parameters

      merge – Pass true if you want to merge animation data.

  inline bool GetMerge()
    Returns

      True if new animation data is merged with existing animation.

  HBhvAnimation *AddAnimation(const char *name, const char *targetpath, HPoint *pivot)

    This method creates a new named animation.

    Parameters

      - name – The name of the new animation

      - targetpath – Segment Path specifying the segment the animation should operate on

      - pivot – Center Point of the target (allows for off-center rotation)

    Returns

      Pointer to newly created Animation Object

  void AddPositionKeyframe(const char *animname, int tick, HPoint pos, bool linear)

    This method creates a new position keyframe for a given animation. The position keyframe allows you to specify a new position for your target object. The interpolated path can be a linear or spline movement.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - pos – 3d coordinate of keyframe

      - linear – Specifies if keyframe defines linear movement or spline movement

  void AddQuatSquadKeyframe(const char *animname, int tick, HQuat rot, bool linear)

    This method creates a new quaternion keyframe for a given animation. The quaternion key frame lets you specify a rotation for your target object.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - rot – Quaternion for keyframe

      - linear – Specifies if keyframe defines linear rotation or non linear rotation

  void AddMatrixKeyframe(const char *animname, int tick, float matrix[])

    This method creates a new matrix keyframe for a given animation. Pass a matrix that describe the rotation you want for your target object.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - matrix – matrix describing the transformation for the keyframe

  void AddSegmentMoveKeyframe(const char *animname, int tick, char *path)

    This method creates a new Segment Move keyframe for a given animation. The current implementation only allows one keyframe of this animation type to exist in a timeline. The segment move keyframe allows you to change the segment path of your target object.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - path – Segment path for keyframe that defines where to move segment to. The leaf segment of the path will be replaced by the name of the target segment

  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)

    This method creates a new trail keyframe for a given animation. Adding a trail keyframe tells HOOPS to draw a line from the position of the previous keyframe to the position of the keyframe you are adding.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - pos – 3d coordinate of keyframe

      - linear – Specifies if keyframe defines linear movement or spline movement

      - trailtype – Trailtype for all keyframes

      - weight – Trail weight for all keyframes

      - style – Line style for all keyframes

      - color – Color for all keyframes

  void AddAxisRotateKeyframe(const char *animname, int tick, float rot, HPoint *axis = 0)

    This method creates a new Axis Rotate keyframe for a given animation. The axis rotate keyframe lets you specify the angle of rotation and axis of rotation for you target object.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - rot – Angle of rotation of keyframe

      - axis – Axis of rotation for all keyframes

  void AddColorKeyframe(const char *animname, int tick, HPoint color, const char *colorcomponent = 0, const char *geomtype = 0)

    This method creates a new color keyframe for a given animation.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - color – rgb color specification for keyframe

      - colorcomponent – Color component (diffuse, specular,…) for all keyframes

      - geomtype – Geometry Type the color applies to for all keyframes

  void AddScaleKeyframe(const char *animname, int tick, HPoint scale)

    This method creates a new scale keyframe for a given animation.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - pos – x/y/z/ scale values for keyframe

  void AddAttributeSwitchKeyframe(const char *animname, int tick, const char *att)

    This method creates a new Attribute Switch keyframe for a given animation. They attribute switch keyframes changes they attributes of your target object by giving it the specified style segment.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - att – Path to segment containing attributes for keyframe

  void AddVertexMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete)

    This method creates a new vertex morph keyframe for a given animation. This interpolator’s behavior is described in more detail under the AddVertexMorphDataToAnimation method.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - mident – Vertex Morph Data Index

      - discrete – Specifies either discrete switching between morph data or interpolation for keyframe

  void AddColorMorphInterpolator(const char *animname, int tick, const char *mident, bool discrete)

    This method creates a new color morph keyframe for a given animation. A color morph keyframe tell HOOPS to perform an interpolation on the face colors of your target object from the previous keyframe to the new keyframe. This method in conjunction with AddColorMorphDataToAnimation.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - mident – Color Morph Data Index

      - discrete – Specifies either discrete switching between morph data or interpolation for keyframe

  void AddSegmentSwitchKeyframe(const char *animname, int tick, const char *ss)

    This method creates a new Segment Switch keyframe for a given animation. This segment switch keyframe unset the visibility of the object specified in the keyframe.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - ss – Path to segment for which visibility should be turned on for keyframe

  void AddInstanceCreateKeyframe(const char *animname, int tick, const char *instance)

    This method creates a new Instance Create keyframe for a given animation. This keyframe creates another instance of the target object in the segment tree specified.

    Parameters

      - animname – The name of the animation

      - tick – Location of new keyframe in timeline

      - instance – Path to instance which should be created for keyframe

  void AddVertexMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1)

    This method adds vertex morph information to a given animation. This function supplies the actual point array and associates an index to it (the first inserted point array has the index 0, the second index 1, etc) This method should be called AFTER defining the interpolator keyframe list using the AddVertexMorphInterpolator method.

    Parameters

      - md – Pointer to morph data vertex list

      - pnum – Number of points in vertex list

      - model – Point to HBaseModel object

      - pos – Position to add morph data to

  void AddColorMorphDataToAnimation(const char *animname, HPoint *md, int pnum, HBaseModel *model, int pos = -1)

    This method adds color morph information to a given animation. This function supplies the actual point array and associates an index to it (the first inserted point array has the index 0, the second index 1, etc) This method should be called AFTER defining the interpolator keyframe list using the AddColorMorphInterpolator method.

    Parameters

      - md – Pointer to morph data rgb color list

      - pnum – Number of points in rgb color list

      - model – Point to HBaseModel object

      - pos – Position to add morph data to

  Public Static Functions

  static void ReadFromFile(HBaseModel *model, const __wchar_t *filename)

    Reads XML data containing animation tags from a file and loads it into memory.

    Parameters

      - model – A pointer to the HBaseModel object.

      - filename – Filename

  static void ReadFromFile(HBaseModel *model, const char *filename)
  static void ProcessXMLData(HBaseModel *model, const char *buffer)

    Sets up the XML parser to read animation related xml tags.

    Parameters

      - model – A pointer to the model object.

      - buffer – A pointer to the memory buffer containing XML data.

  static void *XMLCallback(HUtilityXMLTag *xt, bool open, void *m_pExtraData)

    This is XML read callback which parses XML data and then populates the member variables with the associated values.