Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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:

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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