Jump to content


...and the physx tutorial sample doesn't compile...


  • You cannot reply to this topic
No replies to this topic

#1 chillypacman

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 05 August 2007 - 07:21 AM

I'm having a wonderful time trying to figure out how to work with triggers. I've read over the documentation and implemented a trigger system but it hasn't worked, whats worse is hwen I try to call any of its functions (like getGlobalPosition()) I get a null pointer error.

I looked at the tutorial and it doesn't compile, because NxActorDesc does not have a shapeFlags method though it's in the tutorial code for some reason. I did remove it and it worked just fine. Unfortunately my code doens't work 'just fine' (null pointer error when I try to get its position + collision callback won't work).

My code for *trying* to make it is as follows:

NxActor* PhysX::CreateTriggerBox(float x, float y, float z, float posx, float posy, float posz, LPCWSTR material)

{

	int i;

	for(i = 0; i<mat.size(); i++)

	{

		if(mat[i].name == material)

		{

			break;

		}

	}


	// Add a single-shape actor to the scene

	NxActorDesc actorDesc;

	NxBodyDesc bodyDesc;


	// The actor has one shape, a box

	NxBoxShapeDesc boxDesc;

	boxDesc.dimensions.set(x/4, y/4, z/4);


	boxDesc.materialIndex = ++i;

	boxDesc.shapeFlags |= NX_TRIGGER_ENABLE;


	MyObject* Object = new MyObject;

	Object->size			= 1;

	Object->nbTouched		= 0;


	actorDesc.body = &bodyDesc;

	actorDesc.density = 1;

	actorDesc.userData = Object;

	actorDesc.shapes.pushBack(&boxDesc);


	actorDesc.globalPose.t = NxVec3(posx, posy, posz);


	return gScene->createActor(actorDesc);

}

also for the callback/physx initialization:

struct MyObject

{

	int		size;

	NxU32	nbTouched;

	LPCWSTR collision;

};


class SensorReport : public NxUserTriggerReport

{

	virtual void onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status)

	{

		NX_ASSERT(triggerShape.getFlag(NX_TRIGGER_ENABLE));

		if(status & NX_TRIGGER_ON_ENTER)

		{

			NxActor& actor = otherShape.getActor();

			if(actor.userData)

			{

				NxActor& triggerActor = triggerShape.getActor();

				if(triggerActor.isDynamic() && triggerActor.userData != NULL)

				{

					MyObject* Object = (MyObject*)triggerActor.userData;

					Object->nbTouched++;

				}

			}

		}

		if(status & NX_TRIGGER_ON_LEAVE)

		{

			NxActor& actor = otherShape.getActor();

			if(actor.userData)

			{

				NxActor& triggerActor = triggerShape.getActor();

				if(triggerActor.isDynamic() && triggerActor.userData != NULL)

				{

					MyObject* Object = (MyObject*)triggerActor.userData;

					Object->nbTouched--;

				}

			}

		}

	}

}gMySensorReport;


PhysX::PhysX(float x, float y, float z)	

{

	gCooking = NxGetCookingLib(NX_PHYSICS_SDK_VERSION);

	materialIndex = 1; //set to one for now, should change to 0 after debugging

	if(!gCooking)

		::MessageBox(0, L"gCooking Failed", 0, 0);


	gPhysicsSDK = NULL;

	gScene = NULL;

	NxVec3 gDefaultGravity(x, y, z);


	// Create the physics SDK

	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);

	if (!gPhysicsSDK)  

	{

		::MessageBox(0, L"gPhysicsSDK Failed", 0, 0);

		return;

	}


	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.001);


	//Debug stuff

	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);

	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);

	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);


	// Create the scene

	NxSceneDesc sceneDesc;

	sceneDesc.gravity			= gDefaultGravity;

	sceneDesc.simType			= NX_SIMULATION_SW;

	sceneDesc.userTriggerReport		= &gMySensorReport;


	gScene = gPhysicsSDK->createScene(sceneDesc);



	defaultMaterial = gScene->getMaterialFromIndex(0);

	defaultMaterial->setRestitution(0.0);

	defaultMaterial->setStaticFriction(0.5);

	defaultMaterial->setDynamicFriction(0.5);

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users