Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Make note of what scenery falls outside of our view frustum.
- void HK_CALL cull_scenery( hkpWorld* world,
- tbb::concurrent_vector<Physics_Scenery*> vec_scenery,
- std::vector<hkUint32>* ids_in_frustum ){
- Camera_Alt const* pcam = World_Manager::GetPlayereCamera();
- glm::vec3 look_from = World_Manager::player->get_lookFrom();
- glm::vec3 look_to = World_Manager::player->get_lookTo();
- hkVector4 transFrom(look_from.x,look_from.y,look_from.z,0);
- hkVector4 transTo(look_to.x,look_to.y,look_to.z,0);
- // Lock the world and get the tree broad-phase.
- world->lock();
- hkpTreeBroadPhase* broadphase = static_cast<hkpTreeBroadPhase*>(world->getBroadPhase());
- //broadphase->fullOptimize();
- glm::vec3 f_r = -pcam->getXAxis();
- glm::vec3 f_u = -pcam->getYAxis();
- glm::vec3 f_f = -pcam->getZAxis();
- // organize our axes...................................
- float sc = 50.0f;
- hkVector4 start_fu( f_u.x, f_u.y, f_u.z, 1 );
- hkVector4 end_fu( f_u.x*sc, f_u.y*sc, f_u.z*sc, 1 );
- hkVector4 start_fr( f_r.x, f_r.y, f_r.z, 1 );
- hkVector4 end_fr( f_r.x*sc, f_r.y*sc, f_r.z*sc, 1 );
- hkVector4 start_ff( f_f.x, f_f.y, f_f.z, 1 );
- hkVector4 end_ff( f_f.x*sc, f_f.y*sc, f_f.z*sc, 1 );
- start_fu.add(transFrom);
- end_fu.add(transFrom);
- start_fr.add(transFrom);
- end_fr.add(transFrom);
- start_ff.add(transFrom);
- end_ff.add(transFrom);
- //.....................................................
- if( VISUALIZE_AXES ){
- // Visualize the axes in the vdb........................
- HK_DISPLAY_LINE( start_fu, end_fu ,hkColor::RED);
- HK_DISPLAY_LINE( start_fr, end_fr ,hkColor::AZURE);
- HK_DISPLAY_LINE( start_ff, end_ff ,hkColor::GREEN);
- }
- //........................................................
- // Create frustum vertices.
- hkVector4 nearPlaneQuad[4];
- // Find corners according to our direction.
- float s1=10.0f;
- glm::vec3 bl( f_r*-s1 + f_u*-s1 );
- glm::vec3 br( f_r*s1 + f_u*-s1 );
- glm::vec3 tr( f_r*s1 + f_u*s1 );
- glm::vec3 tl( f_r*-s1 + f_u*s1 );
- nearPlaneQuad[0].set( bl.x, bl.y, bl.z );
- nearPlaneQuad[1].set( br.x, br.y, br.z );
- nearPlaneQuad[2].set( tr.x, tr.y, tr.z );
- nearPlaneQuad[3].set( tl.x, tl.y, tl.z );
- hkVector4 farPlaneQuad[4];
- hkSimdReal fovFactor = pcam->getFov() * 6.5f;
- hkReal farOffset = pcam->getZFar();
- for(int i=0; i<4; ++i)
- {
- farPlaneQuad[i].setMul4(fovFactor, nearPlaneQuad[i]);
- // Translate frustum.
- nearPlaneQuad[i].add( transFrom );
- farPlaneQuad[i].add( transTo );
- }
- // Draw frustum.
- if( VISUALIZE_FRUSTUM ){
- HK_DISPLAY_LINE(nearPlaneQuad[0], nearPlaneQuad[1], hkColor::YELLOW);
- HK_DISPLAY_LINE(nearPlaneQuad[1], nearPlaneQuad[2], hkColor::YELLOW);
- HK_DISPLAY_LINE(nearPlaneQuad[2], nearPlaneQuad[3], hkColor::YELLOW);
- HK_DISPLAY_LINE(nearPlaneQuad[3], nearPlaneQuad[0], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[0], farPlaneQuad[1], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[1], farPlaneQuad[2], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[2], farPlaneQuad[3], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[3], farPlaneQuad[0], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[0], nearPlaneQuad[0], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[1], nearPlaneQuad[1], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[2], nearPlaneQuad[2], hkColor::YELLOW);
- HK_DISPLAY_LINE(farPlaneQuad[3], nearPlaneQuad[3], hkColor::YELLOW);
- }
- // Compute frustum planes.
- hkVector4 planes[6];
- // Side planes
- planes[0] = computePlaneFromTriangle(nearPlaneQuad[0], farPlaneQuad[0], nearPlaneQuad[1]);
- planes[1] = computePlaneFromTriangle(nearPlaneQuad[1], farPlaneQuad[1], nearPlaneQuad[2]);
- planes[2] = computePlaneFromTriangle(nearPlaneQuad[2], farPlaneQuad[2], nearPlaneQuad[3]);
- planes[3] = computePlaneFromTriangle(nearPlaneQuad[3], farPlaneQuad[3], nearPlaneQuad[0]);
- // Near plane
- planes[4] = computePlaneFromTriangle(nearPlaneQuad[0], nearPlaneQuad[1], nearPlaneQuad[2]);
- // Far plane
- planes[5] = computePlaneFromTriangle(farPlaneQuad[0], farPlaneQuad[2], farPlaneQuad[1]);
- broadphase->lock();
- // Cull using frustum.
- hkArray<const hkpBroadPhaseHandle*> handles;
- {
- HK_TIME_CODE_BLOCK("Culling",this);
- handles.reserve(4096 / sizeof(const hkpBroadPhaseHandle*));
- broadphase->queryConvex(planes, 6, handles);
- }
- // Get out objects visible from the frustum.
- for(int i=0; i<handles.getSize(); ++i)
- {
- ids_in_frustum->push_back( handles[i]->m_id );
- }
- broadphase->unlock();
- world->unlock();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement