// plans de clipping AABB
D3DXPLANE m_fClipPlanes[6];
u8 wdCameraCtrlEx::CheckAABBVisible(P3f &_rLowerBound,P3f &_rUpperBound)
{
D3DXVECTOR3 vecMinPt;
D3DXVECTOR3 vecMaxPt;
mcBool bIntersecting=false;
// récupérer les plans de clipping si la caméra a bougé
if (m_bChanged)
{
// récupération des plans de clipping
// ----------------------------------
D3DXMATRIX matView;
D3DXMATRIX matProjection;
D3DXMATRIX matViewProjection;
m_GraphicCamera.GetMatView(*((mmMatrix44*)&matView));
m_GraphicCamera.GetMatProj(*((mmMatrix44*)&matProjection));
D3DXMatrixMultiply(&matViewProjection,&matView,&matProjection);
D3DXMatrixTranspose(&matViewProjection,&matViewProjection);
D3DXVECTOR4 tmpVec;
D3DXVECTOR4 Columns[4];
Columns[0] = D3DXVECTOR4(matViewProjection(0, 0), matViewProjection(0, 1), matViewProjection(0, 2), matViewProjection(0, 3));
Columns[1] = D3DXVECTOR4(matViewProjection(1, 0), matViewProjection(1, 1), matViewProjection(1, 2), matViewProjection(1, 3));
Columns[2] = D3DXVECTOR4(matViewProjection(2, 0), matViewProjection(2, 1), matViewProjection(2, 2), matViewProjection(2, 3));
Columns[3] = D3DXVECTOR4(matViewProjection(3, 0), matViewProjection(3, 1), matViewProjection(3, 2), matViewProjection(3, 3));
tmpVec=Columns[3]-Columns[0];
*((D3DXVECTOR4*)&m_fClipPlanes[0])=-tmpVec;
tmpVec=Columns[3]+Columns[0];
*((D3DXVECTOR4*)&m_fClipPlanes[1])=-tmpVec;
tmpVec=Columns[3]-Columns[1];
*((D3DXVECTOR4*)&m_fClipPlanes[2])=-tmpVec;
tmpVec=Columns[3]+Columns[1];
*((D3DXVECTOR4*)&m_fClipPlanes[3])=-tmpVec;
tmpVec=Columns[3]-Columns[2];
*((D3DXVECTOR4*)&m_fClipPlanes[4])=-tmpVec;
tmpVec=Columns[3]+Columns[2];
*((D3DXVECTOR4*)&m_fClipPlanes[5])=-tmpVec;
m_bChanged=false;
}
for (int i=0;i<6;i++)
{
for (int j=0;j<3;j++)
{
if (m_fClipPlanes[i][j]>=0.0f)
{
vecMinPt[j]=_rLowerBound[j];
vecMaxPt[j]=_rUpperBound[j];
}
else
{
vecMinPt[j]=_rUpperBound[j];
vecMaxPt[j]=_rLowerBound[j];
}
}
float fMinDistance=D3DXPlaneDotCoord(&m_fClipPlanes[i],&vecMinPt);
if (fMinDistance>0.0f) { return 0; }
float fMaxDistance=D3DXPlaneDotCoord(&m_fClipPlanes[i],&vecMaxPt);
if (fMaxDistance>=0.0f) { bIntersecting=true; }
}
return (bIntersecting?(u8)1:(u8)2);
}