|
|
发表于 2005-4-16 12:02:00
|
显示全部楼层
Re:求助 !! 一些D3D中的问题
1.这是一个视截体类,其中m_Planes存放的就是计算后的六个裁平面.近裁截面 的 4个 顶点坐标也就很简单的算出来了.
BOOL CFrustum::Construct(LPDIRECT3DDEVICE9 pd3dDevice, float ZDistance)
{
D3DXMATRIX Matrix, matView, matProj;
float ZMin, Q;
// Error checking
if(pd3dDevice == NULL)
return FALSE;
// Calculate FOV data
pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProj);
if(ZDistance != 0.0f) {
// Calculate new projection matrix based on distance provided
ZMin = -matProj._43 / matProj._33;
Q = ZDistance / (ZDistance - ZMin);
matProj._33 = Q;
matProj._43 = -Q * ZMin;
}
pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
D3DXMatrixMultiply(&Matrix, &matView, &matProj);
// Calculate the planes
m_Planes[0].a = Matrix._14 + Matrix._13; // Near
m_Planes[0].b = Matrix._24 + Matrix._23;
m_Planes[0].c = Matrix._34 + Matrix._33;
m_Planes[0].d = Matrix._44 + Matrix._43;
D3DXPlaneNormalize(&m_Planes[0], &m_Planes[0]);
m_Planes[1].a = Matrix._14 - Matrix._13; // Far
m_Planes[1].b = Matrix._24 - Matrix._23;
m_Planes[1].c = Matrix._34 - Matrix._33;
m_Planes[1].d = Matrix._44 - Matrix._43;
D3DXPlaneNormalize(&m_Planes[1], &m_Planes[1]);
m_Planes[2].a = Matrix._14 + Matrix._11; // Left
m_Planes[2].b = Matrix._24 + Matrix._21;
m_Planes[2].c = Matrix._34 + Matrix._31;
m_Planes[2].d = Matrix._44 + Matrix._41;
D3DXPlaneNormalize(&m_Planes[2], &m_Planes[2]);
m_Planes[3].a = Matrix._14 - Matrix._11; // Right
m_Planes[3].b = Matrix._24 - Matrix._21;
m_Planes[3].c = Matrix._34 - Matrix._31;
m_Planes[3].d = Matrix._44 - Matrix._41;
D3DXPlaneNormalize(&m_Planes[3], &m_Planes[3]);
m_Planes[4].a = Matrix._14 - Matrix._12; // Top
m_Planes[4].b = Matrix._24 - Matrix._22;
m_Planes[4].c = Matrix._34 - Matrix._32;
m_Planes[4].d = Matrix._44 - Matrix._42;
D3DXPlaneNormalize(&m_Planes[4], &m_Planes[4]);
m_Planes[5].a = Matrix._14 + Matrix._12; // Bottom
m_Planes[5].b = Matrix._24 + Matrix._22;
m_Planes[5].c = Matrix._34 + Matrix._32;
m_Planes[5].d = Matrix._44 + Matrix._42;
D3DXPlaneNormalize(&m_Planes[5], &m_Planes[5]);
return TRUE;
}
|
|