//----------------------------------------------------------------------------- // CalcBBox //----------------------------------------------------------------------------- NxBox CPhysicModelSimple::CalcBBox (void) const { NxBounds3 bounds; for (int i = 0; i < (int)m_ActorDesc.shapes.size(); i++) { NxShapeDesc* pShapeDesc = m_ActorDesc.shapes[i]; switch (pShapeDesc->getType()) { case NX_SHAPE_BOX: { NxBoxShapeDesc* pBoxShape = (NxBoxShapeDesc*) pShapeDesc; NxBox shapeBBox (pBoxShape->localPose.t, pBoxShape->dimensions, pBoxShape->localPose.M); NxBounds3 shapeBounds; shapeBounds.boundsOfOBB( shapeBBox.rot, shapeBBox.center, shapeBBox.extents ); bounds.combine (shapeBounds); } break; case NX_SHAPE_SPHERE: { NxSphereShapeDesc* pSphereShape = (NxSphereShapeDesc*) pShapeDesc; NxBox shapeBBox (pSphereShape->localPose.t, NxVec3(pSphereShape->radius), pSphereShape->localPose.M); NxBounds3 shapeBounds; shapeBounds.boundsOfOBB( shapeBBox.rot, shapeBBox.center, shapeBBox.extents ); bounds.combine (shapeBounds); } break; default: // Caso no soportado assert(0); break; } } NxBox result; bounds.getCenter (result.center); bounds.getExtents (result.extents); return result; }
//----------------------------------------------------------------------------- // GetWorldBounds //----------------------------------------------------------------------------- NxBounds3 CPhysicObj::GetWorldBounds (void) const { assert( m_bActivated ); int nNumParts = GetNumParts(); // NOTA: Siempre tendremos que tener al menos 1 parte. NxBounds3 result = GetWorldBounds (0); // El resto de bounds los combinamos con el resultado for (int i = 1; i < nNumParts; i++) { result.combine (GetWorldBounds(i)); } return result; }
Box3F PxBody::getWorldBounds() { AssertFatal( mActor, "PxBody::getTransform - The actor is null!" ); NxBounds3 bounds; bounds.setEmpty(); NxBounds3 shapeBounds; NxShape *const* pShapeArray = mActor->getShapes(); U32 shapeCount = mActor->getNbShapes(); for ( U32 i = 0; i < shapeCount; i++ ) { // Get the shape's bounds. pShapeArray[i]->getWorldBounds( shapeBounds ); // Combine them into the total bounds. bounds.combine( shapeBounds ); } return pxCast<Box3F>( bounds ); }
//----------------------------------------------------------------------------- // GetWorldBounds //----------------------------------------------------------------------------- NxBounds3 CPhysicObj::GetWorldBounds (int nPartIdx) const { assert( m_bActivated && (nPartIdx < GetNumParts()) ); const NxActor* pActor = GetActor(nPartIdx); // Combinamos los bounds de todas las shapes NxBounds3 result; NxBounds3 shapeBounds; uint nNumShapes = pActor->getNbShapes(); assert( nNumShapes > 0 ); NxShape* const* pShapes = pActor->getShapes(); pShapes[0]->getWorldBounds(result); for (uint i = 1; i < nNumShapes; i++) { pShapes[0]->getWorldBounds (shapeBounds); result.combine (shapeBounds); } return result; }