# finding the coordinates

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

## 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 on other sites
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 on other sites
Quote:
 Original post by ramyWell, 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 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 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 on other sites
Maybe you could show us your code, so we can more efficiently tell you what's wrong

##### 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)

##### Share on other sites
get the viewport like g_pD3DDevice->GetViewport(&viewport);

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633755
• Total Posts
3013706
×

## Important Information

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!