PathEngine home previous: The update loop ‑ handling key messagesnext: Placing and moving agents
Contents, Programmers Guide, Example Projects, Tutorials, Tutorial 1, Getting the position under the mouse

Getting the position under the mouse

We need a way for the user to select a desired position to place or move agents on a mesh.

The testbed provides the following function for detecting which point on a mesh is beneath the mouse cursor:

virtual cPosition positionAtMouse()=0;

A cPosition uniquely identifies a position on the mesh.
This class is defined in i_pathengine.h, as follows:
(And see cPosition.)

class cPosition
{
public:
	cPosition() :cell(-1) {}
	int32_t x,y,cell;
};

The 'x' and 'y' members are horizontal coordinates.
(See PathEngine Coordinates.)
The 'cell' member disambiguates between overlapping geometry at a given horizontal position.

The iTestBed::positionAtMouse() function returns the position that will be underneath the mouse cursor after the mesh has been rendered for the current camera orientation.
(So the position found by intersection of a ray back through view space from the mouse screen position.)
If there are multiple layers underneath the mouse, a position on the top layer is returned.

If there is no position on the mesh currently underneath the mesh then positionAtMouse() returns an invalid position, in other words a position with the 'cell' member set to -1.

Note that there is some cost to calling positionAtMouse(), so it is better to avoid calling this function on frames where it is not requird.
But it is ok to call it multiple times in a frame because in this case the result is buffered internally by the testbed and reused.


Documentation for PathEngine release 6.00 - Copyright © 2002-2016 PathEnginenext: Placing and moving agents