DirectX D3DXVec3Project function

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri I am trying to debug results I am getting from the DirectX function D3DXVec3Project.

<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri I have an application that is displaying points. These points have world coordinates. If I zoom in in the application, such that the projection matrix has large values
for _11 and _22 elements, then I am finding that the float precision restriction seems to be causing problems with correctly rendering the data. I wish I was able to use double precision in directx!
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri So in order to work out where the problem is, I am trying to understand how the D3DXVec3Project function works. I understand that its purpose is to convert world coordinates
to screen coordinates by applying World, View, Projection and Viewport transformations, but when I compute the answer manually based upon this premise, I donât get the answer the function returns.
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri Here is the code snippetâ
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt m_pd3dDevice->GetViewport(&m_Viewport);
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt m_pd3dDevice->GetTransform(D3DTS_PROJECTION,
&m_matProj);
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt m_pd3dDevice->GetTransform(D3DTS_VIEW,
&m_matView);
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt m_pd3dDevice->GetTransform(D3DTS_WORLD,
&m_matWorld);
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt D3DXVec3Project(&vecOut, &vecIn, &m_Viewport, &m_matProj,
&m_matView, &m_matWorld);
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt

<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="color:green // Apply world
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fx = vecIn.x * m_matWorld._11
+ vecIn.y * m_matWorld._21 + vecIn.z * m_matWorld._31 + m_matWorld._41;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fy = vecIn.x * m_matWorld._12
+ vecIn.y * m_matWorld._22 + vecIn.z * m_matWorld._32 + m_matWorld._42;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fz = vecIn.x * m_matWorld._13
+ vecIn.y * m_matWorld._23 + vecIn.z * m_matWorld._33 + m_matWorld._43;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue float fxo, fyo, fzo;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fxo = fx;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fyo = fy;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fzo = fz;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="color:green // Apply View
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fx = fxo * m_matView._11
+ fyo * m_matView._21 + fzo * m_matView._31 + m_matView._41;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fy = fxo * m_matView._12
+ fyo * m_matView._22 + fzo * m_matView._32 + m_matView._42;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fz = fxo * m_matView._13
+ fyo * m_matView._23 + fzo * m_matView._33 + m_matView._43;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fxo = fx;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fyo = fy;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fzo = fz;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="color:green // Apply Proj
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fx = fxo * m_matProj._11
+ fyo * m_matProj._21 + fzo * m_matProj._31 + m_matProj._41;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fy = fxo * m_matProj._12
+ fyo * m_matProj._22 + fzo * m_matProj._32 + m_matProj._42;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fz = fxo * m_matProj._13
+ fyo * m_matProj._23 + fzo * m_matProj._33 + m_matProj._43;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fxo = fx;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fyo = fy;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fzo = fz;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="color:green // Apply Viewport
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fx = (fxo + 1) * m_Viewport.Width
* 0.5 + m_Viewport.X;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt fy = (1 - fyo) * m_Viewport.Height
* 0.5 + m_Viewport.Y;
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri Valuesâ
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri vecIn.x = 10000.000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri vecIn,y = 10000.000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri vecIn.z = 300.00000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri Non zero values the matricesâ
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._11 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._22 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._33 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._ 41 = -10000.000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._ 42 = -10000.000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matWorld._44 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._11 = 0.99999994
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._22 = 0.99999994
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._33 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._41 = 9.5995319e-006
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._42 = -0.00018578718
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._43 = 10.0000
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matView._44 = 1.0

<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matProj._11 = 1999.9816
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matProj._22 = 3548.5198
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matProj._33 = 0.090909094
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matProj._43 = -27.181820
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_matProj._44 = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.X = 0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.Y = 0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.Width = 1886
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.Height = 1063
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.MinZ = 0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri m_Viewport.MaxZ = 1.0
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri So after applying these values manually as per the code snippet I get pixel coords of 961, 881, yet the function returns 943, 531.
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri The function is returning a pixel in the very centre of the viewport, yet I compute that it should be lower down the screen. The centre of the screen should be 9999.99999,
10000.000185.
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<span style="font-family:Times New Roman; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-size:small <span style="font-family:Calibri Obviously I am running into issues with float precision and I am not sure what to do about that at this stage. I was firstly trying to work out how the DirectX function
computed the pixel to display, but I canât work out exactly what the function is doing.
<span style="font-family:Times New Roman; font-size:small

View the full article
 

Similar threads

D
Replies
0
Views
104
Donald Uko
D
A
Replies
0
Views
162
ANIL AYDINALP
A
R
Replies
0
Views
132
Ravnø Data
R
Back
Top