# Strategy Game view and cursor coordinates

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm programming a Strategy Game but have a Problem moving objects to the cursor.

If i set the camera vEye(-5,0,0)

vAt(....

it's no problem to read the cursor coordinates and send a Unit to them.

But if i set vEye(-5,-2.0) so that a unit which is on the bottom of the screen is nearer than one on top

(i think its like in warcraft3), I have problems sending a unit to the cursor.

if i click on the top of the screen the unit will do only half the way (the same with left and right). I tried to multiply the cursor coordinates but then the negative one woudln't match any more.

I know this happens because the unit does the same way but because of the angle it seems shorter.

But I don't know what to do to solve this? Should I change the camera settings? Or is there a simple math formula to adjust the distance to the coordinates?

I hope you understand what i mean ^^

Thanks, Ritti

##### Share on other sites
It sounds like you need to transform the cursor position into a 3D direction, and see where a ray in that direction intersects your game-world.
You can use D3DXVec3Unproject or XMVector3Unproject to get a 3D position from a 2D screen position. Set the Z coordinate to 1.0 together with your cursor XY coordinates and Unproject will give you a point on the far-plane which is right under your cursor. Then construct a 3D line from your camera-position and that point, and calculate where that line intersects your geometry, and you know where you have clicked.
Another alternative is to read back the Z-buffer after drawing your game, and check what depth-value is under the cursor, and use that instead of 1.0 when unprojecting, which will directly give you the 3D position of the geometry drawn under the cursor.

##### Share on other sites
Yeah that sounds good, I knew there would be an "easy" solution ^^

Thank you very much for your help

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75