Collision detect

fcofds

16-11-2009 10:12:10

In the previous version of NxOgre I detected collision among moveable object using GroupCallback::InheritedCallback but now I don't know to detect collisions, I have only seen the option volumen for creating something similar but I want to detect collisions with moveable objects. I am trying to use directly PhysX but I am not able to establish the collisions group with NxScene::setGroupCollisionFlag(CollisionGroup g1, CollisionGroup g2, bool enable); because NxScene is a class of PhysX SDK. Can anybody help me?

Sorry for my english

fcofds

16-11-2009 12:39:47

Thank you very much. I found this thread viewtopic.php?f=6&t=10518&p=60844&hilit=setGroupCollisionFlag#p60844 and I saw how I can call to physx. I leave here the code


void Animar::createScene()
{
.......

//creo el nodo del ninja, en este caso, hay que sustituir todo por esta línea que ya lo hace todo
nxBodyNinja = nxRenderSystem->createBody(new NxOgre::Box(20, 20, 20), Vec3(0,100,0), Ogre::String("ninja.mesh"));

//para que tenga sombras
nxBodyNinja->getEntity()->setCastShadows(true); //emite sombras
nxBodyNinja->getSceneNode()->setScale(Vector3(0.2f, 0.2f, 0.2f));
nxBodyNinja->setMass(10);
nxBodyNinja->setMassSpaceInertiaTensor(Vec3(0,0,0));
nxBodyNinja->getNxActor()->setGroup(2);


//introduzco la cámara como hijo del ninja y así le sigue
sceneNodeCamera=nxBodyNinja->getSceneNode()->createChildSceneNode();
sceneNodeCamera->attachObject(mCamera);


//creo los cubos
nxBodyCubo1 = nxRenderSystem->createBody(new NxOgre::Box(40, 40, 40), Vec3(0,30,-200), Ogre::String("cube.mesh"));
nxBodyCubo1->getSceneNode()->scale(Vector3(0.2, 0.2, 0.2));
nxBodyCubo1->getEntity()->setMaterialName("Examples/10PointBlock");
nxBodyCubo1->setMass(10);
nxBodyCubo1->getNxActor()->setGroup(1);


nxBodyCubo2 = nxRenderSystem->createBody(new NxOgre::Box(40, 40, 40);, Vec3(0,30,-400), Ogre::String("cube.mesh"));
nxBodyCubo2->getSceneNode()->scale(Vector3(0.2, 0.2, 0.2));
nxBodyCubo2->getEntity()->setMaterialName("Examples/10PointBlock");
nxBodyCubo2->setMass(10);
nxBodyCubo2->getNxActor()->setGroup(1);



//activo colisiones
nxScene->getScene()->setGroupCollisionFlag(1, 2, true);
nxScene->getScene()->setActorGroupPairFlags(1, 2, NX_NOTIFY_ON_START_TOUCH);

//listener
nxScene->getScene()->setUserContactReport(new NxUserContactReportAnimar());

......
}




The listener

#include "..\include\NxUserContactReportAnimar.h"
#include <NxActor.h>

NxUserContactReportAnimar::NxUserContactReportAnimar(void)
{
}

NxUserContactReportAnimar::~NxUserContactReportAnimar(void)
{
}

void NxUserContactReportAnimar::onContactNotify(NxContactPair& pair, NxU32 events)
{
if((pair.actors[0]->getGroup()==2 && pair.actors[1]->getGroup()==1) || (pair.actors[0]->getGroup()==1 && pair.actors[1]->getGroup()==2))
{
exit(0);
}
}

Regards