Commit fe7b7e83 authored by Frédéric Larue's avatar Frédéric Larue

Frustum now account for orthographic projection matrices.

parent 2b0932aa
......@@ -12,7 +12,56 @@
void Frustum::UpdateFrustumPlanes( const QMatrix4x4& V, const QMatrix4x4& P )
void Frustum::UpdateFrustumPlanes_Ortho( const QMatrix4x4& V, const QMatrix4x4& P )
{
float l = -(P(0,3) + 1.0f) / P(0,0);
float r = -(P(0,3) - 1.0f) / P(0,0);
float b = -(P(1,3) + 1.0f) / P(1,1);
float t = -(P(1,3) - 1.0f) / P(1,1);
float n = (P(2,3) + 1.0f) / P(2,2);
float f = (P(2,3) - 1.0f) / P(2,2);
QVector3D center( -V(0,0)*V(0,3) - V(1,0)*V(1,3) - V(2,0)*V(2,3),
-V(0,1)*V(0,3) - V(1,1)*V(1,3) - V(2,1)*V(2,3),
-V(0,2)*V(0,3) - V(1,2)*V(1,3) - V(2,2)*V(2,3) );
QVector3D right( V(0,0), V(0,1), V(0,2) );
QVector3D top ( V(1,0), V(1,1), V(1,2) );
QVector3D front( -V(2,0), -V(2,1), -V(2,2) );
// Near plane.
m_Planes[NEAR_PLANE].n = front;
m_Planes[NEAR_PLANE].d0 = -QVector3D::dotProduct( front, center ) - n;
// Far plane.
m_Planes[FAR_PLANE].n = -front;
m_Planes[FAR_PLANE].d0 = QVector3D::dotProduct( front, center ) + f;
// Left plane.
m_Planes[LEFT_PLANE].n = right;
m_Planes[LEFT_PLANE].d0 = -QVector3D::dotProduct( m_Planes[LEFT_PLANE].n, center + l*right );
// Right plane.
m_Planes[RIGHT_PLANE].n = -right;
m_Planes[RIGHT_PLANE].d0 = -QVector3D::dotProduct( m_Planes[RIGHT_PLANE].n, center + r*right );
// Bottom plane.
m_Planes[BOTTOM_PLANE].n = top;
m_Planes[BOTTOM_PLANE].d0 = -QVector3D::dotProduct( m_Planes[BOTTOM_PLANE].n, center + b*top );
// Top plane.
m_Planes[TOP_PLANE].n = -top;
m_Planes[TOP_PLANE].d0 = -QVector3D::dotProduct( m_Planes[TOP_PLANE].n, center + t*top );
}
void Frustum::UpdateFrustumPlanes_Persp( const QMatrix4x4& V, const QMatrix4x4& P )
{
float n = P(2,3) / (P(2,2)-1.0f);
float f = P(2,3) / (P(2,2)+1.0f);
......@@ -61,6 +110,15 @@ void Frustum::UpdateFrustumPlanes( const QMatrix4x4& V, const QMatrix4x4& P )
}
void Frustum::UpdateFrustumPlanes( const QMatrix4x4& V, const QMatrix4x4& P )
{
if( P(3,3) == 0.0f )
UpdateFrustumPlanes_Persp( V, P );
else
UpdateFrustumPlanes_Ortho( V, P );
}
bool Frustum::IsOutside( const Box3f::CornerSet& corners ) const
{
for( int i=0; i<PLANE_COUNT; ++i )
......
......@@ -38,6 +38,9 @@ class Frustum
Plane m_Planes[PLANE_COUNT];
void UpdateFrustumPlanes_Ortho( const QMatrix4x4& V, const QMatrix4x4& P );
void UpdateFrustumPlanes_Persp( const QMatrix4x4& V, const QMatrix4x4& P );
bool IsOutside( const Box3f::CornerSet& corners ) const;
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment