Jump to content
  • Advertisement
Sign in to follow this  
vcGamer

finding the coordinates

This topic is 4766 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 how can I find the space coordinate of a point picked up by mouse? is there any straightforward method for doing so, any sample code or program showing it ready-to-use... thanks www.galaxyroad.com

Share this post


Link to post
Share on other sites
Advertisement
Well, in order to pick a 3d space (world) point, u need to project ur mouse coordinates to a ray position. that ray position is ur 3D point.

here is a sample code:

vProjected = D3DXVECTOR3(MousePosX, MousePosY, 0.0f);
D3DXVec3Unproject(vRayPos, vProjected, Viewport, matProjection, matView, matWorld);

vRayPos is ur 3D vertex for the position in 3D space.

Share this post


Link to post
Share on other sites
Quote:
Original post by ramy
Well, in order to pick a 3d space (world) point, u need to project ur mouse coordinates to a ray position. that ray position is ur 3D point.

here is a sample code:

vProjected = D3DXVECTOR3(MousePosX, MousePosY, 0.0f);
D3DXVec3Unproject(vRayPos, vProjected, Viewport, matProjection, matView, matWorld);

vRayPos is ur 3D vertex for the position in 3D space.


Just to make it clear. vRayPos is a 3D point on the near clipping plane ;)

Share this post


Link to post
Share on other sites
Quote:
vProjected = D3DXVECTOR3(MousePosX, MousePosY, 0.0f);


about the MousePosX and MousePoxY, how can i get this....?
i just know the way in using msgproc,
LOWORD(lparam) is x pos and HIWORD(lparam) is y pos.

BUT how about using "Direct Input", how we get that..?

Share this post


Link to post
Share on other sites
thanks for your help but I always get the same numbers, regardless of where my mouse cursor exists in the screen, what's going wrong?

Share this post


Link to post
Share on other sites
here is the code snippet I've used:

//setting the mouse cursor position
if((Cursor_X + input.MX < 1000) && (Cursor_X + input.MX > 0))
Cursor_X += input.MX;
if((Cursor_Y + input.MY < (768-24)) && (Cursor_Y + input.MY > 0))
Cursor_Y += input.MY;

D3DXVECTOR3 vProjected = D3DXVECTOR3(Cursor_X, Cursor_Y, 0.0f);
D3DXVECTOR3 vRayPos;
D3DVIEWPORT9 Viewport;
Viewport.X = 0;
Viewport.Y = 0;
Viewport.Width = 1024;
Viewport.Height = 768;
Viewport.MinZ = 0;
Viewport.MaxZ = 1;
D3DXVec3Unproject(&vRayPos, &vProjected, &Viewport, &Renderer.GetProjectionMatrix (), &Renderer.GetViewMatrix (),
&Renderer.GetWorldMatrix ());

but vRayPos always is the same number,
where input.MX & input.MY are mouse position in screen space (my cursor is 24x24)

thanks in advance

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!