PathEngine home | previous: | next: |
The application starts out with no agent or obstacle placed, so we initialise our agent pointers to null:
unique_ptr<iAgent> agent; unique_ptr<iAgent> obstruction_agent1; unique_ptr<iAgent> obstruction_agent2; |
The following code is added to our our key message switch statment to place or move the user controlled agent when '4' is pressed:
cPosition p=testbed->positionAtMouse(); if(p.cell!=-1 && !mesh->testPointCollision(*agent_shape, context.get(), p)) { if(!agent) agent = mesh->placeAgent(*agent_shape,p); else agent->moveTo(p); } |
If there is no position under the mouse then placement or movement will not be attempted.
Also we don't allow the agent to be placed or moved to a position which is obstructed.
The
The context parameter specifies a state of collision that should apply to the query.
When we add obstacles we will include them in this context.
The result is that it will be impossible to place an agent at a position overlapping an obstacle.
(More about this in the next section.)
Note that the iAgent is constructed when the agent is placed on the mesh.
An iAgent object represents the placement of some entity on a mesh,
as opposed to representing the entity itself.
So to move a character in a game from one mesh to another requires the destruction
of one iAgent object and the construction of another to correspond to placement on the new mesh.
Documentation for PathEngine release 6.04 - Copyright © 2002-2024 PathEngine | next: |