void test_extraPlane() { Vector< PlaneF > planes; // Build planes for a unit cube centered at the origin. // Note that the normals must be facing inwards. planes.push_back( PlaneF( Point3F( -0.5f, 0.f, 0.f ), Point3F( 1.f, 0.f, 0.f ) ) ); planes.push_back( PlaneF( Point3F( 0.5f, 0.f, 0.f ), Point3F( -1.f, 0.f, 0.f ) ) ); planes.push_back( PlaneF( Point3F( 0.f, -0.5f, 0.f ), Point3F( 0.f, 1.f, 0.f ) ) ); planes.push_back( PlaneF( Point3F( 0.f, 0.5f, 0.f ), Point3F( 0.f, -1.f, 0.f ) ) ); planes.push_back( PlaneF( Point3F( 0.f, 0.f, -0.5f ), Point3F( 0.f, 0.f, 1.f ) ) ); planes.push_back( PlaneF( Point3F( 0.f, 0.f, 0.5f ), Point3F( 0.f, 0.f, -1.f ) ) ); // Add extra plane that doesn't contribute a new edge. planes.push_back( PlaneF( Point3F( 0.5f, 0.5f, 0.5f ), Point3F( -1.f, -1.f, -1.f ) ) ); // Turn it into a polyhedron. Polyhedron polyhedron; polyhedron.buildFromPlanes( PlaneSetF( planes.address(), planes.size() ) ); // Check if we got a cube back. TEST( polyhedron.getNumPoints() == 8 ); TEST( polyhedron.getNumPlanes() == 6 ); TEST( polyhedron.getNumEdges() == 12 ); }
void SceneCullingState::debugRenderCullingVolumes() const { const ColorI occluderColor( 255, 0, 0, 255 ); const ColorI includerColor( 0, 255, 0, 255 ); const PlaneF& nearPlane = getCullingFrustum().getPlanes()[ Frustum::PlaneNear ]; const PlaneF& farPlane = getCullingFrustum().getPlanes()[ Frustum::PlaneFar ]; DebugDrawer* drawer = DebugDrawer::get(); const SceneZoneSpaceManager* zoneManager = mSceneManager->getZoneManager(); bool haveDebugZone = false; const U32 numZones = mZoneStates.size(); for( S32 zoneId = numZones - 1; zoneId >= 0; -- zoneId ) { if( !zoneManager->isValidZoneId( zoneId ) ) continue; const SceneZoneCullingState& zoneState = mZoneStates[ zoneId ]; if( !zoneManager->getZoneOwner( zoneId )->isSelected() && ( zoneId != SceneZoneSpaceManager::RootZoneId || haveDebugZone ) ) continue; haveDebugZone = true; for( SceneZoneCullingState::CullingVolumeIterator iter( zoneState ); iter.isValid(); ++ iter ) { // Temporarily add near and far plane to culling volume so that // no matter how it is defined, it has a chance of being properly // capped. const U32 numPlanes = iter->getPlanes().getNumPlanes(); const PlaneF* planes = iter->getPlanes().getPlanes(); TempAlloc< PlaneF > tempPlanes( numPlanes + 2 ); tempPlanes[ 0 ] = nearPlane; tempPlanes[ 1 ] = farPlane; dMemcpy( &tempPlanes[ 2 ], planes, numPlanes * sizeof( PlaneF ) ); // Build a polyhedron from the plane set. Polyhedron polyhedron; polyhedron.buildFromPlanes( PlaneSetF( tempPlanes, numPlanes + 2 ) ); // If the polyhedron has any renderable data, // hand it over to the debug drawer. if( polyhedron.getNumEdges() ) drawer->drawPolyhedron( polyhedron, iter->isOccluder() ? occluderColor : includerColor ); } } }