Esempio n. 1
0
//################################################################
//
// Body functions
//
pRigidBody*PhysicManager::getBody(const char*name,int flags/* =0 */)
{

	for (pWorldMapIt it  = getWorlds()->Begin(); it!=getWorlds()->End(); it++)
	{
		pWorld *w = *it;
		if(w)
		{
			int nbActors = w->getScene()->getNbActors();
			NxActor** actors = w->getScene()->getActors();
			while(nbActors--)
			{
				NxActor* actor = *actors++;
				if(actor->userData != NULL)
				{
					if (!strcmp(actor->getName(),name) )
					{

						pRigidBody* body =static_cast<pRigidBody*>(actor->userData);
						if (body)
						{
							return body;
						}
					}
				}
			}
		}
	}
	return 0;
}
Esempio n. 2
0
void GravitateToGravitators()
{
	NxU32 nbActors = gScene->getNbActors();
	NxActor** actors = gScene->getActors();
	NxReal m1,m2,G=gUniversalBigG,R;
	NxVec3 r,F;
	while (nbActors--)
	{
		NxActor* actor = *actors++;
		const char* name=actor->getName();
		if (strcmp(name,"~lander")==0)
		{
			F.zero();
			m1=actor->getMass();
			for (int k=0; k<gRavitators.size(); k++)
			{
				r = (gRavitators[k]->getCMassGlobalPosition() - actor->getCMassGlobalPosition());
				R = r.magnitudeSquared();
				m2= gRavitators[k]->getMass();
				F = r;
				F.setMagnitude(G*m1*m2/R);
				actor->addForce(F);
			}
		}
	}
}
Esempio n. 3
0
void DrawLanders()
{
	// draw the landers in 2 colors
	NxU32 nbActors = gScene->getNbActors();
	NxActor** actors = gScene->getActors();
	while (nbActors--)
	{
		NxActor* actor = *actors++;
		const char *name=actor->getName();
		if (strcmp(name,"~lander")==0) {
			NxShape*const* shapes;
			shapes = actor->getShapes();
			NxU32 nShapes = actor->getNbShapes();
			//glDisable(GL_LIGHTING);
			char sname[256]="";
			while (nShapes--)
			{
				sprintf(sname,"%s",shapes[nShapes]->getName());
				if      (strcmp(sname,"upside")==0)
					glColor4f(0.0f,1.0f,0.0f,1.0f);
				else if (strcmp(sname,"downside")==0)
					glColor4f(1.0f,0.0f,0.0f,1.0f);
				else if (strcmp(sname,"U1")==0)
					glColor4f(1.0f,0.0f,0.0f,1.0f);
				else if (strcmp(sname,"U2")==0)
					glColor4f(0.0f,1.0f,0.0f,1.0f);
				else if (strcmp(sname,"U3")==0)
					glColor4f(0.0f,0.0f,1.0f,1.0f);
				DrawShape(shapes[nShapes], false);
			}
			//glEnable(GL_LIGHTING);
		}
	}
}
Esempio n. 4
0
void myTrigger::onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status){

	if ( ! triggerShape.getActor().userData && ! otherShape.getActor().userData )
	{
		return;
	}
	
	if (status & NX_TRIGGER_ON_ENTER)
	{
		// A body just entered the trigger area
		NxActor* triggerActor = &triggerShape.getActor();
		String name = triggerActor->getName();
		int thisTarget = StringConverter::parseInt(name);
		creditTarget(thisTarget);
	}
	
}
Esempio n. 5
0
	SoftBone(const NXU::NxuBone &b,unsigned int acount,NxActor **alist,SoftBone *parent)
  {
  	mParent = parent;
		mActor = 0;

		for (unsigned int i=0; i<acount; i++)
		{
			NxActor *a = alist[i];
			const char *name = a->getName();
			if ( name )
			{
				if ( strcmp(name, b.mName) == 0 )
				{
					mActor = a;
					break;
				}
			}
		}

		NxQuat q( b.mOrientation );
		mLocalTransform.M.fromQuat(q);
		mLocalTransform.t.set( b.mPosition );

		if ( mActor )
		{
			mGlobalTransform = mActor->getGlobalPose();
		}
		else
		{
			if ( mParent )
			{
  			mGlobalTransform = parent->mGlobalTransform * mLocalTransform;
			}
  		else
			{
  			mGlobalTransform = mLocalTransform;
			}
		}

		mGlobalTransform.getInverse(mComposite);
  }
