Jump to content
  • Advertisement
Sign in to follow this  
Ritti

Strategy Game view and cursor coordinates

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


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

Thank you very much for your help

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!