This reference page is linked to from the following overview topics: Character Studio Plug-ins, Plug-in Base Classes, Writing Crowd Behavior Plug-ins.
All behaviors must inherit from this base class.
#include <bhvr.h>
Public Types |
|
enum | BEHAVIOR_TYPE { FORCE = 0, CONSTRAINT, ORIENTATION } |
Public Member Functions |
|
BaseBehavior () | |
Identification Functions
|
|
These functions are used to uniquely define the behavior and to describe its type. |
|
SClass_ID | SuperClassID () |
Returns the super class id of the behavior.
|
|
virtual void | SetName (const MCHAR *newname) |
Sets the name of the behavior. |
|
virtual const MCHAR * | GetName () |
Gets the name of the behavior. |
|
virtual BEHAVIOR_TYPE | BehaviorType () |
Returns the behavior's type, either FORCE,
CONSTRAINT, or ORIENTATION. |
|
virtual BOOL | IsWeightable () |
Queries whether or not the behavior may be
modified by the behavior weight scalar. |
|
virtual int | CanConvertToMaxScript () |
Queries whether or not the behavior can
convert itself to a script. |
|
Initialization Functions
|
|
These functions allow a behavior to initialize itself at different times during a simulation. They also allow a behavior to keep track of data associated with delegates assigned to it during a simulation. |
|
virtual void | SetUpDelegates (INodeTab &participants) |
Sends the behavior a list of all delegates
which will participate in the simulation. |
|
virtual void | BehaviorStarted (TimeValue t, INode *node) |
Notifies the behavior that it should start
to act upon a particular delegate. |
|
virtual void | InitAtThisTime (TimeValue t) |
Initializes a behavior at the start of each
simulation frame. |
|
virtual void | InitBeforeSim (int FirstFrame, INode *n, int SimStart, int AssignIndex) |
Initializes the behavior at the start of a
simulation. |
|
Performance Functions
|
|
These functions are called for each delegate assigned to a behavior, each frame during a simulation. Depending on the value returned from the BehaviorType function, only one of the following three functions must be implemented. |
|
virtual int | Perform (INode *node, TimeValue t, int numsubsamples, BOOL DisplayHelpers, float BhvrWeight, PerformOut &out) |
This is the main function for FORCE
behaviors. |
|
virtual int | Constraint (INode *node, TimeValue t, int numsubsamples, BOOL DesGoalExists, BOOL DisplayHelpers, BOOL finalSet, ConstraintInOut &inOut) |
This is the main function for CONSTRAINT
behaviors. |
|
virtual int | Orient (const Point3 &vel, INode *node, TimeValue t, Quat &quat) |
This is the main function for ORIENTATION
behaviors. |
|
Display Functions
|
|
These functions provide an option to display an apparatus along with the behavior at all times - not just during solve. The behavior can offer an option in its user interface to turn this on and off. Keep in mind this apparatus will be displayed as part of the crowd object, and so may enlarge the damaged rectangle significantly. |
|
virtual int | Display (TimeValue t, ViewExp *vpt) |
Using this function, a behavior can display
text or graphics inside the viewports. |
|
virtual void | GetWorldBoundBox (TimeValue t, ViewExp *vpt, Box3 &box) |
Gets the world bounding box of what the
behavior draws. |
enum BEHAVIOR_TYPE |
{ FORCE = 0, CONSTRAINT, ORIENTATION };
BaseBehavior | ( | ) | [inline] |
{}
SClass_ID SuperClassID | ( | ) | [inline, virtual] |
Returns the super class id of the behavior.
The default implementation should be used, to make certain that the new behavior class is recognized by the Crowd system and appears in the list of available behaviors inside Crowd. Use ClassID to define your own class id specific to your behavior.
Reimplemented from ReferenceTarget.
{ return BEHAVIOR_SUPER_CLASS_ID; }
virtual void SetName | ( | const MCHAR * | newname | ) | [inline, virtual] |
Sets the name of the behavior.
When the user changes the name of the behavior from the Crowd interface, this function is called. It should store the name in the behavior.
[in] | newname | - the new name of the behavior. |
{}
virtual const MCHAR* GetName | ( | void | ) | [inline, virtual] |
Gets the name of the behavior.
Usually this name will be stored internally within a paramblock. The name usually starts out being the same as the behavior's class name. The name can then be changed from within the Crowd system, which sets it by calling this function.
{return NULL;}
virtual BEHAVIOR_TYPE BehaviorType | ( | ) | [inline, virtual] |
Returns the behavior's type, either FORCE, CONSTRAINT, or ORIENTATION.
{return FORCE;}
virtual BOOL IsWeightable | ( | ) | [inline, virtual] |
Queries whether or not the behavior may be modified by the behavior weight scalar.
For the user, this weight appears in the assignment dialog for each assignment. Usually FORCE types are weightable, while CONSTRAINT and ORIENTATION behaviors aren't.
{if (BehaviorType() == BaseBehavior::CONSTRAINT) return FALSE; if (BehaviorType() == BaseBehavior::ORIENTATION) return FALSE; return TRUE;}
virtual int CanConvertToMaxScript | ( | ) | [inline, virtual] |
Queries whether or not the behavior can convert itself to a script.
This function is for future versions of Crowd. It is not used now.
{return FALSE;}
virtual void SetUpDelegates | ( | INodeTab & | participants | ) | [inline, virtual] |
Sends the behavior a list of all delegates which will participate in the simulation.
At the beginning of a simulation, this function is called for each behavior in the simulation. All active delegates assigned via an active assignment to any behavior or cognitive controller in the crowd system are included in the participants INodeTab. So this function tells the behavior the maximum number of delegates that could possibly perform this behavior during the simulation, and which delegates those are. With this information, the behavior can set up whatever data structures it requires to keep track of parameters on a per delegate basis. At the end of the simulation, this function is again called for each behavior, this time with an empty participants list, in order to allow the behavior to clear its data structures.
[in] | participants | - a tab of all of the delegates in the simulation. The delegates must be active, and they must be assigned, via an active assignment, to at least one behavior or cognitive controller. |
{}; //called at beginning of simulation.
virtual void BehaviorStarted | ( | TimeValue | t, |
INode * | node | ||
) | [inline, virtual] |
Notifies the behavior that it should start to act upon a particular delegate.
This function is called during a simulation, whenever a cognitive controller activates the behavior for a particular delegate. It allows a behavior to keep track of which delegates it is acting upon.
[in] | t | - the current simulation time. |
[in] | node | - the delegate which started the behavior |
{};
virtual void InitAtThisTime | ( | TimeValue | t | ) | [inline, virtual] |
Initializes a behavior at the start of each simulation frame.
This function is called at the beginning of each frame of the simulation. It allows the behavior to set up or clear out any information that it might need each frame.
[in] | t | - the current simulation time |
{}
virtual void InitBeforeSim | ( | int | FirstFrame, |
INode * | n, | ||
int | SimStart, | ||
int | AssignIndex | ||
) | [inline, virtual] |
Initializes the behavior at the start of a simulation.
This function is called once just before the beginning of the simulation. It is called so that the behavior knows which frame the simulation is actually starting at so it can perform any actions necessary to assure its repeatability. For example, if a behavior knows that the simulation is starting at frame 10 instead of frame 0, it may run it's random number generator 10 times so that the value it generates will be consistent with what it normally computes when the simulation starts from the beginning, as specified by the SimStart parameter.
[in] | FirstFrame | - the value of the first frame for this particular run of the simulation. This is the same as Start Solve in the crowd solve rollout. It is not in time ticks, but in frames. |
[in] | n | - the delegate |
[in] | SimStart | - the value of the frame when the simulation starts This is the same as Simulation Start in the crowd solve rollout. It is not in time ticks, but in frames. |
[in] | AssignIndex | - the index of the assignment used to apply this behavior to the delegate. If this equals -1, the behavior has been assigned using a cognitive controller. The AssignIndex can be used as a parameter to the IDelegate class's IsAssignmentActive function, which allows you to find out if this assignment is active at a given time. You may need this information to properly initialize a behavior before a simulation. |
{}
virtual int Perform | ( | INode * | node, |
TimeValue | t, | ||
int | numsubsamples, | ||
BOOL | DisplayHelpers, | ||
float | BhvrWeight, | ||
PerformOut & | out | ||
) | [inline, virtual] |
This is the main function for FORCE behaviors.
It is called every frame for each delegate the behavior is acting upon. It is within this function that the behavior may set any combination of the following: the force acting upon the delegate, the delegate's speed, or a goal towards which the delegate should move.
[in] | node | - the delegate |
[in] | t | - the current simulation time |
[in] | numsubsamples | - how many subsamples are being computed per frame. Currently not used. |
[in] | DisplayHelpers | - whether or not the behavior should display it's visual information. This parameter exists so that the Crowd system has global control over when the behavior information is displayed. |
[in] | BhvrWeight | - A float value, greater than or equal to 0.0, that corresponds to the BehaviorWeight value in the Crowd Assignment dialog. This value should be used to scale the returned force value in the out parameter. |
[out] | out | - A PerformOut
structure that is used to pass out information that the behavior
calculates. The structure has 4 items that may be set, depending
upon whether the behavior sets a force, a speed or a goal.
|
{return FALSE;}
virtual int Constraint | ( | INode * | node, |
TimeValue | t, | ||
int | numsubsamples, | ||
BOOL | DesGoalExists, | ||
BOOL | DisplayHelpers, | ||
BOOL | finalSet, | ||
ConstraintInOut & | inOut | ||
) | [inline, virtual] |
This is the main function for CONSTRAINT behaviors.
It is called multiple times per frame for each delegate the behavior is acting upon. It is within this function that the behavior may set a modified velocity or modified position for a delegate.
[in] | node | - the delegate |
[in] | t | - the current simulation time |
[in] | numsubsamples | - how many subsamples are being computed per frame. Currently not used. |
[in] | DesGoalExists | - whether or not a goal currently exists for this delegate. If it exists, it will be passed in via the inOut parameter. |
[in] | DisplayHelpers | - whether or not the behavior should display it's visual information. This parameter exists so that the Crowd system has global control over when the behavior information is displayed. |
[in] | finalSet | - whether or not this is the final time that the constraint will be called during the frame. Currently, each constraint behavior is called two times per frame (this may change in the future) - once after all of the forces have been assembled and just before a possible avoid behavior, and then once again at the end of the frame. It is called multiple times per frame so that the behavior may work correctly with any active avoid behavior. This flag lets the behavior know if it is the last time it will be called during that frame and thus should cache any information that it needs for the next frame calculation. Usually if the behavior isn't doing any sort of per frame caching it should just ignore this flag. |
[in,out] | &inOut | - a ConstraintInOut
structure that is used to pass in information that the behavior
will modify and then pass out. The structure contains 4 parameters:
|
{return FALSE;}
This is the main function for ORIENTATION behaviors.
It is called every frame for each delegate the behavior is acting upon. It is within this function that the behavior may set a quaternion representing the delegate's orientation.
[in] | vel | - the current velocity of the delegate |
[in] | node | - the delegate |
[in] | t | - the current simulation time |
[out] | quat | - The quaternion specifying the new orientation of the delegate |
{return FALSE;}
virtual int Display | ( | TimeValue | t, |
ViewExp * | vpt | ||
) | [inline, virtual] |
Using this function, a behavior can display text or graphics inside the viewports.
This is typically used to display a bounding area or a target. Often the behavior will allow the user to turn on or off this display by providing a checkbox in its interface.
[in] | t | - the time to display the object. |
[in] | vpt | - an interface pointer that may be used to call functions associated with the viewports |
{return 0;}
Gets the world bounding box of what the behavior draws.
[in] | t | - the time at which to compute the bounding box |
[in] | vpt | - an interface pointer that may be used to call functions associated with the viewports |
[out] | box | - the bounding box |
{}