/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #include "OgreKdTreeCamera.h" namespace Ogre { KdTreeCamera::KdTreeCamera(const String& name, SceneManager *sm): Camera(name, sm) { } KdTreeCamera::~KdTreeCamera() { } //----------------------------------------------------------------------- // enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const { ++ mNumVisQueries; // Null boxes always invisible if ( box.isNull() ) return KDNV_NONE; // Make any pending updates to the calculated frustum planes updateFrustumPlanes(); // Get corners of the box const Vector3* pCorners = box.getAllCorners(); // For each plane, see if all points are on the negative side // If so, object is not visible. // If one or more are, it's partial. // If all aren't, full int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7}; int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM, FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT, FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR }; bool all_inside = true; for ( int plane = 0; plane < 6; ++plane ) { // Skip far plane if infinite view frustum if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR) continue; bool all_outside = true; float distance = 0; for ( int corner = 0; corner < 8; ++corner ) { distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] ); all_outside = all_outside && ( distance < 0 ); all_inside = all_inside && ( distance >= 0 ); if ( !all_outside && !all_inside ) break; } if ( all_outside ) return KDNV_NONE; } if ( all_inside ) return KDNV_FULL; else return KDNV_PART; } //----------------------------------------------------------------------- // simple vis calculation - does the same as isVisible, only different return type KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilitySimple(const AxisAlignedBox& box) const { ++ mNumVisQueries; // dummy FrustumPlane* culledBy = 0; if (mCullFrustum) { return mCullFrustum->isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE; } else { return Frustum::isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE; } } } // namespace Ogre