bool CSPhysXObject_Character::create(CSPhysXWorld* world, IPhysicsObjectData data) { if (!CSPhysXObject::create(world)) return false; #define SKINWIDTH 0.0001f PxF32 gInitialRadius = data.scale.X; PxF32 gInitialHeight = data.scale.Y; if (data.node) { gInitialRadius = data.node->getBoundingBox().getExtent().X / 2 * data.scale.X ; gInitialHeight = data.node->getBoundingBox().getExtent().Y / 2 * data.scale.Y ; } PxCapsuleControllerDesc desc; desc.position.x = data.position.X; desc.position.y = data.position.Y; desc.position.z = data.position.Z; desc.radius = gInitialRadius; desc.height = gInitialHeight; desc.upDirection = PxVec3(0,1,0); desc.slopeLimit = cosf(degToRad(45.0f)); desc.stepOffset = 0.02f; desc.callback = &gControllerHitReport; desc.userData = (void*)data.userdata; desc.scaleCoeff = 0.9f; desc.volumeGrowth = 1.2f; desc.density = 10; desc.material = getWorld()->getPhysXManager()->m_DefaultMaterial; m_Controller = world->getControllerManager()->createController(*getWorld()->getPhysXManager()->m_PhysicsSDK, getWorld()->getScene(), desc); m_Controller->setUserData((void*)data.userdata); m_Controller->getActor()->userData = (void*)data.userdata; PxShape* shapes[10]; PxU32 nShapes = m_Controller->getActor()->getShapes(shapes, 10); while (nShapes--) { shapes[nShapes]->setSimulationFilterData(getFilterData(data.objecttype)); } CS_CHECK_NULL(m_Controller, CSLOGTYPE::CSL_WARNING, "CSPhysXObject_Character::create() Controller creaation failed"); // everything went fine return true; }
void PhysActor_PhysX::Rotate(vec4f quat) { if (impl && impl->physActor) { PxTransform trans = impl->physActor->getGlobalPose(); PxQuat rot_quat(quat.w, PxVec3(quat.x, quat.y, quat.z)); rot_quat = rot_quat.getNormalized(); trans.q *= rot_quat; trans.q = trans.q.getNormalized(); impl->physActor->setGlobalPose(trans); } }
PxConvexMesh* createSquashedCuboidMesh(const PxF32 baseLength, const PxF32 baseDepth, const PxF32 height1, const PxF32 height2, PxPhysics& physics, PxCooking& cooking) { const PxF32 x=baseLength*0.5f; const PxF32 z=baseDepth*0.5f; PxVec3 verts[8]= { PxVec3(-x,-0.5f*height1,-z), PxVec3(-x,-0.5f*height1,+z), PxVec3(+x,-0.5f*height1,-z), PxVec3(+x,-0.5f*height1,+z), PxVec3(-x,-0.5f*height1+height2,-z), PxVec3(-x,+0.5f*height1,+z), PxVec3(+x,-0.5f*height1+height2,-z), PxVec3(+x,+0.5f*height1,+z) }; PxU32 numVerts=8; return createConvexMesh(verts,numVerts,physics,cooking); }
PxConvexMesh* Vehicle::createChassisMesh(const PxVec3 dims, PxPhysics& physics, PxCooking& cooking) { const PxF32 x = dims.x*0.5f; const PxF32 y = dims.y*0.5f; const PxF32 z = dims.z*0.5f; PxVec3 verts[8] = { PxVec3(x, y, -z), PxVec3(x, y, z), PxVec3(x, -y, z), PxVec3(x, -y, -z), PxVec3(-x, y, -z), PxVec3(-x, y, z), PxVec3(-x, -y, z), PxVec3(-x, -y, -z) }; return createConvexMesh(verts, 8, physics, cooking); }
void PlayerController::MovePlayerController(double _dt) { const PxVec3 up(0, 1, 0); bool onGround; float movementSpeed = 10.0f; float rotationSpeed = 1.0f; float minDistance = 0.001f; if (m_myHitReport->GetPlayerContactNormal().y > 0.3f) { m_characterYVelocity = -0.1f; onGround = true; } else { m_characterYVelocity += -1 * _dt; onGround = false; } m_myHitReport->ClearPlayerContactNormal(); PxVec3 velocity(0, m_characterYVelocity, 0); if (glfwGetKey(m_window, GLFW_KEY_LEFT) == GLFW_PRESS) { m_characterRotation += glm::radians(5.f); } if (glfwGetKey(m_window, GLFW_KEY_RIGHT) == GLFW_PRESS) { m_characterRotation -= glm::radians(5.f); } if (glfwGetKey(m_window, GLFW_KEY_UP) == GLFW_PRESS) { velocity.z -= movementSpeed * _dt; } if (glfwGetKey(m_window, GLFW_KEY_DOWN) == GLFW_PRESS) { velocity.z += movementSpeed * _dt; } PxControllerFilters filter; PxQuat rotation(m_characterRotation, PxVec3(0, 1, 0)); //velocity = PxVec3(0, m_characterYVelocity, 0); m_controller->move(rotation.rotate(velocity), minDistance, _dt, filter); }
void GameWorld::addPxMoveBall(int num) { Color4f color(50 / 255.0, 225 / 255.0, 50 / 255.0); for (int i = 0;i < num;i++) { PxMoveBall* newball = new PxMoveBall(color, 5.0, 100.0f); Material mtl; PerlinImage perlinGreen = createPerlinGreenImage(40, 40, 6, 1.8); PerlinTexture(perlinGreen, mtl.kd_texid); mtl.ka = Color4f(1, 1, 1, 1); mtl.kd = Color4f(1, 1, 1, 1); newball->mtl = mtl; newball->createPxBall(*gPhysics, PxTransform(PxVec3(rand() % 500 - 250, 100, rand() % 700 - 350)), *gMaterial); newball->pxActor->setAngularDamping(0.5); gScene->addActor(*(newball->pxActor)); pxMoveBalls.push_back(newball); perlinGreen.clear(); } }
void KinematicController::CreatePhyiscsAgent() { PxTransform transform(PxVec3(m_position.x, m_position.y, m_position.z)); //transform = PxVec3(0, 0, 0); float density = 50; float halfHeight = m_height / 2; PxCapsuleGeometry capsule(m_radius, m_height); m_actor = PxCreateDynamic(*m_physicsObject->m_Physics, transform, capsule, *m_physicsObject->m_PhysicsMaterial, density); m_physicsObject->m_PhysicsScene->addActor(*m_actor); m_physicsObject->m_boxActors.push_back(m_actor); }
PxVec3 Scene::getWindAtPoint(const PxVec3& point) { if( !database::LocationInfo::getRecord( _location->getDatabaseId() )->wind ) { return PxVec3( 0,0,0 ); } float windAmbient = _location->getWindAmbient(); float windBlast = _location->getWindBlast(); float windAmplitude = ( windBlast - windAmbient ) / 2; float windMagnitude = windAmbient + windAmplitude + windAmplitude * blast( _windTime ); PxVec3 windN = wrap( _location->getWindDirection() ); windN.normalize(); return windN * windMagnitude; }
void GLES2Renderer::renderQuad(const void* verts, PxU32 nbVerts, const PxU16* indices, PxU32 nbIndices, RendererMaterial* material) { PxU32 positionStride = 0, colorStride = 0, texcoordStride = 0, normalStride = 0; PxU8* locked_positions = static_cast<PxU8*>(m_quadVertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_POSITION, positionStride)); PxU8* locked_texcoords = static_cast<PxU8*>(m_quadVertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_TEXCOORD0, texcoordStride)); PxU8* locked_colors = static_cast<PxU8*>(m_quadVertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_COLOR, colorStride)); // copy indices PxU16* locked_indices = static_cast<PxU16*>(m_quadIndexBuffer->lock()); memcpy(locked_indices, indices, nbIndices * sizeof(PxU16)); m_quadIndexBuffer->unlock(); PxU32 windowWidth, windowHeight; getWindowSize(windowWidth, windowHeight); PxReal windowWidthHalf = windowWidth / 2.0f, windowHeightHalf = windowHeight / 2.0f; TextVertex* tv = (TextVertex*)verts; PxU32 color; for(PxU32 i = 0; i < nbVerts; ++i, locked_positions += positionStride, locked_colors += colorStride, locked_texcoords += texcoordStride, tv += 1) { PxVec3 pos = PxVec3(tv->p.x / windowWidthHalf - 1.0f, 1.0f - tv->p.y / windowHeightHalf, 0.0f); memcpy(locked_positions, &(pos), sizeof(tv->p)); color = tv->color; RevertColor(color); memcpy(locked_colors, &color, sizeof(tv->color)); memcpy(locked_texcoords, &(tv->u), sizeof(PxReal)); memcpy(locked_texcoords + sizeof(PxReal), &(tv->v), sizeof(PxReal)); } m_quadVertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_COLOR); m_quadVertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_TEXCOORD0); m_quadVertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_POSITION); m_quadMesh->setVertexBufferRange(0, nbVerts); m_quadMesh->setIndexBufferRange(0, nbIndices); m_quadMesh->bind(); m_quadMesh->render(material); m_quadMesh->unbind(); }
PxGeometry& Camera::getPixelFrustum(FDreal pixelXSize, FDreal pixelYSize) { if (pixelFrustum.isValid()) { return pixelFrustum; } Vector3 proj1(-pixelXSize / 2, -pixelYSize / 2, 1); Vector3 proj2(-pixelXSize / 2, pixelYSize / 2, 1); Vector3 proj3(pixelXSize / 2, -pixelYSize / 2, 1); Vector3 proj4(pixelXSize / 2, pixelYSize / 2, 1); fdmath::Matrix44 projInverse; fdmath::gluInvertMatrix44(projection, projInverse); FDreal len = -100.0f; Vector3 view1 = projInverse.transform(proj1).getNormalized() * len; Vector3 view2 = projInverse.transform(proj2).getNormalized() * len; Vector3 view3 = projInverse.transform(proj3).getNormalized() * len; Vector3 view4 = projInverse.transform(proj4).getNormalized() * len; static const PxVec3 convexVerts[] = {PxVec3(0,0,0), view1, view2, view3, view4}; PhysicsSystem* physics = FreeThread__getWorld(). getSystem<PhysicsSystem>(); PxConvexMeshDesc convexDesc; convexDesc.points.count = 5; convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = convexVerts; convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX; convexDesc.vertexLimit = 256; PxDefaultMemoryOutputStream buf; if (!physics->cooking->cookConvexMesh(convexDesc, buf)) { FD_THROW(GenericException("Unable to cook convex pixel mesh!")); } PxDefaultMemoryInputData input(buf.getData(), buf.getSize()); PxConvexMesh* convexMesh = physics->physics->createConvexMesh(input); pixelFrustum = PxConvexMeshGeometry(convexMesh); return pixelFrustum; }
void CParticleSystem::SetBufferData() { if (m_pParticleSystem) g_PhysxManager->GetActiveScene()->removeActor(*m_pParticleSystem); if (!m_Emitter.m_useSkeleton) { m_pParticleSystem = g_PhysxManager->CreateParticleSystem(m_numParticles); } m_particles.initialize(m_numParticles); VEC3 offset = GetOffsetPosition(); PxVec3 pos = PxVec3(0, 0, 0); for (int i = 0; i < m_numParticles; i++) { m_particles.indexBuffer[i] = i; m_particles.maxLifeTimeBuffer[i] = *m_Emitter.GetLifeTime() + random(*m_Emitter.GetLifeTimeRandomMin(), *m_Emitter.GetLifeTimeRandomMax()); //max time pos = *m_Emitter.GetPosition() + PhysxConversion::Vec3ToPxVec3(offset); m_particles.positionBuffer[i] = pos; m_particles.velocityBuffer[i] = *m_Emitter.GetVelocity(); m_particles.negativeVelocityBuffer[i] = -*m_Emitter.GetVelocity(); m_particles.lifeTimeBuffer[i] = m_particles.maxLifeTimeBuffer[i]; dbg("Particle %d - max lifetime = %f\n", i, m_particles.lifeTimeBuffer[i]); m_particles.positionInitBuffer[i] = pos; m_particles.velocityInitBuffer[i] = m_initial_velocity; m_particles.colorBuffer[i] = PhysxConversion::PxVec4ToVec4(*m_Emitter.GetColor()); m_particles.colorOriginBuffer[i] = m_particles.colorBuffer[i]; } m_particles.speed_frame = frames_speed; m_particles.numParticles = m_numParticles; bool ret = true; //m_pParticleValidity = (PxU32*)PX_ALLOC(((m_pParticleSystem->getMaxParticles() + 31) >> 5) << 2, "validParticleBitmap"); if (!m_Emitter.m_useSkeleton) { m_pIndexPool = PxParticleExt::createIndexPool(m_numParticles); m_pParticleValidity = std::vector<PxU32>(((m_pParticleSystem->getMaxParticles() + 31) >> 5) << 2).data(); ret = CreateParticles(m_particles); }
int main(int argc, char** argv) { Viewport window("The People of Earth TestBed ***Demo***", 800, 600/*1920, 1080*/, 0); GUIEngine guiEngine("Assets/GUI"); RenderingEngine renderingEngine(window); SceneManager sceneManager(&window); PhysicsEngine physicsEngine; physicsEngine.getPhysicsWorld()->init(PxVec3(0.0f, 0.0f, 0.0f), 20000.0f); AudioEngine audioEngine; CoreEngine core(60.0, &window, &renderingEngine, &physicsEngine, &audioEngine, &guiEngine, &sceneManager); sceneManager.push(new TestScene, Modality::Exclusive); core.start(); return 0; }
void Physx1::MakeBlocks() { PxTransform m_transform(PxVec3(0, 20, 0)); PxBoxGeometry box(2, 2, 2); float density = 50; m_dynamicActor = PxCreateDynamic(*m_Physics, m_transform, box, *m_PhysicsMaterial, density); m_boxActors.push_back(m_dynamicActor); int size = m_boxActors.size(); m_PhysicsScene->addActor(*m_boxActors[size - 1]); m_boxCount++; std::cout << "Boxes in Scene: " << m_boxCount << "\n"; }
//apply the calculated movement void TCompCharacterController::ApplyPendingMoves(float dt) { PROFILE_FUNCTION("apply moves"); std::string toprint = "apply pending moves "; toprint = toprint + name; if (name == "pj") { int i = 0; } if (m_toMove != VEC3(0.0f, 0.0f, 0.0f)) { PROFILE_FUNCTION(name.c_str()); assert(isValid(m_toMove)); PxVec3 moved = PxVec3(m_toMove.x, m_toMove.y, m_toMove.z); m_last_speed = m_pActor->getActor()->getLinearVelocity(); m_flagsCollisions = m_pActor->move(moved, 0.0f, dt, m_filterController); //clean acceleration & pendent displacement m_toMove = VEC3(0.0f, 0.0f, 0.0f); m_accel = m_toMove; } }
void Spacetime::setState(matrix<double> stateVector) { std::vector<PxQuat> theta; for (int i = 0; i < joints.size(); i++) { PxQuat q = PxQuat::createIdentity(); if (i == 0) { if (DOF > X) { q *= PxQuat(stateVector((i)*DOF+X,0), PxVec3(1,0,0)); } if (DOF > Y) { q *= PxQuat(stateVector((i)*DOF+Y,0), PxVec3(0,1,0)); } if (DOF > Z) { q *= PxQuat(stateVector((i)*DOF+Z,0), PxVec3(0,0,1)); } } else { if (DOF > X) { q *= PxQuat(stateVector((i)*DOF+X,0), PxVec3(1,0,0)) * theta[(i-1)*DOF+X]; } if (DOF > Y) { q *= PxQuat(stateVector((i)*DOF+Y,0), PxVec3(0,1,0)) * theta[(i-1)*DOF+Y]; } if (DOF > Z) { q *= PxQuat(stateVector((i)*DOF+Z,0), PxVec3(0,0,1)) * theta[(i-1)*DOF+Z]; } } theta.push_back(q); } dynamic_actors[0]->setGlobalPose(PxTransform(root, PxQuat::createIdentity())); PxVec3 lastJointPos = dynamic_actors[0]->getGlobalPose().p + PxVec3(0,0.5,0); PxQuat lastJointRot = dynamic_actors[0]->getGlobalPose().q; for (int i = 0; i < joints.size(); i++) { PxRigidDynamic *current = dynamic_actors[i+1]; PxVec3 t = theta[i].rotate(-joint_local_positions[i]); PxVec3 gPos = lastJointPos + t; current->setGlobalPose(PxTransform(gPos, theta[i])); lastJointPos = lastJointPos + 2*t; } for (int i = 0; i < joints.size(); i++) { PxRigidDynamic *current = dynamic_actors[i+1]; PxVec3 angularVelocity; if (DOF > X) { angularVelocity[X] = stateVector(joints.size()*DOF + i*DOF+X,0); } else { angularVelocity[X] = 0.0; } if (DOF > Y) { angularVelocity[Y] = stateVector(joints.size()*DOF + i*DOF+Y,0); } else { angularVelocity[Y] = 0.0; } if (DOF > Z) { angularVelocity[Z] = stateVector(joints.size()*DOF + i*DOF+Z,0); } else { angularVelocity[Z] = 0.0; } current->setAngularVelocity(angularVelocity); current->setLinearVelocity(PxVec3(0,0,0)); } }
void Physx1::setUpPhysX() { m_myCallback = new myAllocator(); m_PhysicsFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *m_myCallback, m_defaultErrorCallback); m_Physics = PxCreatePhysics(PX_PHYSICS_VERSION, *m_PhysicsFoundation, PxTolerancesScale()); PxInitExtensions(*m_Physics); //Create physics material m_PhysicsMaterial = m_Physics->createMaterial(0.5f, 0.5f, .5f); PxSceneDesc sceneDesc(m_Physics->getTolerancesScale()); sceneDesc.gravity = PxVec3(0, -10.0f, 0); sceneDesc.filterShader = &physx::PxDefaultSimulationFilterShader; sceneDesc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1); m_PhysicsScene = m_Physics->createScene(sceneDesc); }
PxConvexMesh* createWedgeConvexMesh(const PxVec3& halfExtents, PxPhysics& physics, PxCooking& cooking) { PxVec3 verts[6]= { PxVec3(-halfExtents.x, -halfExtents.y, -halfExtents.z), PxVec3(-halfExtents.x, -halfExtents.y, +halfExtents.z), PxVec3(-halfExtents.x, +halfExtents.y, -halfExtents.z), PxVec3(+halfExtents.x, -halfExtents.y, -halfExtents.z), PxVec3(+halfExtents.x, -halfExtents.y, +halfExtents.z), PxVec3(+halfExtents.x, +halfExtents.y, -halfExtents.z) }; PxU32 numVerts=6; return createConvexMesh(verts,numVerts,physics,cooking); }
// add some physics objects into the scene void AddPhyObjects() { PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 1, 0, 0), *gMaterial); gScene->addActor(*groundPlane); PxShape* shape = gPhysics->createShape(PxBoxGeometry(1.0f, 1.0f, 1.0f), *gMaterial); PxTransform localTm(PxVec3(-3.0f, 5.0f, 0.f)); PxRigidDynamic* body = gPhysics->createRigidDynamic(localTm); body->attachShape(*shape); PxRigidBodyExt::updateMassAndInertia(*body, 10.0f); gScene->addActor(*body); shape->release(); shape = gPhysics->createShape(PxSphereGeometry(1.0f), *gMaterial); PxTransform localTmS(PxVec3(3.0f, 5.0f, 0.f)); body = gPhysics->createRigidDynamic(localTmS); body->attachShape(*shape); PxRigidBodyExt::updateMassAndInertia(*body, 10.0f); gScene->addActor(*body); shape->release(); PxRigidDynamic* dynamic = PxCreateDynamic(*gPhysics, PxTransform(PxVec3(0, 20, 20)), PxSphereGeometry(1), *gMaterial, 10.0f); dynamic->setAngularDamping(0.5f); dynamic->setLinearVelocity(PxVec3(0, -5, -10)); gScene->addActor(*dynamic); // add capsule into the scene shape = gPhysics->createShape(PxCapsuleGeometry(1.0f, 3.0f), *gMaterial); PxTransform localTmC(PxVec3(3.0f, 5.0f, -3.f)); body = gPhysics->createRigidDynamic(localTmC); body->attachShape(*shape); PxRigidBodyExt::updateMassAndInertia(*body, 10.0f); gScene->addActor(*body); // add a static box as the trigger shape = gPhysics->createShape(PxBoxGeometry(1.0f, 1.0f, 1.0f), *gMaterial); PxTransform localTmTrigger(PxVec3(0.0f, 1.0f, -10.f)); body = gPhysics->createRigidDynamic(localTmTrigger); shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true); body->attachShape(*shape); body->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, true); gScene->addActor(*body); shape->release(); }
MirrorScene::MirrorScene(physx::PxScene &primaryScene, physx::PxScene &mirrorScene, NxMirrorScene::MirrorFilter &mirrorFilter, physx::PxF32 mirrorStaticDistance, physx::PxF32 mirrorDynamicDistance, physx::PxF32 mirrorDistanceThreshold) : mPrimaryScene(primaryScene) , mMirrorScene(mirrorScene) , mMirrorFilter(mirrorFilter) , mMirrorStaticDistance(mirrorStaticDistance) , mMirrorDynamicDistance(mirrorDynamicDistance) , mMirrorDistanceThreshold(mirrorDistanceThreshold*mirrorDistanceThreshold) , mTriggerActor(NULL) , mTriggerMaterial(NULL) , mTriggerShapeStatic(NULL) , mTriggerShapeDynamic(NULL) , mSimulationEventCallback(NULL) { mLastCameraLocation = PxVec3(1e9,1e9,1e9); primaryScene.getPhysics().registerDeletionListener(*this,physx::PxDeletionEventFlag::eMEMORY_RELEASE | physx::PxDeletionEventFlag::eUSER_RELEASE); }
bool ParticleChain::checkPenetration(const Ogre::Vector3 &position, Ogre::Vector3 &closestSurfacePos, Ogre::Vector3 &collisionNormal) { PxShape *hit = nullptr; PxVec3 pxPos = Convert::toPx(position); if (mPhysXScene->getPxScene()->overlapAny(PxSphereGeometry(0.05f), PxTransform(pxPos), hit)) { PxVec3 actorCenter = hit->getActor().getWorldBounds().getCenter(); PxVec3 rayDir = actorCenter - pxPos; rayDir.normalize(); PxVec3 rayOrigin = pxPos - rayDir.multiply(PxVec3(0.2f, 0.2f, 0.2f)); if (mPhysXScene->getPxScene()->overlapAny(PxSphereGeometry(0.05f), PxTransform(rayOrigin), hit)) return false; PxRaycastHit rayHit; if (mPhysXScene->getPxScene()->raycastSingle(rayOrigin, rayDir, 0.2f, PxSceneQueryFlag::eIMPACT|PxSceneQueryFlag::eNORMAL|PxSceneQueryFlag::eDISTANCE, rayHit)) { closestSurfacePos = Convert::toOgre(rayHit.impact); collisionNormal = Convert::toOgre(rayHit.normal); return true; } } return false; }
void ApexParticles::CreateEmitter(NxApexSDK* gApexSDK, NxApexScene* gApexScene) { NxApexEmitterAsset* emitterAsset; physx::apex::NxApexAsset* asset = reinterpret_cast<physx::apex::NxApexAsset*>(gApexSDK->getNamedResourceProvider()->getResource(NX_APEX_EMITTER_AUTHORING_TYPE_NAME, "testSpriteEmitter4ParticleFluidIos")); if (asset) { emitterAsset = static_cast<NxApexEmitterAsset*> (asset); } //NxApexEmitterAsset* emitterAsset = static_cast<NxApexEmitterAsset*> (gApexSDK->createAsset(asParams, "testMeshEmitter4ParticleIos.apb")); gApexSDK->forceLoadAssets(); NxParameterized::Interface* descParams = emitterAsset->getDefaultActorDesc(); PX_ASSERT(descParams); if (!descParams) { return; } // Set Actor pose //NxParameterized::setParamMat44( *descParams, "initialPose", pose ); NxApexEmitterActor* emitterActor; if(descParams->areParamsOK()) { emitterActor = static_cast<NxApexEmitterActor*>(emitterAsset->createApexActor(*descParams,*gApexScene)); if(emitterActor) { emitterActor->setCurrentPosition(PxVec3(0.0f, 1.0f, 0.0f)); emitterActor->startEmit( true ); //emitterActor->setLifetimeRange(physx::apex::NxRange<PxF32>(1,5)); //emitterActor->setRateRange(physx::apex::NxRange<PxF32>(10, 10)); } } PxBounds3 b; b.setInfinite(); mRenderVolume = mIofxModule->createRenderVolume(*gApexScene, b, 0, true ); emitterActor->setPreferredRenderVolume( mRenderVolume ); }
// Experiment specific functions called from ARSS.cpp void CreateExperiment() { // This is how you turn on the grid display. (There is also an XY Grid.) gDebug.bXZGridOn=true; // This is how you create a ground plane (and save its address in gExp.VIPs). CreateGroundPlane(); // This is how you create a compound, multi-shape, static actor. PxRigidStatic* basket = gPhysX.mPhysics->createRigidStatic(PxTransform(PxVec3(0))); if (!basket) ncc__error("basket fail!"); PxMaterial* defmat=gPhysX.mDefaultMaterial; PxBoxGeometry base(0.5,0.1,0.5); PxBoxGeometry pole(0.05,1,0.05); PxBoxGeometry board(0.5,0.5,0.01); PxBoxGeometry hoopel(0.01,0.01,0.15); basket->createShape(base,*defmat,PxTransform(PxVec3(0,0.1,0))); basket->createShape(pole,*defmat,PxTransform(PxVec3(0,1,0))); PxShape* sboard = basket->createShape(board,*defmat,PxTransform(PxVec3(0,2,0.05))); PxShape* shoopel1 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(-0.15,2,0.15+0.06))); PxShape* shoopel2 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(+0.15,2,0.15+0.06))); PxShape* shoopel3 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(+0.00,2,0.30+0.05),PxQuat(PxPi/2,PxVec3(0,1,0)))); gPhysX.mScene->addActor(*basket); // We saved the pointers to the shapes we wish to color separately, with a call to the convenience function... ColorShape(sboard, ncc::rgb::yLightYellow); // ... or manually (in case we wish to be efficient with duplicate colors). gColors.colorBucket.push_back(vector<GLubyte>(3)); gColors.colorBucket.back()[0]=ncc::rgb::grBlack[0]; gColors.colorBucket.back()[1]=ncc::rgb::grBlack[1]; gColors.colorBucket.back()[2]=ncc::rgb::grBlack[2]; shoopel1->userData=&(gColors.colorBucket.back()[0]); shoopel2->userData=&(gColors.colorBucket.back()[0]); shoopel3->userData=&(gColors.colorBucket.back()[0]); // We signal that the experiment is ready for simulation by setting this flag. gSim.isRunning = true; }
PxTriangleMesh* createTriangleMesh( osg::Node& node ) { GeometryDataCollector collector; node.accept( collector ); std::vector<PxVec3> verts; for ( unsigned int i=0; i<collector.vertices.size(); ++i ) { const osg::Vec3& v = collector.vertices[i]; verts.push_back( PxVec3(v[0], v[1], v[2]) ); } std::vector<PxU32> indices; for ( unsigned int i=0; i<collector.faces.size(); ++i ) { const GeometryDataCollector::GeometryFace& f = collector.faces[i]; indices.push_back( f.indices[0] ); indices.push_back( f.indices[1] ); indices.push_back( f.indices[2] ); } if ( !verts.size() || !indices.size() ) return NULL; return createTriangleMesh(verts, indices); }
void PhysActor_PhysX::SetAngularVelocity(vec3f velocity) { if (!impl->physActor) { LOG("Cannot set angular velocity from actor because actor ptr is null!"); return; } PxRigidBody* actor = nullptr; if (impl->physActor->isRigidDynamic() || impl->physActor->isRigidBody()) actor = (PxRigidBody*)impl->physActor; else { LOG("Cannot set angular velocity from actor because actor is not a Rigid Dynamic or Rigid Body actor."); return; } if (!actor) return; actor->setAngularVelocity(PxVec3(velocity.x, velocity.y, velocity.z)); }
void collideWithSphereNonContinuous(PxsParticleCollData& collData, const PxVec3& pos, const PxReal& radius, const PxReal& proxRadius) { if(collData.localFlags & PXS_FLUID_COLL_FLAG_CC) return; // Only apply discrete and proximity collisions if no continuous collisions was detected so far (for any colliding shape) PxReal dist = pos.magnitude(); collData.localSurfaceNormal = pos; if(dist < (radius + proxRadius)) { if (dist != 0.0f) collData.localSurfaceNormal *= (1.0f / dist); else collData.localSurfaceNormal = PxVec3(0); // Push particle to surface such that the distance to the surface is equal to the collision radius collData.localSurfacePos = collData.localSurfaceNormal * (radius + collData.restOffset); collData.localFlags |= PXS_FLUID_COLL_FLAG_L_PROX; if(dist < (radius + collData.restOffset)) collData.localFlags |= PXS_FLUID_COLL_FLAG_L_DC; } }
// Experiment specific functions called from ARSS.cpp void CreateExperiment() { // All experiments are in lab setup, give the lab gravity gPhysX.mScene->setGravity(PxVec3(0,-labscale::units.littleG,0)); // Now dispatch to specific setup switch (labscale::eExperimentType) { case labscale::eHOLSAPPLE1: if (labscale::eExperimentSubtype==labscale::eFILL_BOX) labscale::CreateFillBoxExperiment(); else if (labscale::eExperimentSubtype==labscale::ePENETRATOR) labscale::CreatePenetratorExperiment(); else if (labscale::eExperimentSubtype==labscale::eTILT_BOX) labscale::CreateTiltBoxExperiment(); else ncc__error("Unknown experiment type. Experiment aborted.\a"); break; case labscale::eBAD_EXPERIMENT_TYPE: // intentional fall through! default: ncc__error("Unknown experiment type. Experiment aborted.\a"); } }
Item* Item::Init(OPphysXScene* scene, const OPchar* modelAsset, const OPchar* textureAsset, OPrendererEntity* sceneEntity) { elapsed = 0; holdTime = 500; upTime = 250; downTime = 750; raisedHeight = 1.0; offsetY = 0;// -raisedHeight; offsetYPrev = 0;// -raisedHeight; activated = false; activateBy = NULL; player = NULL; physics.entity.entityType = ITEM; physics.entity.ptr = this; physics.entity.rendererEntity = sceneEntity; physics.physX = OPphysXSceneCreateDynamic(scene, physics.entity.transform.position); OPphysXMaterial* material = OPphysXCreateMaterial(0.6, 0.6, 0.0); f32 size = 0.125; physics.shapes = OPphysXAddBoxShape(physics.physX, material, OPvec3Create(size)); //physics.shapes->setLocalPose(PxTransform(PxVec3(0, 0.5, 0))); physics.physX->setMassSpaceInertiaTensor(PxVec3(0.0f, 1.0f, 0.0f)); OPphysXSceneAddActor(scene, physics.physX); physics.shapes->userData = &physics.entity; physics.physX->setMass(500.f); interactionShape = OPphysXAddBoxShape(physics.physX, material, OPvec3Create(0.35)); OPphysXSetSimulation(interactionShape, 0); OPphysXSetTrigger(interactionShape, 1); interactionShape->userData = &physics.entity; return this; }
PxConvexMesh* createConvexMesh( osg::Node& node, PxConvexFlags flags ) { GeometryDataCollector collector; node.accept( collector ); std::vector<PxVec3> verts; for ( unsigned int i=0; i<collector.vertices.size(); ++i ) { const osg::Vec3& v = collector.vertices[i]; verts.push_back( PxVec3(v[0], v[1], v[2]) ); } std::vector<PxU32> indices; for ( unsigned int i=0; i<collector.faces.size(); ++i ) { const GeometryDataCollector::GeometryFace& f = collector.faces[i]; indices.push_back( f.indices[0] ); indices.push_back( f.indices[1] ); indices.push_back( f.indices[2] ); } if ( !verts.size() || !indices.size() ) return NULL; PxConvexMeshDesc convexDesc; convexDesc.points.count = verts.size(); convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = &(verts[0]); convexDesc.triangles.count = indices.size() / 3; convexDesc.triangles.stride = 3 * sizeof(PxU32); convexDesc.triangles.data = &(indices[0]); convexDesc.flags = flags; MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookConvexMesh(convexDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createConvexMesh( readBuffer ); }
PxU32 PrismaticJointSolverPrep(Px1DConstraint* constraints, PxVec3& body0WorldOffset, PxU32 maxConstraints, PxConstraintInvMassScale &invMassScale, const void* constantBlock, const PxTransform& bA2w, const PxTransform& bB2w) { PX_UNUSED(maxConstraints); const PrismaticJointData& data = *reinterpret_cast<const PrismaticJointData*>(constantBlock); invMassScale = data.invMassScale; PxTransform cA2w = bA2w.transform(data.c2b[0]); PxTransform cB2w = bB2w.transform(data.c2b[1]); bool limitEnabled = data.jointFlags & PxPrismaticJointFlag::eLIMIT_ENABLED; const PxJointLinearLimitPair &limit = data.limit; bool limitIsLocked = limitEnabled && limit.lower >= limit.upper; PxVec3 bOriginInA = cA2w.transformInv(cB2w.p); body0WorldOffset = cB2w.p-bA2w.p; joint::ConstraintHelper ch(constraints,cB2w.p-bA2w.p, cB2w.p-bB2w.p); ch.prepareLockedAxes(cA2w.q, cB2w.q, bOriginInA, limitIsLocked ? (PxU32)7 : 6, 7); if(limitEnabled && !limitIsLocked) { PxVec3 axis = cA2w.rotate(PxVec3(1.f,0,0)); PxReal ordinate = bOriginInA.x; ch.linearLimit(axis, ordinate, limit.upper, limit); ch.linearLimit(-axis, -ordinate, -limit.lower, limit); } return ch.getCount(); }
PxConvexMesh* createPrismConvexMesh(const PxF32 baseLength, const PxF32 baseDepth, const PxF32 height, PxPhysics& physics, PxCooking& cooking) { const PxF32 x=baseLength*0.5f; const PxF32 z=baseDepth*0.5f; PxVec3 verts[6]= { PxVec3(-x, 0, -z), PxVec3(-x, 0, +z), PxVec3(+x, 0, -z), PxVec3(+x, 0, +z), PxVec3(-x, height, 0), PxVec3(+x, height, 0), }; PxU32 numVerts=6; return createConvexMesh(verts,numVerts,physics,cooking); }