void PhysicsLib::addFluidContainmentPlane(float height) { if(!data->scene) return; assert(data->scene->isWritable()); assert(data->physicslib_fluid_containment_actor == NULL); NxPlaneShapeDesc planeDesc; planeDesc.d = -height; planeDesc.normal.set(NxReal(0.0),NxReal(-1.0),NxReal(0.0)); NxActorDesc actorDesc; actorDesc.shapes.pushBack(&planeDesc); data->physicslib_fluid_containment_actor = data->scene->createActor(actorDesc); if(data->physicslib_fluid_containment_actor) { data->physicslib_fluid_containment_actor->setGroup(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES); NxShape *const*shapes = data->physicslib_fluid_containment_actor->getShapes(); if(shapes && shapes[0]) { shapes[0]->setGroup(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES); data->physicslib_fluid_containment_shape = shapes[0]->isPlane(); } } }
bool Controller::setPos(const NxExtendedVec3& pos) { position = filteredPosition = exposedPosition = pos; memory = pos[upDirection]; // Update kinematic actor if(kineActor) kineActor->moveGlobalPosition(NxVec3(NxReal(position.x), NxReal(position.y), NxReal(position.z))); // LOSS OF ACCURACY return true; }
void PhysicsLib::addSkyPlane(float height) { if(!data->scene) return; NxPlaneShapeDesc planeDesc; planeDesc.d = -height; planeDesc.normal.set(NxReal(0.0),NxReal(-1.0),NxReal(0.0)); NxActorDesc actorDesc; actorDesc.shapes.pushBack(&planeDesc); data->scene->createActor(actorDesc); }
Vec2 Box2::getCenter() const { Vec2 center; center.add(min,max); center *= NxReal(0.5); return center; }
ParticleEmitter::ParticleEmitter(NxScene*& pSceneToSet, NxVec3 vStartingPos, NxReal& fStartingVelScale, NxVec3 vThermoDynamicAcceleration) { _iHeadIndex = 0; _iTailIndex = 0; _iParticleCount = 0; _pScene = pSceneToSet; _vStartingPos = vStartingPos; _fStartingVelScale = (1.0f / NxReal(RAND_MAX)) * fStartingVelScale; _fNewParticleTimer = 0.0f; _vThermoDynamicAcceleration = vThermoDynamicAcceleration; }
void DrawPlane(NxShape* plane) { NxPlaneShape* planeShape = plane->isPlane(); NxPlane p = planeShape->getPlane(); NxVec3 n=p.normal; n.normalize(); NxVec3 t1; NxVec3 t2; static const NxReal cos45 = 0.7071067811865475244008443621048490; if (fabs(n.z) > cos45) { NxReal a = n.y*n.y + n.z*n.z; NxReal k = NxReal(1.0)/NxMath::sqrt(a); t1.set(0,-n.z*k,n.y*k); t2.set(a*k,-n.x*t1.z,n.x*t1.y); } else { NxReal a = n.x*n.x + n.y*n.y; NxReal k = NxReal(1.0)/NxMath::sqrt(a); t1.set(-n.y*k,n.x*k,0); t2.set(-n.z*t1.y,n.z*t1.x,a*k); } NxMat34 pose; pose.M.setColumn(0, t2); pose.M.setColumn(1, n); pose.M.setColumn(2, t1); // We can't use this cause someone decided it was a good idea to support two plane representations // pose.t=p.pointInPlane(); pose.t = n * p.d; glPushMatrix(); glDisable(GL_LIGHTING); glColor4f(0.1f, 0.2f, 0.3f, 1.0f); SetupGLMatrix(pose.t, pose.M); glTranslatef(0,-0.1f,0); glScalef(1024,1,1024); RenderPlane(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_LIGHTING); glPopMatrix(); }
void ParticleEmitter::addParticle() { if ((_iTailIndex == _iHeadIndex) && (_iParticleCount != 0)) // FIFO is full { removeParticle(); // Now there is a slot free } // Add a single-shape actor to the scene NxActorDesc actorDesc; NxBodyDesc bodyDesc; NxSphereShapeDesc sphereDesc; sphereDesc.radius = 1.0f; sphereDesc.group = cParticleCollisionGroup; // this group does not collide with itself actorDesc.shapes.pushBack(&sphereDesc); actorDesc.body = &bodyDesc; actorDesc.density = 10.0f; actorDesc.globalPose.t = _vStartingPos; NxActor* pNewActor = _pScene->createActor(actorDesc); // Give it an initial linear velocity, scaled by _fStartingVelScale NxVec3 vRandVec(NxReal(rand()*_fStartingVelScale), NxReal(rand()*_fStartingVelScale), NxReal(rand()*_fStartingVelScale)); pNewActor->setLinearVelocity(vRandVec); // Turn off gravity for smoke pNewActor->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); _aParticleArray[_iHeadIndex] = new Particle(pNewActor, _vThermoDynamicAcceleration); _iHeadIndex = (_iHeadIndex+1) % ciMaxParticles; ++_iParticleCount; }