//-----------------------------------------------------------------------
		void PhysXActorExtern::_processParticle(
			ParticleTechnique* particleTechnique, 
			Particle* particle, 
			Ogre::Real timeElapsed, 
			bool firstParticle)
		{
			// Only update after a PhysX simulation step
			if (mSynchronize)
			{
				if (particle->particleType != Particle::PT_VISUAL)
					return;

				if (!particle->physicsActor)
					return;

				VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
				PhysXActor* physXActor = static_cast<PhysXActor*>(particle->physicsActor);
				NxActor* nxActor = physXActor->nxActor;
				if (nxActor)
				{
					// Synchronize both the particle and the pysicsActor with the nxActor
					particle->position = PhysXMath::convert(nxActor->getGlobalPosition());
					particle->direction = PhysXMath::convert(nxActor->getLinearVelocity());
					visualParticle->orientation = PhysXMath::convert(nxActor->getGlobalOrientationQuat());
					physXActor->position = particle->position;
					physXActor->direction = particle->direction;
					physXActor->orientation = visualParticle->orientation;

					if (nxActor->getNbShapes())
					{
						NxShape *shape = nxActor->getShapes()[0]; // Max one.
						switch(shape->getType())
						{
							case NX_SHAPE_BOX:
								(static_cast<NxBoxShape*>(shape))->setDimensions(
									PhysXMath::convert(0.5 * Ogre::Vector3(
									visualParticle->width, visualParticle->height, visualParticle->depth)));
							break;
							 case NX_SHAPE_SPHERE:
								(static_cast<NxSphereShape*>(shape))->setRadius(0.5f * visualParticle->width);
							break;
							case NX_SHAPE_CAPSULE:
							{
								(static_cast<NxCapsuleShape*>(shape))->setRadius(0.5f * visualParticle->width);
								(static_cast<NxCapsuleShape*>(shape))->setHeight(0.5f * visualParticle->height);
							}
							break;
						}
					}
				}
			}
		}
