Actor pair filter problem

tomneo2000

23-09-2009 17:54:52

My actor pair filter not working

There are some bodies in the scene, a mountain, a stair, a church, a robot, 10 barrels and a plane. If user press space will fire a robot.
I want robot not collide with barrel, so i use actor pair filter, but it still has collision.

I set the flag for robot and barrel but not others.

Can someone help me?


#include "ExampleApplication.h"


#include <NxOgre.h>
#include <NxOgreOGRE3D.h>
#include <NxPhysics.h>




class UserFilter:public NxUserActorPairFiltering
{
public:
UserFilter(){}

virtual void onActorPairs(NxActorPairFilter* filterArray, NxU32 arraySize)
{
for (NxU32 i=0; i<arraySize; i++)
{
NxActor* pAct0=filterArray[i].actor[0];
NxActor* pAct1=filterArray[i].actor[1];
const char* p0name=pAct0->getName();
const char* p1name=pAct1->getName();

if (p0name=="Robot" && p1name=="Barrel")
{
filterArray[i].filtered=true;
}
}
}
};

class BloodyMessTutorial7Listener : public ExampleFrameListener
{
public:
BloodyMessTutorial7Listener(RenderWindow *win, Camera *cam, OGRE3DRenderSystem* rs, NxOgre::Mesh* barrel, NxOgre::Mesh* ro, NxOgre::VisualDebugger* vd, SceneNode* vdnode)
: ExampleFrameListener(win, cam)
{
mTimeController = NxOgre::TimeController::getSingleton();
mRenderSystem=rs;
mBarrel=barrel;
mConvexRobotMesh=ro;

mVD=vd;
mVDNode=vdnode;
mDebugMode=false;
}

bool frameStarted(const FrameEvent& evt)
{
mTimeController->advance(evt.timeSinceLastFrame);

if (mKeyboard->isKeyDown(OIS::KC_SPACE)&&mTimeUntilNextToggle<=0)
{
NxOgre::RigidBodyDescription de;
de.mMass=2;

mBarrelBody=mRenderSystem->createBody(new NxOgre::Convex(mBarrel),NxOgre::Vec3(mCamera->getPosition().x,mCamera->getPosition().y,mCamera->getPosition().z), "robotS.mesh",de);

//mBarrelBody->setGlobalOrientation(NxOgre::Matrix33(NxOgre::Vec4(0,45,45,0)));
mBarrelBody->addForce(NxOgre::Vec3(mCamera->getDirection().x*10000, mCamera->getDirection().y*10000, mCamera->getDirection().z*10000), NxOgre::Enums::ForceMode_Force, true);

mBarrelBody->getNxActor()->raiseActorFlag(NX_AF_USER_ACTOR_PAIR_FILTERING);
mBarrelBody->getNxActor()->setName("Robot");
mBarrelBody->getNxActor()->resetUserActorPairFiltering();

mTimeUntilNextToggle=0.2;
}

if (mKeyboard->isKeyDown(OIS::KC_F1)&&mTimeUntilNextToggle<=0)
{
mDebugMode=!mDebugMode;
mTimeUntilNextToggle=1;
}

if (mDebugMode)
{
mVD->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);
mVDNode->needUpdate();
mVD->draw();
}
else
{
mVD->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowNone);
mVDNode->needUpdate();
mVD->draw();
}


return ExampleFrameListener::frameStarted(evt);
}

protected:
NxOgre::TimeController* mTimeController;
OGRE3DRenderSystem* mRenderSystem;
NxOgre::Mesh* mBarrel;
NxOgre::Mesh* mConvexRobotMesh;
OGRE3DBody* mBarrelBody;
OGRE3DBody* mRobot;

NxOgre::VisualDebugger* mVD;
SceneNode* mVDNode;
bool mDebugMode;
};

class BloodyMessTutorial7 : public ExampleApplication
{
protected:
NxOgre::World* mWorld;
NxOgre::Scene* mScene;
NxOgre::TimeController* mTimeController;
OGRE3DRenderSystem* mRenderSystem;

NxOgre::Mesh* mConvexMesh;
NxOgre::Mesh* mConvexRobotMesh;
NxOgre::Mesh* mTriangleMesh;
NxOgre::Mesh* mMountan;
NxOgre::Mesh* mChurch;

OGRE3DBody* mBarrel;
OGRE3DBody* mRobot;

NxOgre::VisualDebugger* mVD;
OGRE3DRenderable* mVDRenderable;
SceneNode* mVDNode;

NxOgre::Actor* mActor;

void createScene()
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));

// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20, 80, 50);

// Position the camera
mCamera->setPosition(0, 20, 80);
mCamera->lookAt(0, 20, 0);

// Create the world
mWorld = NxOgre::World::createWorld();

// Create scene description
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0, -9.8f, 0);
sceneDesc.mName = "DemoScene";

// Create scene
mScene = mWorld->createScene(sceneDesc);

// Set some physical scene values
mScene->getMaterial(0)->setStaticFriction(0.5);
mScene->getMaterial(0)->setDynamicFriction(0.5);
mScene->getMaterial(0)->setRestitution(0.1);

// Create render system
mRenderSystem = new OGRE3DRenderSystem(mScene);

//Create time controller
mTimeController = NxOgre::TimeController::getSingleton();

// Create floor plane (BloodyMess)
mScene->createSceneGeometry(new NxOgre::PlaneGeometry(0, NxOgre::Vec3(0, 1, 0)), Matrix44_Identity);

// Create floor plane (Ogre)
MovablePlane *plane = new MovablePlane("Plane");
plane->d = 0;
plane->normal = Vector3::UNIT_Y;
Ogre::MeshManager::getSingleton().createPlane("PlaneMesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
*plane, 1200, 1200, 1, 1, true, 1, 3, 3, Vector3::UNIT_Z);
Entity *planeEnt = mSceneMgr->createEntity("PlaneEntity", "PlaneMesh");
planeEnt->setMaterialName("Examples/GrassFloor");

Ogre::SceneNode* mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlaneNode->attachObject(planeEnt);

//define resource path
NxOgre::ResourceSystem::getSingleton()->openArchive("Media","file:../../media/NxOgreMedia");

//load resource
mConvexMesh=NxOgre::MeshManager::getSingleton()->load("Media:Barrel.nxs");
mTriangleMesh=NxOgre::MeshManager::getSingleton()->load("Media:stair.nxs");
mConvexRobotMesh=NxOgre::MeshManager::getSingleton()->load("Media:robotS.nxs");
mMountan=NxOgre::MeshManager::getSingleton()->load("Media:mon.nxs");
mChurch=NxOgre::MeshManager::getSingleton()->load("Media:church.nxs");

//create geometry
NxOgre::Convex* mBarrelGeometry=new NxOgre::Convex(mConvexMesh);
NxOgre::TriangleGeometry* mStairGeometry=new NxOgre::TriangleGeometry(mTriangleMesh);
NxOgre::Convex* mRobotGeometry=new NxOgre::Convex(mConvexRobotMesh);
NxOgre::TriangleGeometry* mMountanGeometry=new NxOgre::TriangleGeometry(mMountan);
NxOgre::TriangleGeometry* mChurchGeometry=new NxOgre::TriangleGeometry(mChurch);

//setup object
static int range;
range=0;
for(int i=0; i<10; i++)
{
mBarrel=mRenderSystem->createBody(new NxOgre::Convex(mConvexMesh), NxOgre::Vec3(0+range,100+range,0), "Barrel.mesh");
mBarrel->setGlobalOrientation(NxOgre::Matrix33(NxOgre::Vec4(0,45,45,0)));

mBarrel->getNxActor()->raiseActorFlag(NX_AF_USER_ACTOR_PAIR_FILTERING);
mBarrel->getNxActor()->setName("Barrel");
mBarrel->getNxActor()->resetUserActorPairFiltering();
range+=10;
}

range=0;

//create a robot
mRobot=mRenderSystem->createBody(new NxOgre::Convex(mConvexRobotMesh), NxOgre::Vec3(50, 200, 0), "robotS.mesh");

mRobot->getNxActor()->raiseActorFlag(NX_AF_USER_ACTOR_PAIR_FILTERING);
mRobot->getNxActor()->setName("Robot");
mRobot->getNxActor()->resetUserActorPairFiltering();

//mActor=mScene->createActor(new NxOgre::Convex(mConvexRobotMesh),Matrix44_Identity);


NxScene* mNxScene=mScene->getScene();
mNxScene->setUserActorPairFiltering(new UserFilter());


//mActor=mScene->createActor(new NxOgre::Box, Matrix44_Identity);

//create stair
mScene->createSceneGeometry(new NxOgre::TriangleGeometry(mTriangleMesh), NxOgre::Matrix44(NxOgre::Vec3(0,5,0)));

Ogre::Entity* mStairEnt=mSceneMgr->createEntity("TriangleGeometry", "stair.mesh");
Ogre::SceneNode* mStairNode=mSceneMgr->getRootSceneNode()->createChildSceneNode("StairNode");
mStairNode->attachObject(mStairEnt);
mStairNode->setPosition(Ogre::Vector3(0,5,0));

//create mountan
mScene->createSceneGeometry(new NxOgre::TriangleGeometry(mMountan), NxOgre::Matrix44(NxOgre::Vec3(-300, 5, 0)));

Ogre::Entity* mount=mSceneMgr->createEntity("mount", "mon.mesh");
Ogre::SceneNode* scmount=mSceneMgr->getRootSceneNode()->createChildSceneNode("scmount");
scmount->attachObject(mount);
scmount->setPosition(Ogre::Vector3(-300, 5, 0));

//create church
NxOgre::SceneGeometry* sg=mScene->createSceneGeometry(new NxOgre::TriangleGeometry(mChurch), NxOgre::Matrix44(NxOgre::Vec3(150,1,0)));

Ogre::Entity* chu=mSceneMgr->createEntity("church", "church.mesh");
Ogre::SceneNode* chunode=mSceneMgr->getRootSceneNode()->createChildSceneNode("churchnode");
chunode->attachObject(chu);
chunode->setPosition(150, 1, 0);


//visual debug
mVD=mWorld->getVisualDebugger();
mVDRenderable=new OGRE3DRenderable(NxOgre::Enums::RenderableType_VisualDebugger);
mVD->setRenderable(mVDRenderable);
mVDNode=mSceneMgr->getRootSceneNode()->createChildSceneNode("VisualDebug");
mVDNode->attachObject(mVDRenderable);
mVD->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);

}

// Create a new frame listener
void createFrameListener()
{
mFrameListener = new BloodyMessTutorial7Listener(mWindow, mCamera, mRenderSystem, mConvexRobotMesh, mConvexRobotMesh, mVD, mVDNode);
mRoot->addFrameListener(mFrameListener);
}
};


#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
BloodyMessTutorial7 app;

try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(),
"An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occurred: " << e.getFullDescription();
#endif
}

return 0;
}

#ifdef __cplusplus
}
#endif

betajaen

23-09-2009 19:38:10

First.

Drop the PhysX crap in there. Obviously your having a hard enough time with NxOgre, throwing complicated PhysX code into there when you don't need to - is going to ruin any chances of getting anything remotely useful out of NxOgre. Drop PhysX codes, remove the headers and libraries from your project. NxOgre deals with PhysX so you don't have to. If you insist in using PhysX directly, I won't help you anymore.

Second;

There is a far far easier way to handle ignoring collisions. The easiest way for you is this;

OGRE3DBody* barrel = mRendersystem->createBody(...);
OGRE3DBody* robot = mRendersystem->createBody(...);

mScene->setActorFlags(barrel, robot, Enums::ContactPairFlags_Ignore);


If you keep a vector of barrels handy, every time you create a robot - just set the actor flags between your new robot and all the barrels in the scene to Ignore.

tomneo2000

24-09-2009 02:26:10

First.

Drop the PhysX crap in there. Obviously your having a hard enough time with NxOgre, throwing complicated PhysX code into there when you don't need to - is going to ruin any chances of getting anything remotely useful out of NxOgre. Drop PhysX codes, remove the headers and libraries from your project. NxOgre deals with PhysX so you don't have to. If you insist in using PhysX directly, I won't help you anymore.

Second;

There is a far far easier way to handle ignoring collisions. The easiest way for you is this;

OGRE3DBody* barrel = mRendersystem->createBody(...);
OGRE3DBody* robot = mRendersystem->createBody(...);

mScene->setActorFlags(barrel, robot, Enums::ContactPairFlags_Ignore);


If you keep a vector of barrels handy, every time you create a robot - just set the actor flags between your new robot and all the barrels in the scene to Ignore.


ok i drop it and use your way and it work thanks

can i write my own actor pair filter class?
is there any kind of UserData in NxOgre?

for the callback question, i have write my own class and inherit from NxOgre::callback but i got error say error C2504: 'NxOgre::PhysXCallback' : base class undefined

i though i just need to inplement function onContact() for example, but it seems not like this way.


class myCallBack: public NxOgre::callback
{
public:
myCallBack(){}

};