Esempio n. 6
0
void ReCreateExperiment()
{
	gScene->simulate(0);
	gScene->checkResults(NX_ALL_FINISHED,true); // make sure time step is done
	
	// Re-set the crucial SDK parameters
	if (gPhysicsSDK)
	{
		gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES,0);
		gPhysicsSDK->setParameter(NX_VISUALIZE_WORLD_AXES,0);
		if (gBounceEps>0)
			gPhysicsSDK->setParameter(NX_BOUNCE_THRESHOLD,-gBounceEps);
		if (gSkinWidth>0)
			gPhysicsSDK->setParameter(NX_SKIN_WIDTH, gSkinWidth);
	}
	if (gScene)
	{
		if (bVarTimeStep)
			gScene->setTiming(gDeltaTime/4.0,4,NX_TIMESTEP_VARIABLE);
		else
			gScene->setTiming(gDeltaTime/4.0,4,NX_TIMESTEP_FIXED);
		gScene->setGravity(gDefaultGravity*bGravity);
	}

	// Next get to cleaning up the scene that was maybe loaded from file.
	if (gScene)
	{
		// Get rid of defined materials (who knows where they've been...)
		NxMaterial* mats[20]; // I hardly think we'll have more than 20
		NxU32 iter=0; // don't worry about it
		int nmats = gScene->getMaterialArray(mats,20,iter);
		while (nmats--)
		{
			gScene->releaseMaterial(*(mats[nmats]));
		}
		gCellMaterial=NULL;
		gLanderUpMaterial=NULL;
		gLanderDownMaterial=NULL;

		CreateExperimentMaterials(); // make shiny new materials

		// Now, look over all the actors, who knows where they've been. Find out then.
		NxU32 nbActors = gScene->getNbActors();
		NxActor** actors = gScene->getActors();
		while (nbActors--)
		{
			NxActor* actor = *actors++;
			const char *name=actor->getName();
			NxShape*const* shapes;
			shapes = actor->getShapes();
			NxU32 nShapes = actor->getNbShapes();

			// If it's a rubble grain, make sure it uses the default material
			if      (strcmp(name,"rubble")==0 || strcmp(name,"boulder")==0)
				while (nShapes--) shapes[nShapes]->setMaterial(0);

			// If it's a cell container, make sure it uses the cell material, and remember its pointer
			else if (strcmp(name,"left wall")==0) {
				shapes[0]->setMaterial(gCellMaterial->getMaterialIndex());
				gContainerCell[0]=actor;
			}
			else if (strcmp(name,"right wall")==0) {
				shapes[0]->setMaterial(gCellMaterial->getMaterialIndex());
				gContainerCell[1]=actor;
			}
			else if (strcmp(name,"in wall")==0) {
				shapes[0]->setMaterial(gCellMaterial->getMaterialIndex());
				gContainerCell[2]=actor;
			}
			else if (strcmp(name,"out wall")==0) {
				shapes[0]->setMaterial(gCellMaterial->getMaterialIndex());
				gContainerCell[3]=actor;
			}

			// If it's the ground plane it also uses default material
			else if (strcmp(name,"ground")==0) {
				shapes[0]->setMaterial(0);
				groundPlane=actor;
			}

			// If it's the lander, it has two shapes made of different material, but the lander will be recreated elsewhere...

			// Anything else, get rid of
			else
				gScene->releaseActor(*actor);
		
		}

		// If the container is damaged, recreate it
		for (int k=0; k<4; k++)
		{
			if (gContainerCell[k]==NULL) {
				for (int j=0; j<4; j++)
				{
					if (gContainerCell[j]) {
						gScene->releaseActor(*gContainerCell[j]);
						gContainerCell[j]=NULL;
					}
				}
				CreateContainerCell(gCellSize);
				break;
			}
		}
	}

	// OK, all clean, now create the experiment as needed.
	switch (gExperimentType) {
	case LANDER:
		gLander=CreateLander(NxVec3(0.0f,gCellSize/2,0.0f));
		IdentifyGravitators();
		if (gLander) {
			ReOrientActor(gLander);
			SpinActor(gLander,gLandingRoughness*sqrt(gCellSize*gDefaultGravity.magnitude()/(gLander->getMassSpaceInertiaTensor().magnitude())));
			LaunchActor(gLander,gLandingRoughness*sqrt(gCellSize*gDefaultGravity.magnitude()));
			gSelectedActor=gLander;
			//gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES,gLanderSize.magnitude()); // not sure why this is a problem when reading from previous xml
			isRunning=true;
		}
		else {
			printf("Error: Unable to create lander\a\n");
			isRunning=false;
		}
		break;
	case LAY_SUBSTRATE:
		{
			isRunning=true;
			break;
		}
	default:
		printf("Error: Unknown experiment type\a\n");
		isRunning=false;
		break;
	}
	if (!isManualControl){bPause=false;}
}