finding the coordinates
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
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.
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.
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 ;)
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..?
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?
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
//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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement