PathEngine home previous: Agent rotationnext: Translating the agent
Contents, Programmers Guide, Example Projects, 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(const iCollisionContext* context, const cPosition& newPosition) const = 0;
    virtual bool testCollisionTo_XY(const iCollisionContext* context, int32_t x, int32_t y, int32_t& cell) const = 0;
    virtual bool firstCollisionTo(const iCollisionContext* context, int32_t x, int32_t y, int32_t& cell, cCollidingLine& collidingLine, iAgent*& agent) const = 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, but this method then returns some additional 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 6.00 - Copyright © 2002-2016 PathEnginenext: Translating the agent