Esempio n. 2
0
void PhysicsLib::updateVisualization(const VC3 &cameraPosition, float range, bool forceUpdate)
{
	bool visualizeCollisionShapes = data->featureMap[PhysicsLib::VISUALIZE_COLLISION_SHAPES];
	bool visualizeDynamic = data->featureMap[PhysicsLib::VISUALIZE_DYNAMIC];
	bool visualizeStatic = data->featureMap[PhysicsLib::VISUALIZE_STATIC];
	bool visualizeCollisionContacts = data->featureMap[PhysicsLib::VISUALIZE_COLLISION_CONTACTS];
	bool visualizeFluids = data->featureMap[PhysicsLib::VISUALIZE_FLUIDS];
	bool visualizeJoints = data->featureMap[PhysicsLib::VISUALIZE_JOINTS];
	bool visualizeCCD = data->featureMap[PhysicsLib::VISUALIZE_CCD];

	if (forceUpdate
		|| visualizeCollisionShapes
		|| visualizeDynamic
		|| visualizeStatic
		|| visualizeCollisionContacts
		|| visualizeFluids
		|| visualizeJoints
		|| visualizeCCD)
	{
		// (do the update)
	} else {
		// do not unnecessarily do this stuff!
		return;
	}

	float rangeSq = range * range;

	int actorAmount = data->scene->getNbActors();
	NxActor **actorArray = data->scene->getActors();

	if(visualizeCollisionShapes || visualizeStatic || visualizeCollisionContacts)
		data->sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	else
		data->sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 0);

	if(visualizeDynamic)
		data->sdk->setParameter(NX_VISUALIZE_BODY_MASS_AXES, 1);
	else
		data->sdk->setParameter(NX_VISUALIZE_BODY_MASS_AXES, 0);

	data->sdk->setParameter(NX_VISUALIZE_CONTACT_NORMAL, visualizeCollisionContacts);
	data->sdk->setParameter(NX_VISUALIZE_CONTACT_FORCE, visualizeCollisionContacts);
	data->sdk->setParameter(NX_VISUALIZE_CONTACT_POINT, visualizeCollisionContacts);

	data->sdk->setParameter(NX_VISUALIZE_COLLISION_SKELETONS, visualizeCCD);	

	for(int i = 0; i < actorAmount; ++i)
	{
		NxActor *actor = actorArray[i];
		if(!actor)
			continue;

		NxVec3 nxpos = actor->getGlobalPosition();
		VC3 pos(nxpos.x, nxpos.y, nxpos.z);
		VC3 diff = (pos - cameraPosition);
		diff.y = 0; // ignore height

		bool inRange = false;		
		if (diff.GetSquareLength() < rangeSq)
			inRange = true;

		if(actor->isDynamic())
		{
			//if(visualizeDynamic && inRange)
			if(visualizeDynamic)
				actor->raiseBodyFlag(NX_BF_VISUALIZATION);
			else
				actor->clearBodyFlag(NX_BF_VISUALIZATION);
		}

		int shapeAmount = actor->getNbShapes();
		NxShape *const*shapes = actor->getShapes();

		while(shapeAmount--)
		{
			NxShape *shape = shapes[shapeAmount];

			if(actor->isDynamic())
			{
				//if(visualizeCollisionShapes && inRange)
				if(visualizeCollisionShapes)
					shape->setFlag(NX_SF_VISUALIZATION, true);
				else
					shape->setFlag(NX_SF_VISUALIZATION, false);
			}
			else
			{
				if(visualizeStatic && !shape->isHeightField() && inRange)
					shape->setFlag(NX_SF_VISUALIZATION, true);
				else
					shape->setFlag(NX_SF_VISUALIZATION, false);
			}
		}
	}
}
		//-----------------------------------------------------------------------
		PhysicsActor* PhysXActorExtern::createPhysicsActor(PhysicsActorDesc* physicsActorDesc, PhysicsShapeDesc* physicsShapeDesc)
		{
			if (!PhysXBridge::getSingletonPtr()->getScene() || !physicsActorDesc || !physicsShapeDesc)
				return 0;

			NxBodyDesc bodyDesc;
			bodyDesc.setToDefault();
			NxReal angularDamping = bodyDesc.angularDamping;
			NxVec3 angularVelocity = bodyDesc.angularVelocity;
			NxVec3 linearVelocity = bodyDesc.linearVelocity;
			bodyDesc.angularDamping = physicsShapeDesc->mAngularDamping;
			bodyDesc.angularVelocity = PhysXMath::convert(physicsShapeDesc->mAngularVelocity);
			bodyDesc.linearVelocity = PhysXMath::convert(physicsActorDesc->direction);

			NxActorDesc actorDesc;
			NxActorDesc defaultActorDesc;
			actorDesc.setToDefault();
			defaultActorDesc.setToDefault();
			switch (physicsShapeDesc->mPhysicsShapeType)
			{
				case ST_BOX:
				{
					PhysicsBoxDesc* physicsBoxDesc = static_cast<PhysicsBoxDesc*>(physicsShapeDesc);
					NxBoxShapeDesc boxDesc;
					boxDesc.setToDefault();
					boxDesc.dimensions = PhysXMath::convert(physicsBoxDesc->mDimensions);
					boxDesc.group = physicsBoxDesc->mCollisionGroup;
					boxDesc.groupsMask = PhysXMath::convert(physicsBoxDesc->mGroupMask);
					boxDesc.materialIndex = physicsBoxDesc->mMaterialIndex;
					actorDesc.density = NxComputeBoxDensity(2 * boxDesc.dimensions, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&boxDesc);
				}
				break;

				case ST_SPHERE:
				{
					PhysicsSphereDesc* physicsSphereDesc = static_cast<PhysicsSphereDesc*>(physicsShapeDesc);
					NxSphereShapeDesc sphereDec;
					sphereDec.setToDefault();
					sphereDec.radius = physicsSphereDesc->mRadius;
					sphereDec.group = physicsSphereDesc->mCollisionGroup;
					sphereDec.groupsMask = PhysXMath::convert(physicsSphereDesc->mGroupMask);
					sphereDec.materialIndex = physicsSphereDesc->mMaterialIndex;
					actorDesc.density = NxComputeSphereDensity(sphereDec.radius, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&sphereDec);
				}
				break;

				case ST_CAPSULE:
				{
					PhysicsCapsuleDesc* physicsCapsuleDesc = static_cast<PhysicsCapsuleDesc*>(physicsShapeDesc);
					NxCapsuleShapeDesc capsuleDec;
					capsuleDec.setToDefault();
					capsuleDec.radius = physicsCapsuleDesc->mRadius;
					capsuleDec.height = physicsCapsuleDesc->mHeight;
					capsuleDec.group = physicsCapsuleDesc->mCollisionGroup;
					capsuleDec.groupsMask = PhysXMath::convert(physicsCapsuleDesc->mGroupMask);
					capsuleDec.materialIndex = physicsCapsuleDesc->mMaterialIndex;
					actorDesc.density = NxComputeCylinderDensity(capsuleDec.radius, capsuleDec.height, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&capsuleDec);
				}
				break;
			}
			actorDesc.globalPose.t = PhysXMath::convert(physicsActorDesc->position);
			actorDesc.body = &bodyDesc;
			actorDesc.group = physicsActorDesc->collisionGroup;
			PhysXActor* physXActor = 0;
			if (!actorDesc.isValid())
			{
				actorDesc = defaultActorDesc;
				Ogre::LogManager::getSingleton().logMessage("ParticleUniverse PhysXActor: Cannot create actor; use default attributes.");
			}
			NxActor* nxActor = PhysXBridge::getSingletonPtr()->getScene()->createActor(actorDesc);

			if (nxActor)
			{
				physXActor = OGRE_NEW_T(PhysXActor, Ogre::MEMCATEGORY_SCENE_OBJECTS)();
				physXActor->position = PhysXMath::convert(nxActor->getGlobalPosition());
				physXActor->direction = PhysXMath::convert(nxActor->getLinearVelocity());
				nxActor->setGlobalOrientationQuat(PhysXMath::convert(physicsActorDesc->orientation));
				physXActor->orientation = physicsActorDesc->orientation;
				physXActor->mass = nxActor->getMass();
				physXActor->collisionGroup = nxActor->getGroup();
				physXActor->nxActor = nxActor;
			}
			return physXActor;
		}
