Archived

This topic is now archived and is closed to further replies.

Fistandantilus

acquiring camera planes with directx

Recommended Posts

How do I do that? I read a code that does that in OpenGL , and it goes like that : // Get the current projection matrix from OpenGL glGetFloatv(GL_PROJECTION_MATRIX, fProj); // Get the current modelview matrix from OpenGL glGetFloatv(GL_MODELVIEW_MATRIX, fView); then those 2 matrix are multiplied , and then with the resulting matrix, the planes are extracted. In directX you handle mainly with 3 matrix , the D3DTS_WORLD , D3DTS_VIEW and D3DTS_PROJECTION, then how would you do that ? Do you multiply all three matrix to acquire the equivalent to the OpenGL one ? Do you have to multiply just the VIEW and the PROJECTION ? Does anyone can help me with that?

Share this post


Link to post
Share on other sites
Try this:

D3DXMATRIX CD3DManager::GetViewMatrix()
{
D3DXMATRIX view;
m_pDevice->GetTransform(D3DTS_VIEW, &view);
return view;
}

D3DXMATRIX CD3DManager::GetProjectionMatrix()
{
D3DXMATRIX projection;
m_pDevice->GetTransform(D3DTS_PROJECTION, &projection);
return projection;
}

D3DXMATRIX CD3DManager::GetViewFrustum()
{
D3DXMATRIX ViewFrustum;
D3DXMatrixMultiply( &ViewFrustum, &GetViewMatrix(), &GetProjectionMatrix() );
return ViewFrustum;
}

void CD3DManager::ExtractFrustum()
{
double t;
D3DXMATRIX clip;
clip = GetViewFrustum();

// RIGHT PLANE
frustum[0][0] = clip._14 - clip._11;
frustum[0][1] = clip._24 - clip._21;
frustum[0][2] = clip._34 - clip._31;
frustum[0][3] = clip._44 - clip._41;
t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] );
frustum[0][0] /= t;
frustum[0][1] /= t;
frustum[0][2] /= t;
frustum[0][3] /= t;

// LEFT PLANE
frustum[1][0] = clip._14 + clip._11;
frustum[1][1] = clip._24 + clip._21;
frustum[1][2] = clip._34 + clip._31;
frustum[1][3] = clip._44 + clip._41;
t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] );
frustum[1][0] /= t;
frustum[1][1] /= t;
frustum[1][2] /= t;
frustum[1][3] /= t;

// BOTTOM PLANE
frustum[2][0] = clip._14 + clip._12;
frustum[2][1] = clip._24 + clip._22;
frustum[2][2] = clip._34 + clip._32;
frustum[2][3] = clip._44 + clip._42;
t = sqrt( frustum[2][0] * frustum[2][0] + frustum[2][1] * frustum[2][1] + frustum[2][2] * frustum[2][2] );
frustum[2][0] /= t;
frustum[2][1] /= t;
frustum[2][2] /= t;
frustum[2][3] /= t;

// TOP PLANE
frustum[3][0] = clip._14 - clip._12;
frustum[3][1] = clip._24 - clip._22;
frustum[3][2] = clip._34 - clip._32;
frustum[3][3] = clip._44 - clip._42;
t = sqrt( frustum[3][0] * frustum[3][0] + frustum[3][1] * frustum[3][1] + frustum[3][2] * frustum[3][2] );
frustum[3][0] /= t;
frustum[3][1] /= t;
frustum[3][2] /= t;
frustum[3][3] /= t;

// FAR PLANE
frustum[4][0] = clip._14 - clip._13;
frustum[4][1] = clip._24 - clip._23;
frustum[4][2] = clip._34 - clip._33;
frustum[4][3] = clip._44 - clip._43;
t = sqrt( frustum[4][0] * frustum[4][0] + frustum[4][1] * frustum[4][1] + frustum[4][2] * frustum[4][2] );
frustum[4][0] /= t;
frustum[4][1] /= t;
frustum[4][2] /= t;
frustum[4][3] /= t;

// NEAR PLANE
frustum[5][0] = clip._14 + clip._13;
frustum[5][1] = clip._24 + clip._23;
frustum[5][2] = clip._34 + clip._33;
frustum[5][3] = clip._44 + clip._43;
t = sqrt( frustum[5][0] * frustum[5][0] + frustum[5][1] * frustum[5][1] + frustum[5][2] * frustum[5][2] );
frustum[5][0] /= t;
frustum[5][1] /= t;
frustum[5][2] /= t;
frustum[5][3] /= t;
}

Reg''ds,
sTeVe

Share this post


Link to post
Share on other sites