void Renderer::Cull( XNA::Frustum* frustum, Transform* pTransform ) { if (m_Mesh) { XNA::OrientedBox objectBox; for( int i=0; i<m_Mesh->GetNumberOfSubmeshes(); i++ ) { Submesh* submesh = m_Mesh->GetSubmesh( i ); XMVECTOR extents = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Extents ); XMVECTOR scale = XMLoadFloat3( &pTransform->GetScale().intoXMFLOAT3() ); XMVECTOR offset = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Center )*scale; XMVECTOR position = XMVector3Rotate( offset, XMLoadFloat4(&pTransform->GetOrientation().intoXMFLOAT4()) ); position += XMLoadFloat3( &pTransform->GetPosition().intoXMFLOAT3() ); XMStoreFloat3( &objectBox.Center, position ); XMStoreFloat3( &objectBox.Extents, extents*scale ); objectBox.Orientation = pTransform->GetOrientation().intoXMFLOAT4(); if( XNA::IntersectOrientedBoxFrustum( &objectBox, frustum ) > 0 ) m_SubmeshRenderData[i].bVisible = true; else m_SubmeshRenderData[i].bVisible = false; } } }
void Renderer::CullLight( SpotLight* light, Transform* pTransform ) { if (m_Mesh) { XNA::OrientedBox objectBox; XNA::Frustum lightFrustum = light->GetFrustum(); for( int i=0; i<m_Mesh->GetNumberOfSubmeshes(); i++ ) { if (m_SubmeshRenderData[i].bVisible) { Submesh* submesh = m_Mesh->GetSubmesh( i ); XMVECTOR extents = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Extents ); XMVECTOR scale = XMLoadFloat3( &pTransform->GetScale().intoXMFLOAT3() ); XMVECTOR offset = XMLoadFloat3( &submesh->GetGeometryChunk()->GetAABB()->Center )*scale; XMVECTOR position = XMVector3Rotate( offset, XMLoadFloat4(&pTransform->GetOrientation().intoXMFLOAT4()) ); position += XMLoadFloat3( &pTransform->GetPosition().intoXMFLOAT3() ); XMStoreFloat3( &objectBox.Center, position ); XMStoreFloat3( &objectBox.Extents, extents*scale ); objectBox.Orientation = pTransform->GetOrientation().intoXMFLOAT4(); if( XNA::IntersectOrientedBoxFrustum( &objectBox, &lightFrustum ) > 0 ) m_SubmeshRenderData[i].AffectingSpotLights.push_back( light ); } } } }