void Px3World::explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ) { physx::PxVec3 nxPos = px3Cast<physx::PxVec3>( pos ); const physx::PxU32 bufferSize = 10; physx::PxSphereGeometry worldSphere(radius); physx::PxTransform pose(nxPos); physx::PxOverlapBufferN<bufferSize> buffer; if(!mScene->overlap(worldSphere,pose,buffer)) return; for ( physx::PxU32 i = 0; i < buffer.nbTouches; i++ ) { physx::PxRigidActor *actor = buffer.touches[i].actor; bool dynamic = actor->isRigidDynamic(); if ( !dynamic ) continue; bool kinematic = actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC; if ( kinematic ) continue; physx::PxVec3 force = actor->getGlobalPose().p - nxPos; force.normalize(); force *= forceMagnitude; physx::PxRigidBody *body = actor->is<physx::PxRigidBody>(); physx::PxRigidBodyExt::addForceAtPos(*body,force,nxPos,physx::PxForceMode::eIMPULSE); } }
bool CPhysicsManager::CheckOverlapSphere(Vect3f LightPosition, float radius){ NxSphere worldSphere(NxVec3(LightPosition.x,LightPosition.y,LightPosition.z),radius); bool intersection = CORE->GetPhysicsManager()->GetScene()->checkOverlapSphere(worldSphere, NX_STATIC_SHAPES,1<<0); return intersection; }
void CPhysicsManager::OverlapSphereActorGrenade (float radiusSphere, const Vect3f& posSphere, std::vector<CPhysicUserData*> impactObjects, float _fPower) { assert(m_pScene); NxSphere worldSphere(NxVec3(posSphere.x,posSphere.y,posSphere.z), radiusSphere); NxU32 nbShapes = m_pScene->getNbDynamicShapes(); NxShape** shapes = new NxShape* [nbShapes]; for (NxU32 i = 0; i < nbShapes; i++) { shapes[i] = NULL; } //NX_DYNAMIC_SHAPES m_pScene->overlapSphereShapes(worldSphere, NX_DYNAMIC_SHAPES, nbShapes, shapes, NULL); for (NxU32 i = 0; i < nbShapes; i++) { if( shapes[i] != NULL ) { NxActor* actor = &shapes[i]->getActor(); CPhysicUserData* physicObject = (CPhysicUserData*)actor->userData; //Si está petando aquí quiere decir que se ha registrado un objeto físico sin proporcionarle ID assert(physicObject); //Antes de meterlo comprobamos que no exista ya (un objeto fisico puede estar compuesto por varias shapes) std::vector<CPhysicUserData*>::iterator it(impactObjects.begin()); std::vector<CPhysicUserData*>::iterator itEnd(impactObjects.end()); bool find = false; while (it!=itEnd) { CPhysicUserData* id = *it; if( id == physicObject) find = true; ++it; } if(!find) { impactObjects.push_back(physicObject); physicObject->SetColor(colRED); ApplyExplosion(actor,posSphere,radiusSphere,_fPower); } } //delete &shapes[i]; } delete shapes; /*for (NxU32 i = 0; i < nbShapes; i++) { delete &shapes[i]; }*/ }
DecalInstance* DecalManager::raycast( const Point3F &start, const Point3F &end, bool savedDecalsOnly ) { if ( !mData ) return NULL; const Vector<DecalSphere*> &grid = mData->getGrid(); DecalInstance *inst = NULL; SphereF worldSphere( Point3F( 0, 0, 0 ), 1.0f ); Vector<DecalInstance*> hitDecals; for ( U32 i = 0; i < grid.size(); i++ ) { DecalSphere *decalSphere = grid[i]; if ( !decalSphere->mWorldSphere.intersectsRay( start, end ) ) continue; const Vector<DecalInstance*> &items = decalSphere->mItems; for ( U32 n = 0; n < items.size(); n++ ) { inst = items[n]; if ( !inst ) continue; if ( savedDecalsOnly && !(inst->mFlags & SaveDecal) ) continue; worldSphere.center = inst->mPosition; worldSphere.radius = inst->mSize; if ( !worldSphere.intersectsRay( start, end ) ) continue; RayInfo ri; bool containsPoint = false; if ( gServerContainer.castRayRendered( start, end, STATIC_COLLISION_MASK, &ri ) ) { Point2F poly[4]; poly[0].set( inst->mPosition.x - (inst->mSize / 2), inst->mPosition.y + (inst->mSize / 2)); poly[1].set( inst->mPosition.x - (inst->mSize / 2), inst->mPosition.y - (inst->mSize / 2)); poly[2].set( inst->mPosition.x + (inst->mSize / 2), inst->mPosition.y - (inst->mSize / 2)); poly[3].set( inst->mPosition.x + (inst->mSize / 2), inst->mPosition.y + (inst->mSize / 2)); if ( MathUtils::pointInPolygon( poly, 4, Point2F(ri.point.x, ri.point.y) ) ) containsPoint = true; } if( !containsPoint ) continue; hitDecals.push_back( inst ); } } if ( hitDecals.empty() ) return NULL; gSortPoint = start; dQsort( hitDecals.address(), hitDecals.size(), sizeof(DecalInstance*), cmpDecalDistance ); return hitDecals[0]; }