/// \brief /// Helper function to retrieve current distance to a given plane /// /// \param vCameraPos /// Camera position to test the distance against /// \param fLODScaleSqr /// Square of the LOD scaling factor /// \param fPlane /// Reference plane distance, will be subtracted from final result /// /// \returns /// Relative distance from object to given plane inline float GetDistanceToPlane(const hkvVec3& vCameraPos, float fLODScaleSqr=1.f, float fPlane=0.f) const { int iLODMode = m_iPerformTestFlags&VIS_PERFORM_LODTEST; float fDistSqr; switch (iLODMode) { case VIS_LOD_TEST_NONE: fDistSqr = 0.0f; break; case VIS_LOD_TEST_CLIPPOSITION: fDistSqr = vCameraPos.getDistanceToSquared(m_vClipReference); break; case VIS_LOD_TEST_CLIPPOSITION|VIS_LOD_TEST_APPLYLODSCALING: fDistSqr = vCameraPos.getDistanceToSquared(m_vClipReference)*fLODScaleSqr; break; case VIS_LOD_TEST_BOUNDINGBOX: fDistSqr = m_BoundingBox.getDistanceToSquared(vCameraPos); break; case VIS_LOD_TEST_BOUNDINGBOX|VIS_LOD_TEST_APPLYLODSCALING: fDistSqr = m_BoundingBox.getDistanceToSquared(vCameraPos)*fLODScaleSqr; break; default: VASSERT_MSG(false,"Invalid combination of LOD flags"); return false; } return hkvMath::sqrt(fDistSqr) - fPlane; }
/// \brief /// Helper function for visibility loop implementations /// /// \param vCameraPos /// Camera position to test LOD clipping /// \param fLODScaleSqr /// Square of the LOD scaling factor /// /// \returns /// true if the object is clipped either by near of far clip distance (if specified) inline bool IsNearOrFarClipped(const hkvVec3& vCameraPos, float fLODScaleSqr=1.f) const { // changes in this function have to be reflected in SPU version IsNearOrFarClipped int iLODMode = m_iPerformTestFlags&VIS_PERFORM_LODTEST; float fDistSqr; switch (iLODMode) { case VIS_LOD_TEST_NONE: return false; case VIS_LOD_TEST_CLIPPOSITION: fDistSqr = vCameraPos.getDistanceToSquared(m_vClipReference); break; case VIS_LOD_TEST_CLIPPOSITION|VIS_LOD_TEST_APPLYLODSCALING: fDistSqr = vCameraPos.getDistanceToSquared(m_vClipReference)*fLODScaleSqr; break; case VIS_LOD_TEST_BOUNDINGBOX: fDistSqr = m_BoundingBox.getDistanceToSquared(vCameraPos); break; case VIS_LOD_TEST_BOUNDINGBOX|VIS_LOD_TEST_APPLYLODSCALING: fDistSqr = m_BoundingBox.getDistanceToSquared(vCameraPos)*fLODScaleSqr; break; default: VASSERT_MSG(false,"Invalid combination of LOD flags"); return false; } return ((m_fNearClipDistance>0.f) && (fDistSqr<(m_fNearClipDistance*m_fNearClipDistance))) || ((m_fFarClipDistance>0.f) && (fDistSqr>=(m_fFarClipDistance*m_fFarClipDistance))); }