Jump to content
Sign in to follow this  
Prospero

2d screen cursor coordinates to 3d world vector

Recommended Posts

Hi all,

What with a number of RTS mods being developed, I wondered if anyone's come up with an elegant way of taking a 2D screen cursor coordinate and translating this to a 3D world coordinate (whilst pointing at the ground *and* the air). I have come up with a limited, very imperfect way, but anyway... I thought I'd ask.

A feature like this would help with overhead (C&C style) ordering of units via scripting.

Edit: Ooops I should also have said one would also need to be able to do the reverse - i.e. get the 2D screen coordinate of any specified object.

Prospero

Share this post


Link to post
Share on other sites

I guess you could use the onmapsingleclick to spawn a gamelogic and get the position of that.

3D to 2D shouldn't be that hard as you will not need to display the height.

RED

Share this post


Link to post
Share on other sites

Yup.

But I am looking for a solution which avoids having to do this from the map screen. Ordering units around via the map screen is.. well, not as good as doing it "live" in 3D.

Prospero

Share this post


Link to post
Share on other sites

I'm not following you. Don't you just pick a unit and click on the screen where you want them to go already?? So then can't you then get some feedback as to where that waypoint was you just created?

Doolittle

Share this post


Link to post
Share on other sites
Guest

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Prospero @ Nov. 22 2002,13:39)</td></tr><tr><td id="QUOTE">What with a number of RTS mods being developed, I wondered if anyone's come up with an elegant way of taking a 2D screen cursor coordinate and translating this to a 3D world coordinate (whilst pointing at the ground *and* the air).<span id='postcolor'>

Not really, since the 3d view is projected on a plane, thus loosing a dimension. You can get an infinite line of world coordinates though.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

Edit: Ooops I should also have said one would also need to be able to do the reverse - i.e. get the 2D screen coordinate of any specified object.

<span id='postcolor'>

This shouldn't be too difficult. You just have to create your own camera. By knowing its position you can just project the world coordinates (on a plane with a normal in the camera's direction). You will have to compensate for the FOV too, but that is also just a linear operation.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×