AI_SDB_FrustumClipper.h

Go to the documentation of this file.
00001 #ifndef AI_SDB_FRUSTUMCLIPPER_H
00002 #define AI_SDB_FRUSTUMCLIPPER_H
00003 
00026 #include "AI_SDB_PlaneClipper.h"
00027 #include "AI_SDB_Camera.h"
00028 
00029 class AI_SDB_FrustumClipper : public AI_SDB_PlaneClipper {
00030 public:
00031     AI_SDB_FrustumClipper();
00032     AI_SDB_FrustumClipper(const AI_SDB_FrustumClipper &copyme);
00033     AI_SDB_FrustumClipper(AI_SDB_Camera &camera, const AI_Matrix44 &viewtransform);
00034     AI_SDB_FrustumClipper(const AI_Plane clipplanes[6]);
00035 };
00036 
00037 inline
00038 AI_SDB_FrustumClipper::AI_SDB_FrustumClipper() : AI_SDB_PlaneClipper()
00039 {
00040 }
00041 
00042 inline
00043 AI_SDB_FrustumClipper::AI_SDB_FrustumClipper(const AI_SDB_FrustumClipper &copyme)
00044     : AI_SDB_PlaneClipper(copyme)
00045 {
00046 }
00047 
00048 
00049 inline
00050 AI_SDB_FrustumClipper::AI_SDB_FrustumClipper(AI_SDB_Camera &camera, const AI_Matrix44 &viewtransform)
00051 : AI_SDB_PlaneClipper()
00052 {
00053 
00054     m_numplanes = 6;
00055 
00056     // initialize clip planes from the projection and transform info
00057     // stolen from nOctFrustum code, 
00058     AI_Matrix44 proj(camera.GetProjection());
00059     AI_Matrix44 m(viewtransform);
00060     m.invert();
00061     m *= proj;
00062 
00063     // front
00064     m_planes[0].a = m.m[0][2];
00065     m_planes[0].b = m.m[1][2];
00066     m_planes[0].c = m.m[2][2];
00067     m_planes[0].d = m.m[3][2];
00068 
00069     // back
00070     m_planes[1].a = (m.m[0][3] - m.m[0][2]);
00071     m_planes[1].b = (m.m[1][3] - m.m[1][2]);
00072     m_planes[1].c = (m.m[2][3] - m.m[2][2]);
00073     m_planes[1].d = (m.m[3][3] - m.m[3][2]);
00074 
00075     // left
00076     m_planes[2].a = (m.m[0][3] + m.m[0][0]);
00077     m_planes[2].b = (m.m[1][3] + m.m[1][0]);
00078     m_planes[2].c = (m.m[2][3] + m.m[2][0]);
00079     m_planes[2].d = (m.m[3][3] + m.m[3][0]);
00080 
00081     // right
00082     m_planes[3].a = (m.m[0][3] - m.m[0][0]);
00083     m_planes[3].b = (m.m[1][3] - m.m[1][0]);
00084     m_planes[3].c = (m.m[2][3] - m.m[2][0]);
00085     m_planes[3].d = (m.m[3][3] - m.m[3][0]);
00086 
00087     // top
00088     m_planes[4].a = (m.m[0][3] - m.m[0][1]);
00089     m_planes[4].b = (m.m[1][3] - m.m[1][1]);
00090     m_planes[4].c = (m.m[2][3] - m.m[2][1]);
00091     m_planes[4].d = (m.m[3][3] - m.m[3][1]);
00092 
00093     // bottom
00094     m_planes[5].a = (m.m[0][3] + m.m[0][1]);
00095     m_planes[5].b = (m.m[1][3] + m.m[1][1]);
00096     m_planes[5].c = (m.m[2][3] + m.m[2][1]);
00097     m_planes[5].d = (m.m[3][3] + m.m[3][1]);
00098 
00099     //normalize planes.
00100     float denom;
00101     AI_Vector3 tmp;
00102     
00103     for (int i=0; i<6; i++)
00104     {
00105         tmp.set (m_planes[i].a, m_planes[i].b, m_planes[i].c);
00106         denom = 1.0f / tmp.len();
00107         m_planes[i].a *= denom;
00108         m_planes[i].b *= denom;
00109         m_planes[i].c *= denom;
00110         m_planes[i].d *= denom;
00111     }
00112 }
00113 
00114 inline
00115 AI_SDB_FrustumClipper::AI_SDB_FrustumClipper(const AI_Plane clipplanes[6]) : AI_SDB_PlaneClipper(clipplanes, 6)
00116 {
00117 }
00118 
00119 #endif
00120