physx::PxRigidStatic* CPhysicManager::createStaticSphere(const Vector3 &position, const float &radius, bool trigger, int group, const Logic::Component::IPhysic *component) { assert(m_scene); PxVec3 p = Vector3ToPxVec3(position); PxTransform pose(p); PxSphereGeometry geom(radius); PxRigidStatic *actor = PxCreateStatic(*m_physics,pose,geom,*m_defaultMaterial); if(trigger) { PxShape *shape; actor->getShapes(&shape,1,0); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); } actor->userData = (void*)component; PxSetGroup(*actor,group); setupFiltering(actor,FilterGroup::eSPACE_FILTER,FilterGroup::eSPACE_FILTER); //m_scene->addActor(*actor); return actor; }
PxRigidStatic* CPhysicManager::createStaticBox(const Vector3 &position, const Vector3 &dimensions, bool trigger, int group, const IPhysic *component) { assert(m_scene); PxVec3 p = Vector3ToPxVec3(position); PxVec3 d = Vector3ToPxVec3(dimensions); PxTransform pose(p); PxBoxGeometry geom(d); PxTransform localPose(PxVec3(0,dimensions.y,0)); PxRigidStatic *actor = PxCreateStatic(*m_physics,pose,geom,*m_defaultMaterial,localPose); if(trigger) { PxShape *shape; actor->getShapes(&shape,1,0); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); } actor->userData = (void*)component; PxSetGroup(*actor,group); setupFiltering(actor,FilterGroup::eSPACE_FILTER,FilterGroup::eSPACE_FILTER); //m_scene->addActor(*actor); return actor; }
PxRigidActor* gkPhysX::createGrid() { PxRigidStatic* plane = PxCreatePlane(*m_Physics, PxPlane(PxVec3(0,1,0), 0), *m_Material); m_Scene->addActor(*plane); PxShape* shape; plane->getShapes(&shape, 1); return plane; }
void Physics::setShapeAsTrigger(PxRigidActor* actorIn) { PxRigidStatic* staticActor = actorIn->is<PxRigidStatic>(); assert(staticActor); const PxU32 numShapes = staticActor->getNbShapes(); PxShape** shapes = (PxShape**)_aligned_malloc(sizeof(PxShape*)*numShapes, 16); staticActor->getShapes(shapes, numShapes); for (PxU32 i = 0; i < numShapes; i++) { shapes[i]->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shapes[i]->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); } }
void PhysicsEngine::createPizzaPickup(physx::PxVec3 location, physx::PxF32 radius) { PxBoxGeometry geometry(radius, radius, radius); PxTransform transform(location, PxQuat::createIdentity()); PxMaterial* material = physics->createMaterial(0.5f, 0.5f, 0.5f); PxRigidStatic* actor = PxCreateStatic(*physics, transform, geometry, *material); PxShape* shape; actor->getShapes(&shape, 1); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); shape->setFlag(PxShapeFlag::eSCENE_QUERY_SHAPE, false); scene->addActor(*actor); }
PxRigidStatic* createDrivablePlane(physx::PxMaterial* material, PxPhysics* physics) { //Add a plane to the scene. PxRigidStatic* groundPlane = PxCreatePlane(*physics, PxPlane(0,1,0,0), *material); //Get the plane shape so we can set query and simulation filter data. PxShape* shapes[1]; groundPlane->getShapes(shapes, 1); //Set the query filter data of the ground plane so that the vehicle raycasts can hit the ground. physx::PxFilterData qryFilterData; setupDrivableSurface(qryFilterData); shapes[0]->setQueryFilterData(qryFilterData); //Set the simulation filter data of the ground plane so that it collides with the chassis of a vehicle but not the wheels. PxFilterData simFilterData; simFilterData.word0 = COLLISION_FLAG_GROUND; simFilterData.word1 = COLLISION_FLAG_GROUND_AGAINST; shapes[0]->setSimulationFilterData(simFilterData); return groundPlane; }
PxRigidStatic* CServer::createStaticBox(const Vector3 &position, const Vector3 &dimensions, bool trigger, int group, const IPhysics *component) { assert(_scene); // Nota: PhysX coloca el sistema de coordenadas local en el centro de la caja, mientras // que la lógica asume que el origen del sistema de coordenadas está en el centro de la // cara inferior. Para unificar necesitamos realizar una traslación en el eje Y. // Afortunadamente, el descriptor que se usa para crear el actor permite definir esta // transformación local, por lo que la conversión entre sistemas de coordenadas es transparente. // Crear un cubo estático PxTransform pose(Vector3ToPxVec3(position)); PxBoxGeometry geom(Vector3ToPxVec3(dimensions)); PxMaterial *material = _defaultMaterial; PxTransform localPose(PxVec3(0, dimensions.y, 0)); // Transformación de coordenadas lógicas a coodenadas de PhysX PxRigidStatic *actor = PxCreateStatic(*_physics, pose, geom, *material, localPose); // Transformarlo en trigger si es necesario if (trigger) { PxShape *shape; actor->getShapes(&shape, 1, 0); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); } // Anotar el componente lógico asociado a la entidad física actor->userData = (void *) component; // Establecer el grupo de colisión PxSetGroup(*actor, group); // Añadir el actor a la escena _scene->addActor(*actor); return actor; }