Skip to main content
gamedev.net
🔒 Locked

Problems with D3DXVec3Project()

Started by strahan 2 replies 800+ views
Original Post
strahan
strahan
I am using D3DXVec3Project() to output text located in 3D world space onto the screen when it's in the my cameras view. This works fine when the text is in the cameras view. However, if I move the camera (view matrix) away from the text depending upon where I am in the world sometimes D3DXVec3Project() thinks this text should be visible and so the text appears. Any ideas why? Here is my source:
D3DXVECTOR3 screenOut;
D3DXVECTOR3 source;

// Text is at origin (0,0,0)

source.x = source.y = source.z = 0;

D3DVIEWPORT9 vp;
D3DXMATRIX matProj;
D3DXMATRIX matView;
D3DXMATRIX matWorld;

m_pD3DDevice->GetViewport(&vp);
m_pD3DDevice->GetTransform(D3DTS_PROJECTION, &matProj);
m_pD3DDevice->GetTransform(D3DTS_VIEW, &matView);
m_pD3DDevice->GetTransform(D3DTS_WORLD, &matWorld);

D3DXVec3Project(&screenOut, &source, &vp, &matProj, &matView, &matWorld);

// Make certain pOut is in valid screen coordinates

if(screenOut.x >= 0 && screenOut.y >= 0 && screenOut.x < nWidth && screenOut.y < nHeight)
     m_pFont->Print("(0,0,0)", screenOut.x, screenOut.y, 0, 0, 0xFFFFFF00);


Thanks for your help. [edited by - strahan on January 8, 2004 1:34:49 PM]
neneboricua19
neneboricua19
quote:
Original post by strahan
I am using D3DXVec3Project() to output text located in 3D world space onto the screen when it''s in the my viewport. This works fine when the text is in the viewport. However, if I move the viewport away from the text depending upon where I am in the world sometimes D3DXVec3Project() thinks this text should be visible and so the text appears. Any ideas why? Here is my source:
< snip source >


When you say that you "move the viewport", do you mean the camera location or do you actually change the values in the D3DVIEWPORT9 structure? I ask because it seems that what you *want* to do is change the position of your camera. This would then change the values in your view matrix, not your viewport.

If you''re really changing the values in your viewport, then the behaviour you''re seeing is correct. The viewport maps how homogeneous coordinates get mapped onto the screen.

Think about it this way: after the projection matrix has been applied, vertices are in homogenous clip space. This means their values range [-1..1] in x and y, and [0..1] in z. The scene that you will see consists of all the objects in this cuboid space. The viewport maps this space onto the screen itself. Changing the viewport to be smaller won''t make part of your scene not visisble. It will just map the entire cuboid (your scene basically) onto a smaller surface of your computer screen.

I hope I''ve understood your problem, and I hope this helps,
neneboricua
strahan
strahan
Actually I did mean to say move the camera changing the view matrix not the view port. The view port remains constant.

I changed the text above to the proper wording.

Any more thoughts?

Thanks.

[edited by - strahan on January 8, 2004 1:35:09 PM]
don
don
You need to test the Z before drawing the text. The vertex could be behind your camera, but within the x and y bounds.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.