Esempio n. 4
0
void NxRobot::cloneRobot(int indexNewScene, int indexNewRobot, NxVec3 newPosition, int indexNewTeam)
{
    NxRobot* nxRobotSource = Simulation::gScenes[this->indexScene]->allRobots->getRobotByIdByTeam(this->id, this->idTeam);

    NxActor* robotActor = Simulation::cloneActor(nxRobotSource->getActor(),indexNewScene);
    //NxBounds3 bodyBounds;
    //robotShapes[0]->getWorldBounds(bodyBounds);

    NxVehicleDesc vehicleDesc;

    vehicleDesc.position				= NxVec3(robotActor->getGlobalPosition());
    vehicleDesc.mass					= robotActor->getMass();
    //vehicleDesc.motorForce				= 70000;
    //vehicleDesc.maxVelocity				= 300.f;
    //vehicleDesc.cameraDistance			= 8.0f;
    vehicleDesc.centerOfMass.set(robotActor->getCMassLocalPosition());
    //vehicleDesc.differentialRatio = 3.42f;
    //vehicleDesc.transmissionEfficiency
    vehicleDesc.actor = robotActor;

    //Motor descricao
    //NxVehicleMotorDesc motorsDesc[4];
    //for(NxU32 i=0;i<4;i++)
    //{
    //motorsDesc[i].setToCorvette();
    //vehicleDesc.motorsDesc.push_back(&motorsDesc[i]);
    //}

    //Roda (Wheel) descricao
    int numberWheels = nxRobotSource->getNbWheels();
    NxWheelDesc* wheelDesc = new NxWheelDesc[numberWheels];
    for(NxU32 i=0; i<numberWheels; i++)
    {
        //NxActor* wheelModel = Simulation::getActorWheel(indexSourceScene,indexNewRobot,i);
        //NxActorDesc wheelActorDesc;
        //wheelModel->saveToDesc(wheelActorDesc);
        //Simulation::gScenes[0]->releaseActor(*wheelModel);

        //NxShape*const* wheelShapes = actorWheel->getShapes();
        //NxBounds3 wheelBounds;
        //wheelShapes[0]->getWorldBounds(wheelBounds);

        const NxWheel* wheel = nxRobotSource->getWheel(i);
        NxWheelShape* wheelShape = ((NxWheel2*)wheel)->getWheelShape();
        //wheelDesc[i].wheelApproximation = 10;
        wheelDesc[i].wheelOrientation = wheelShape->getGlobalOrientation();
        wheelDesc[i].position.set(wheelShape->getGlobalPosition()-robotActor->getGlobalPosition());
        //wheelDesc[i].position.z = 0;
        wheelDesc[i].id = i;
        wheelDesc[i].wheelFlags = ((NxWheel*)wheel)->getWheelFlags();
        wheelDesc[i].wheelRadius = wheel->getRadius();
        //wheelDesc[i].wheelWidth = 100;
        wheelDesc[i].wheelSuspension = wheelShape->getSuspensionTravel();
        wheelDesc[i].springRestitution = 0;
        wheelDesc[i].springDamping = 0;
        wheelDesc[i].springBias = 0.0f;
        wheelDesc[i].maxBrakeForce = 100;
        wheelDesc[i].frictionToFront = 0.1f;//0.1f;
        wheelDesc[i].frictionToSide = 0;//0.02f;//
        wheelDesc[i].inverseWheelMass = wheelShape->getInverseWheelMass(); //TODO: CONFIGURAR PARÂMETRO

        //Angulo das Rodas (Omni)
        wheelDesc[i].angWheelRelRobot = ((NxWheel2*)wheel)->angWheelRelRobot;

        vehicleDesc.robotWheels.pushBack(&wheelDesc[i]);
    }

    //Criar robot, vehicle base
    NxRobot* robot = (NxRobot*)NxRobot::createVehicle(Simulation::gScenes[indexNewScene], &vehicleDesc);
    //NxRobot* robot = (NxRobot*)NxRobot::createVehicle(gScenes[indexSourceScene], &vehicleDesc);
    robot->setId(indexNewRobot);
    robot->setIdTeam(indexNewTeam);
    robot->indexScene = indexNewScene;
    robot->bodyRadius = nxRobotSource->bodyRadius;

    //Dribbler and Kicker
    NxShape*const* robotShapes = robotActor->getShapes();
    for(int i=0; i<robotActor->getNbShapes(); i++) {
        const char* shapeName = robotShapes[i]->getName();
        if(shapeName) {
            char* dribblerName = new char[10];//"Driblador\0"
            dribblerName[9] = 0;
            memcpy(dribblerName, shapeName, strlen(dribblerName));

            if(strcmp(dribblerName, "Driblador") == 0) {
                robot->dribbler->dribblerShapes.push_back(robotShapes[i]);
            }
            delete dribblerName;
        }
    }
    robot->kicker->kickerShapeDesc = new NxBoxShapeDesc();
    NxShapeDesc* shapeDesc = nxRobotSource->kicker->kickerShapeDesc;
    robot->kicker->kickerShapeDesc->localPose = shapeDesc->localPose;
    ((NxBoxShapeDesc*)(robot->kicker->kickerShapeDesc))->dimensions = ((NxBoxShapeDesc*)shapeDesc)->dimensions;

    //Initial Pose
    robot->setInitialPose(robotActor->getGlobalPose());

    robotActor->putToSleep();

    //Transladando o robo
    robot->getActor()->setGlobalPosition(newPosition);

    string label;
    string plabel = "Robo";
    stringstream out;
    out << indexNewRobot;
    out << "-";
    out << indexNewTeam;
    //out << "-";
    //out << indexNewScene;
    label.append(plabel);
    label.append(out.str());
    char* arrayLabel = new char[label.size()+1];
    arrayLabel[label.size()]=0;
    memcpy(arrayLabel, label.c_str(), label.size());
    robotActor->setName(arrayLabel);
    //delete arrayLabel;
}
Esempio n. 5
0
void Simulation::buildModelRobot(int indexRobot, int indexScene, int indexTeam)
{
    //Veiculo descricao
    //Body Descricao
    NxActor* robotActor = Simulation::getActorRobot(indexScene, indexRobot);
    //NxBounds3 bodyBounds;
    //robotShapes[0]->getWorldBounds(bodyBounds);
    NxVehicleDesc vehicleDesc;

    vehicleDesc.position				= NxVec3(robotActor->getGlobalPosition());
    float mass = 5.;
    vehicleDesc.mass					= mass;//robotActor->getMass(); //PLUGIN TAH COM PROBLEMA XML ERRADO
    //vehicleDesc.motorForce				= 70000;
    //vehicleDesc.maxVelocity				= 300.f;
    //vehicleDesc.cameraDistance			= 8.0f;
    vehicleDesc.centerOfMass.set(NxVec3(0,0,0));//robotActor->getCMassLocalPosition());
    //vehicleDesc.differentialRatio = 3.42f;
    //vehicleDesc.transmissionEfficiency
    vehicleDesc.actor = robotActor;
    vehicleDesc.actor->setMaxAngularVelocity(6.2);
    vehicleDesc.actor->setMass(mass);

    //TODO: LEVANTAR DAMPING
    float t = vehicleDesc.actor->getLinearDamping();
    float b = vehicleDesc.actor->getAngularDamping();
    //vehicleDesc.actor->setAngularDamping(0.5);
    //vehicleDesc.actor->setLinearDamping(0.5);

    //TODO: LEVANTAR CMASS E INERTIA TENSOR

    //vehicleDesc.actor->setCMassOffsetGlobalPosition(NxVec3(0, 0, 0));
    NxMat33 inertiaTensor = NxMat33(NxVec3(1294.4362, 3.14502, -66.954), NxVec3(3.14502, 1094.42351, -0.24279), NxVec3(-66.954, -0.24279, 1754.80511));
    vehicleDesc.actor->setCMassOffsetLocalPose( NxMat34( inertiaTensor, NxVec3(0,0,0) ) );
    //TODO: Diagonalizar inertiaTensor e passar para setMassSpaceInertiaTensor
    vehicleDesc.actor->setMassSpaceInertiaTensor(/*vehicleDesc.actor->getMassSpaceInertiaTensor()*1000.*/NxVec3(1764.3, 1284.9, 1094.4) );

    //Motor descricao
    //NxVehicleMotorDesc motorsDesc[4];
    //for(NxU32 i=0;i<4;i++)
    //{
    //motorsDesc[i].setToCorvette();
    //vehicleDesc.motorsDesc.push_back(&motorsDesc[i]);
    //}

    //Roda (Wheel) descricao
    int numberWheels = Simulation::getNumberWheels(indexScene, indexRobot);
    NxWheelDesc* wheelDesc = new NxWheelDesc[numberWheels];
    for(NxU32 i=0; i<numberWheels; i++)
    {
        //NxActor* wheelModel = Simulation::getActorWheel(indexScene,indexRobot,i);
        //NxActorDesc wheelActorDesc;
        //wheelModel->saveToDesc(wheelActorDesc);
        //Simulation::gScenes[0]->releaseActor(*wheelModel);
        NxActor* actorWheel = Simulation::getActorWheel(indexScene,indexRobot,i);//wheelModel;//Simulation::gScenes[0]->createActor(wheelActorDesc);
        //NxShape*const* wheelShapes = actorWheel->getShapes();
        //NxBounds3 wheelBounds;
        //wheelShapes[0]->getWorldBounds(wheelBounds);

        //Para exportar modelo da roda do 3ds Max
        //	NxWhee
        //wheelDesc[i]
        //robot1Shapes[0]->isConvexMesh()->getConvexMesh().saveToDesc(convexMesh);
        //NxWheelShape* wheelShape = (NxWheelShape*)wheel;
        //NxTriangleMeshDesc meshDesc = *((NxTriangleMeshDesc*)(mesh->userData));
        //robot1Shapes[0]->isWheel()->

        //wheelDesc[i].wheelApproximation = 10;

        wheelDesc[i].wheelOrientation = actorWheel->getGlobalOrientation();
        wheelDesc[i].position.set(actorWheel->getGlobalPosition()-robotActor->getGlobalPosition());
        //wheelDesc[i].position.z = 0;
        wheelDesc[i].id = i;
        wheelDesc[i].wheelRadius = 27.6;
        //wheelDesc[i].wheelWidth = 100;
        wheelDesc[i].wheelSuspension = 0;
        wheelDesc[i].springRestitution = 0;
        wheelDesc[i].springDamping = 0;
        wheelDesc[i].springBias = 0.0f;
        wheelDesc[i].maxBrakeForce = 100;
        wheelDesc[i].frictionToFront = 0.1f;//0.1f;	//TODO: CONFIGURAR PARÂMETRO
        wheelDesc[i].frictionToSide = 0;//0.02f;	//TODO: CONFIGURAR PARÂMETRO
        wheelDesc[i].inverseWheelMass = 0.1;		//TODO: CONFIGURAR PARÂMETRO

        //Angulo das Rodas (Omni)
        NxVec3 wheelPosRel = actorWheel->getGlobalPosition() - robotActor->getGlobalPosition();
        wheelDesc[i].angWheelRelRobot = NxMath::atan2( wheelPosRel.y, wheelPosRel.x );

        vehicleDesc.robotWheels.pushBack(&wheelDesc[i]);
        Simulation::gScenes[indexScene]->scene->releaseActor(*actorWheel);

        //NxU32 flags = NX_WF_BUILD_LOWER_HALF;
        wheelDesc[i].wheelFlags = NX_WF_ACCELERATED | NX_WF_AFFECTED_BY_HANDBRAKE | NX_WF_USE_WHEELSHAPE | NX_WF_BUILD_LOWER_HALF;// |/*NX_WF_STEERABLE_INPUT |*/ flags;
    }

    //NxBall* teste = Simulation::gScenes[indexScene]->ball;

    //Criar robot, vehicle base
    NxRobot* robot = (NxRobot*)NxRobot::createVehicle(Simulation::gScenes[indexScene], &vehicleDesc);
    if(robot) {
        robot->setId(indexRobot);
        robot->setIdTeam(indexTeam);
        robot->indexScene = indexScene;

        //Dribbler and Kicker
        for(int i=0; i<robotActor->getNbShapes(); i++) {
            NxShape*const* robotShapes = robotActor->getShapes();
            const char* shapeName = robotShapes[i]->getName();
            if(shapeName) {
                char* dribblerName = new char[10];//"Driblador\0"
                dribblerName[9] = 0;
                memcpy(dribblerName, shapeName, strlen(dribblerName));

                char* kickerName = new char[9];//"Chutador\0"
                kickerName[8] = 0;
                memcpy(kickerName, shapeName, strlen(kickerName));

                if(strcmp(dribblerName, "Driblador") == 0) {
                    robot->dribbler->dribblerShapes.push_back(robotShapes[i]);
                }
                else if(strcmp(kickerName, "Chutador") == 0) {
                    robot->kicker->kickerShapeDesc = Simulation::copyShapeDesc(robotShapes[i]);
                    robotActor->releaseShape(*(robotShapes[i]));
                }
                delete dribblerName;
                delete kickerName;
            }
        }

        //Initial Pose
        robot->setInitialPose(robotActor->getGlobalPose());

        robotActor->putToSleep();

        //Mudar pose do robo
        //NxQuat q;
        //q.
        //q.fromAngleAxis(180.0f, NxVec3(0.0f, 1.0f, 0.0f));
        //robot->getActor()->setGlobalPose(pose);

        //Release no actor importado do 3ds Max
        //gScenes[0]->releaseActor(*robotActor);

        string label;
        string plabel = "Robo";
        stringstream out;
        out << indexRobot;
        out << "-";
        out << indexTeam;
        //out << "-";
        //out << indexScene;
        label.append(plabel);
        label.append(out.str());
        char* arrayLabel = new char[label.size()+1];
        arrayLabel[label.size()]=0;
        memcpy(arrayLabel, label.c_str(), label.size());
        robotActor->setName(arrayLabel);
        //delete arrayLabel;
    }
}
Esempio n. 6
0
void render()
{
	static Timer t;
	if(!gMyPhysX.isPaused())
	{
		for (NxU32 i = 0; i < gKinematicActors.size(); i++)
		{
			NxActor* actor = gKinematicActors[i].actor;
			NxVec3 pos = actor->getGlobalPosition();
			pos += gKinematicActors[i].vel * 1.f/60.f;
			actor->moveGlobalPosition(pos);
		}
	}	
	gMyPhysX.simulate(t.elapsed_time());
	t.reset(); 
	// Clear buffers
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glColor4f(0.5,0.9,0.5,1.0);
	DrawSkyBox(SKYEXTENTS);
	drawPlane(SKYEXTENTS);
	// Keep physics & graphics in sync
	for (NxU32 pass = 0; pass < 2; pass++) {
		int nbActors = gMyPhysX.getScene()->getNbActors();
		NxActor** actors = gMyPhysX.getScene()->getActors();
		actors += nbActors;
		while(nbActors--)
		{
			NxActor* actor = *--actors;

			float size;
			bool isTrigger = false;
			bool isKinematic = actor->isDynamic() && actor->readBodyFlag(NX_BF_KINEMATIC);
			NxVec3 color;
			NxF32 alpha = 1;
			if (actor->isDynamic()) {
				if (actor->readBodyFlag(NX_BF_KINEMATIC)) {
					color.set(1,0,0);
				} else {
					color.set(0,1,0);
				}
			} else {
				color.set(0.2f,0.2f,0.2f);
			}

			if (*(int *)(&actor->userData) < 0)
			{
				NxI32 triggerNumber = -(*(NxI32 *)(&actor->userData));
				NxI32 triggerIndex = triggerNumber - 1;
				// This is our trigger
				isTrigger = true;

				size = 10.0f;
				color.z = gNbTouchedBodies[triggerIndex] > 0.5f ? 1.0f:0.0f;
				alpha = 0.5f;
				if (pass == 0)
					continue;
			}
			else
			{
				// This is a normal object
				size = float(*(int *)(&actor->userData));
				if (pass == 1)
					continue;
			}
			float glmat[16];
			glPushMatrix();
			actor->getGlobalPose().getColumnMajor44(glmat);
			glMultMatrixf(glmat);
			glColor4f(color.x, color.y, color.z, 1.0f);
			glutSolidCube(size*2.0f);
			glPopMatrix();

			// Handle shadows
			if( !isTrigger)
			{
				glPushMatrix();

				const static float ShadowMat[]={ 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 };

				glMultMatrixf(ShadowMat);
				glMultMatrixf(glmat);

				glDisable(GL_LIGHTING);
				glColor4f(0.1f, 0.2f, 0.3f, 1.0f);
				glutSolidCube(size*2.0f);
				glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
				glEnable(GL_LIGHTING);

				glPopMatrix();
			}
		}
	}
}