Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


D3DXVec3Unproject Problems

markmacumbermarkmacumber Member Posts: 1
Hello All, I am currently new to DirectX and am trying to make a very simple, rotating cube to a position in 3d-space from a users mouse click.

I can do 90% of this, but when I try to convert the users mouse click into 3D-space, I get strange values (or at least I think they are strange).

I have placed a cube at and around the -3 to +3 vertex positions in 3D space. Then I setup the camera, etc... and I can see the cube in the middle of the black screen.

Then when I click the mouse, I call a self-defined method called
SetupLocalMousePoints(IDirect3DDevice9* p_d3dDevice)

The method is defined as:

D3DXVECTOR3* GameEntity::SetupLocalMousePoints(IDirect3DDevice9* p_d3dDevice)
if (m_mousePoint)
D3DXVECTOR3 result;
D3DXVECTOR3 screenPoint;
D3DVIEWPORT9 viewport;
D3DXMATRIX matProjection;
D3DXMATRIX matWorld;

screenPoint.x = m_mousePoint->x;
screenPoint.y = m_mousePoint->y;
screenPoint.z = 0.0f;
m_mousePoint = 0;

p_d3dDevice->GetTransform( D3DTS_PROJECTION, &matProjection );
p_d3dDevice->GetTransform( D3DTS_VIEW, &matView );
p_d3dDevice->GetTransform( D3DTS_WORLD, &matWorld );

//transform the mouse clicked location
D3DXVec3Unproject( &result, &screenPoint, &viewport, &matProjection, &matView, &matWorld );
return &result;
return NULL;

m_mousePoint is a private class member variable:
POINTS* m_mousePoint

The rest should be pretty obvious.

Now, the issue is when I click in the TOP RIGHT corner of the screen, I am getting. X: -23, Y:8 and Z:0.44 (ish).

Why on earth would X be a negative number???

I am having real trouble here and would appreciate any help at all!

Sign In or Register to comment.