I'm having some strangeness with my W2S and hoping someone can help..
It behaves as if I'm using the wrong matrix; if you divide the world in half and I look in the direction of 1 side, my w2s works fine; look the other and nothing... w is negative and it thinks objects are behind me..
Here's a quick vid.
[YOUTUBE_ID]1ByKl2nXDPg[/YOUTUBE_ID]
here's my w2s code... is m_ViewProj not the correct matrix to use?
It behaves as if I'm using the wrong matrix; if you divide the world in half and I look in the direction of 1 side, my w2s works fine; look the other and nothing... w is negative and it thinks objects are behind me..
Here's a quick vid.
[YOUTUBE_ID]1ByKl2nXDPg[/YOUTUBE_ID]
here's my w2s code... is m_ViewProj not the correct matrix to use?
Code:
bool worldToScreen(D3DXVECTOR3 v3, D3DXVECTOR3* vOut)
{
unsigned int screenWidth = DxRenderer::GetInstance()->m_pScreen->m_Width;
unsigned int screenHeight = DxRenderer::GetInstance()->m_pScreen->m_Height;
D3DXMATRIX viewProjectionMatrix = GameRenderer::GetInstance()->m_pRenderView->m_ViewProj;
if (!viewProjectionMatrix)
return false;
float mX = screenWidth * 0.5f;
float mY = screenHeight * 0.5f;
float w =
viewProjectionMatrix(0, 3) * v3.x +
viewProjectionMatrix(1, 3) * v3.y +
viewProjectionMatrix(2, 3) * v3.z +
viewProjectionMatrix(3, 3);
if (w < 0.01f)
{
vOut->z = w;
return false;
}
float x =
viewProjectionMatrix(0, 0) * v3.x +
viewProjectionMatrix(1, 0) * v3.y +
viewProjectionMatrix(2, 0) * v3.z +
viewProjectionMatrix(3, 0);
float y =
viewProjectionMatrix(0, 1) * v3.x +
viewProjectionMatrix(1, 1) * v3.y +
viewProjectionMatrix(2, 1) * v3.z +
viewProjectionMatrix(3, 1);
vOut->x = mX + mX * x / w;
vOut->y = mY - mY * y / w;
vOut->z = w;
return true;
}
Aucun commentaire:
Enregistrer un commentaire