I'm building a Wander steering behavior from Mat Buckland's book Programming AI by Example, and translating the behaviors I need to Box2d. Here is the visual example from Craig Reynolds paper:http://www.red3d.com/cwr/steer/Wander.html
Wander defines a slightly randomized point on the radius of a circle, then moves this target point in front of the Box2D body.
I'm stuck on the translation of a point to world space relative to the heading of a b2Body.
Is there an equivalent function in b2Math or elsewhere to this code from Mat's book?
Wander defines a slightly randomized point on the radius of a circle, then moves this target point in front of the Box2D body.
I'm stuck on the translation of a point to world space relative to the heading of a b2Body.
Is there an equivalent function in b2Math or elsewhere to this code from Mat's book?
Code:
inline Vector2D PointToWorldSpace(const Vector2D &point,
const Vector2D &AgentHeading,
const Vector2D &AgentSide,
const Vector2D &AgentPosition)
{
//make a copy of the point
Vector2D TransPoint = point;
//create a transformation matrix
C2DMatrix matTransform;
//rotate
matTransform.Rotate(AgentHeading, AgentSide);
//and translate
matTransform.Translate(AgentPosition.x, AgentPosition.y);
//now transform the vertices
matTransform.TransformVector2Ds(TransPoint);
return TransPoint;
}
const Vector2D &AgentHeading,
const Vector2D &AgentSide,
const Vector2D &AgentPosition)
{
//make a copy of the point
Vector2D TransPoint = point;
//create a transformation matrix
C2DMatrix matTransform;
//rotate
matTransform.Rotate(AgentHeading, AgentSide);
//and translate
matTransform.Translate(AgentPosition.x, AgentPosition.y);
//now transform the vertices
matTransform.TransformVector2Ds(TransPoint);
return TransPoint;
}