4
\$\begingroup\$

I want to let a unit follow the mouse like in any RTS (Warcraft 3, Starcraft, ...). For that I have a "ground plane" which is defined through 2 vectors, the X and Z axis. Now I need to get the world coordinate of the mouse click on this plane in order to move the unit. I'm using OGRE & C++.

How can I get the coordinates of the mouse click on the ground plane?

\$\endgroup\$
4
\$\begingroup\$

This is known as 3D picking, and usually involves some kind of raycast from a point in screen space (the cursor position) in the camera's forward vector direction.

For some Ogre tutorials, check those links:

\$\endgroup\$
2
\$\begingroup\$

Since you're using Ogre then you should probably read those ogre3d.org links, but if you want to know the math behind the intersect algorithm, here it is:

http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane%20Intersection

When I do that I also use a bit from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104.htm

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.