#include <src/Agent.h>
Inheritance diagram for Agent:
The main differences between this model and the OpenSteer library are:
Integration update => at least once per frame in graphics mode, may be more often
AI update => From time to time
Attitude correction:
Physics:
Public Member Functions | |
virtual osg::Vec3d | steerForSeek (const osg::Vec3d &targetPosition) |
Return a force to apply to steer toward the given point. | |
virtual osg::Vec3d | steerForFlee (const osg::Vec3d &targetPosition) |
Return a force to apply to steer to the opposite direction of the given point Roughly equivalent to the experimental version of the OpenSteer Library. | |
virtual osg::Vec3d | steerToAvoid (Localized *object) |
Return a force to apply to steer to avoid collision with a given object. | |
virtual osg::Vec3d | steerForEvasion (Agent *menace) |
Not only do we seek to avoid the agent, but also try to escape it. | |
virtual osg::Vec3d | steerForPursuit (Agent *quarry) |
The opposite of evasion, try to follow the other agent. | |
virtual osg::Vec3d | steerForWander (double changeRate) |
Returns a "random" direction, based on the previous direction. | |
virtual osg::Vec3d | steerForTargetSpeed (double targetSpeed) |
Try to adjust speed to the desired speed. | |
virtual void | integrationStep () |
Integration update: update position and attitude by taking into account forces set by AI. | |
virtual void | aiStep () |
Public AI step. | |
virtual void | destroy () |
Destroys the agent. | |
virtual void | clampToMaxForce () |
virtual void | findNeighbors (double radius) |
Find all neighbors of this object within a sphere of the given radius. | |
Public Attributes | |
double | speed |
Speed of the agent, along its forward direction, expressed in OSG space unit / simulator time unit. | |
osg::Vec3d | forward |
Current forward vector in world coordinates: initialized to Y in local space to begin with, so orient your models accordingly at load time (or override this in your constructor). | |
osg::Vec3d | steeringForce |
Current steering force set by AI, in world coordinates. | |
AttitudeCorrection * | attitudeCorrection |
Attitude correction policy for this agent. | |
Static Public Attributes | |
static std::list< Agent * > | allAgents |
A list containing all objects of this class Subset of Localized, useful for faster algorithms. | |
Protected Member Functions | |
virtual void | updateAI (double elapsedTime, double currentTime) |
Subclasses should override the updateAI method to implement an AI. | |
virtual void | updateIntegration (double elapsedTime, double currentTime) |
Subclasses should override the updateStep method to modify the position and attitude _before_ the locality database is updated! They can also modify newPosition and newAttitude directly in this method: the update consistency lock in done only once in the integrationStep method, after this call. | |
virtual double | predictNearestApproachTime (Agent *agent) |
Directly stolen from OpenSteer Library and adapted to this framework. | |
Protected Attributes | |
osg::Vec3d | newPosition |
new Position usable in the updateStep method, set by integrationStep. | |
osg::Quat | newAttitude |
new Attitude usable in the updateStep method, set by integrationStep. | |
osg::Vec3d | newForward |
new Forward vector usable in the updateStep method, set by integrationStep. | |
double | newSpeed |
new Speed usable in the updateStep method, set by integrationStep. | |
double | steeringForceLen |
Pre-compute force len at AI frequency, not integration step frequency... | |
double | forwardRadius |
Ad-hoc hack to avoid instantaneous rotation on place due to point-mass model. While this is no substitute for a proper rotational momentum, it still allows agents with more mass to turn more slowly on themselves, adding realism. | |
double | lastIntegrationStepTime |
step control variable: explicit name | |
double | lastAIStepTime |
step control variable: explicit name | |
Static Protected Attributes | |
static ShortestAngleAttitudeCorrection | shortestAngleAttitudeCorrection |
Shared class variable. The shortest angle policy is stateless, which makes this possible. |
|
Public AI step. This is the method that should be scheduled, subclasses should override the updateAI protected method which is given time information. Note: The very first call to this method actually sets the starting point in time for the first cycle. It returns immediately. Subsequent calls can then use the (simulation) time delta for integration. Reimplemented in CrogaiAgent. |
|
Destroys the agent. Really, don't use delete.... Reimplemented from Localized. |
|
Find all neighbors of this object within a sphere of the given radius. Agents are returned classified by distance order, in a multimap whose pair values are: square of the distance and agent pointer. See neighbors field Note: This function should not be protected with neighborsAccessLock(); Indded, it already uses it internally. Besides which, we need to keep allObjectAccess mutex around the neighbors, and not the opposite, so this is the only choice. Note that it doesn't matter if the updated neighbor list is modified before you re-acquire the mutex. Reimplemented from Localized. Reimplemented in CrogaiAgent. |
|
Integration update: update position and attitude by taking into account forces set by AI. This is the method that should be scheduled, subclasses should override the updateStep method to modify the position and attitude _before_ the locality database is updated! Note: The very first call to this method actually sets the starting point in time for the first cycle. It returns immediately. Subsequent calls can then use the (simulation) time delta for integration. |
|
Not only do we seek to avoid the agent, but also try to escape it. This is exactly the same algorithm as in the OpenSteer Library without maximum prediction time, and adapted to this framework. We don't include a maximum for prediction time because that's one more parameter we don't have a clear default value for, and because anyway this function will usually be called for neighbors, with the intent to evade NOW!!! |
|
The opposite of evasion, try to follow the other agent. This is exactly the same algorithm as in the OpenSteer Library without maximum prediction time, and adapted to this framework. We don't include a maximum for prediction time because that's one more parameter we don't have a clear default value for, and because anyway this function will usually be called for neighbors, with the intent to pursue them so long as they are visible. |
|
Return a force to apply to steer toward the given point. Roughly equivalent to the experimental version of the OpenSteer Library |
|
Try to adjust speed to the desired speed. Do not change direction, useful for breaking. The implementation in the OpenSteer library uses the speed delta as a force. This implementation use numerical integration to predict the effect of the returned force, such that if applied the alone target speed would be reached at next AI step. It's not clamped to max force at this point.
|
|
Returns a "random" direction, based on the previous direction. The idea is the same as in the OpenSteer library in the sense that there is no abrupt change in direction, allowing consistent turns. But this implementation does not constrain the new force on a sphere. Instead of the sphere radius, a new parameter is introduced to quantify the "smoothness" of the changes. Note: The standard Utility::Random() function is used, you may control the seed.
|
|
Return a force to apply to steer to avoid collision with a given object. Then:
Notes:
|
|
Subclasses should override the updateAI method to implement an AI. At least, a new steering force should be given. All steerForXXX methods are available. Reimplemented in ExplicitAIAgent, NeuronalAgent, TerrainAgent, and ExplicitAIAgent. |
|
Attitude correction policy for this agent. By default, all agents use a ShortestAngle attitude correction, which has the nice advantage of being stateless so it can be shared among agents. This field is not deleted in the destructor (the shared ShortestAngle is handled separately). So if you change the default policy, it's your responsability to manage this field. |
|
Current forward vector in world coordinates: initialized to Y in local space to begin with, so orient your models accordingly at load time (or override this in your constructor). You should not normally need to change this value directly, but rather set a steering force. Of course, if your particular environment has special zones (water swirl?) then maybe... |
|
new Attitude usable in the updateStep method, set by integrationStep. This will be the new attitude of this agent, so it can be modified in the updateStep method |
|
new Forward vector usable in the updateStep method, set by integrationStep. This will be the new forward vector of this agent, so it can be modified in the updateStep method |
|
new Position usable in the updateStep method, set by integrationStep. This will be the new position of this agent, so it can be modified in the updateStep method |
|
new Speed usable in the updateStep method, set by integrationStep. This will be the new speed of this agent, so it can be modified in the updateStep method |
|
Speed of the agent, along its forward direction, expressed in OSG space unit / simulator time unit. You should not normally need to change this value directly, but rather set a steering force. Of course, if your particular environment has slow-down zones (water?) then maybe... |
|
Current steering force set by AI, in world coordinates. Apply this force to the current agent at each integration update, so long as it can (so song as energy remains), till next AI update. One very important goal of the updateAI overload is to update this variable. Note: It is clamped to maxForce at the end of the AI step, after updateAI is called. |