/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #include "OgreBvHierarchyCamera.h" namespace Ogre { BvHierarchyCamera::BvHierarchyCamera(const String& name, SceneManager *sm): Camera(name, sm) { } BvHierarchyCamera::~BvHierarchyCamera() { } //----------------------------------------------------------------------- // enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum BvHierarchyCamera::NodeVisibility BvHierarchyCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const { ++ mNumVisQueries; // Null boxes always invisible if ( box.isNull() ) return BVHNV_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 BVHNV_NONE; } if ( all_inside ) return BVHNV_FULL; else return BVHNV_PART; } //----------------------------------------------------------------------- // simple vis calculation - does the same as isVisible, only different return type BvHierarchyCamera::NodeVisibility BvHierarchyCamera::getVisibilitySimple(const AxisAlignedBox& box) const { ++ mNumVisQueries; // dummy FrustumPlane* culledBy = 0; if (mCullFrustum) { return mCullFrustum->isVisible(box, culledBy) ? BVHNV_PART : BVHNV_NONE; } else { return Frustum::isVisible(box, culledBy) ? BVHNV_PART : BVHNV_NONE; } } } // namespace Ogre