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);
}












