PathEngine home previous: Agent rotationnext: Translating the agent
Contents, Programmers Guide, Tutorials, Tutorial 2, Line collision and collision info

Line collision and collision info

For placing and moving our agent we used iTestBed::testPointCollision().
This tests whether a shape is obstructed at a given position.

For a moving agent, we need to test whether the agent is obstructed for movement along a line.
For this we can use the following functions, provided by Interface iAgent.

virtual bool testCollisionTo(iCollisionContext *context, const cPosition &newposition)=0;
virtual bool testCollisionTo_XY(iCollisionContext *context, tSigned32 x, tSigned32 y, tSigned32 &cell)=0;
virtual iCollisionInfo* firstCollisionTo(iCollisionContext *context, tSigned32 x, tSigned32 y, tSigned32 &cell)=0;

(Note that corresponding functions are also provided by Interface iMesh, to test collision for a moving shape without creating an agent.)

The difference between testCollisionTo() and testCollisionTo_XY() is that testCollisionTo_XY() does not require a fully specified position as an end point of the line.
testCollisionTo_XY() requires only x and y coordinates for the end of the line and fills in the cell appropriately.
This is exactly the behaviour we need to move our agent in a direction from their current position.

firstCollisionTo() also requires only x and y coordinates for the end point. This method returns an Interface iCollisionInfo object from which we can obtain some information about the first obstruction contacted in the case of a collision.
We will use this information to implement a basic mechanism for sliding against obstructions.


Documentation for PathEngine release 5.17 - Copyright © 2002-2008 PathEnginenext: Translating the agent