Collision detection + debugger = wierd collisions?!

joaopccosta

21-10-2010 14:41:27

Hi there guys!
I'm totally new to NxOgre and i'm using it on my college thesis project.

So... first, i've built it successfuly and I've been following the 1st tutorial. I successfuly ran through it but i noticed that... the collision between the two cubes, does not occur at the cube's meshes but at the "object center" you might say. Meaning, there's mesh penetration :? Plus, when the cubes hit the ground, their meshes don't collide with the plane... again, it's their "object center" that collides :?

Thinking that this was abnormal, i move forward to the 2nd tutorial. Maybe the visual debugger would help to understand what was going wrong. Again, it was a breeze. But, when i run the app, I get no visual debugging :(

So my question is... what could be wrong with my approach?
Thanks for any help!

Here goes my code, just in case:
I've added some methods of mine so...
Application Code

class NxOgre_testapp : public ExampleApplication
{
public:
NxOgre_tutorial1App()
{
createdObjects = 0;
}
~NxOgre_tutorial1App()
{
}

protected:

//NxOgre Vars
NxOgre::World* mWorld;
NxOgre::Scene* mScene;
OGRE3DRenderSystem* mRenderSystem;

//NxOgre Debugger vars
NxOgre::VisualDebugger* mVisualDebugger;
OGRE3DRenderable* mVisualDebuggerRenderable;
Ogre::SceneNode* mVisualDebuggerNode;

vector<OGRE3DBody*> bodies;
int createdObjects;

virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");

// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,200,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(5);
}


virtual bool configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
HWND hwnd;
mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
LONG iconID = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
SetClassLong( hwnd, GCL_HICON, iconID );
#endif
return true;
}
else
{
return false;
}
}


// Just override the mandatory create scene method
virtual void createScene(void)
{
// Create Physics World
initNxOgre();

// 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);
l->setDiffuseColour(.20,.20,.20);
l->setSpecularColour(.20,.20,.20);


//basic world is now set...
//creating objects
createPlane("GrassFloor");
//createSphere(Vector3(-50,200,0),1,"RustySteel");
//createSphere(Vector3(50,200,0),2,"");
createCube(Vector3(0,200,0),10,"");
//createCube(Vector3(0,200,100),10,"");

addForceOnBody("Cube_1", NxOgre::Vec3(0,0,-1000));
//addForceOnBody("Sphere_1", NxOgre::Vec3(3000,0,0));

}



// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new NxOgre_tutorial1FrameListener(mWindow, mCamera, mVisualDebugger, mVisualDebuggerNode);
mRoot->addFrameListener(mFrameListener);
}

void addForceOnBody(string bodyName, NxOgre::Vec3 force)
{
unsigned int i;
OGRE3DBody* tempbody;
for (i = 0; i<bodies.size(); i++){
tempbody = bodies.at(i);
string tempname = tempbody->getNxActor()->getName();

if(tempname.find(bodyName)!= -1)
tempbody->addForce(force);
}

}

void createSphere(Vector3 pos, float scale = 1, string name = "")
{
OGRE3DBody* mBody;
//this is a scale between Ogre and NxOgre
static const Real physics_scale = 0.1;

//incrase number of objects
createdObjects++;

//create the body
mBody = mRenderSystem->createBody(new NxOgre::Sphere(scale),pos,"sphere.mesh");

//set object name
char* temp = new char[sizeof(int)];
itoa(createdObjects,temp,10);
char* temp2= new char[20];
char *aux = "Sphere_";
memcpy(temp2,aux,strlen(aux));
strcat(temp2,temp);
mBody->getNxActor()->setName(temp2);


//scale adjust
mBody->getEntity()->getParentNode()->scale(scale*physics_scale ,scale*physics_scale ,scale*physics_scale);

if (name.compare("") !=0)
mBody->getEntity()->setMaterialName("Examples/"+name);

bodies.push_back(mBody);
}
void createCube(Vector3 pos, float scale = 1, string name = "")
{

OGRE3DBody* mBody;
//this is a scale between Ogre and NxOgre
static const Real physics_scale = 0.1;
scale = scale * physics_scale;
//incrase number of objects
createdObjects++;

//create the body
mBody = mRenderSystem->createBody(new NxOgre::Box(scale,scale,scale),pos,"cube.mesh");


//set object name
char* temp = new char[sizeof(int)];
itoa(createdObjects,temp,10);
char* temp2= new char[20];
char *aux = "Cube_";
memcpy(temp2,aux,strlen(aux));
strcat(temp2,temp);
mBody->getNxActor()->setName(temp2);
mBody->getEntity()->getParentNode()->scale(scale*physics_scale ,scale*physics_scale ,scale*physics_scale );
mBody->setMass(10);

if (name.compare("") !=0)
mBody->getEntity()->setMaterialName("Examples/"+name);

bodies.push_back(mBody);
}

void createPlane(string name)
{

mScene->createSceneGeometry(new NxOgre::PlaneGeometry(0, NxOgre::Vec3(0, 1, 0)), Matrix44_Identity);

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/"+name);
planeEnt->setVisible(true);
Ogre::SceneNode* mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlaneNode->attachObject(planeEnt);
//mPlaneNode->scale(1, 1, 1);
}



void logActors()
{
//test to log all NxOgre Actors
unsigned int i;
OGRE3DBody* tempbody;
Ogre::LogManager::getSingleton().logMessage(LML_NORMAL,"Our Objects! \n");

for (i = 0; i<bodies.size(); i++){
tempbody = bodies.at(i);
string tempname = tempbody->getNxActor()->getName();
Ogre::LogManager::getSingleton().logMessage(LML_NORMAL,tempname);
}

}

private:
void initNxOgre()
{
//init NxOgre World
mWorld = NxOgre::World::createWorld();
//init NxOgre Visual Debugger
mVisualDebugger = mWorld->getVisualDebugger();
mVisualDebuggerRenderable = new OGRE3DRenderable(NxOgre::Enums::RenderableType_VisualDebugger);
mVisualDebugger->setRenderable(mVisualDebuggerRenderable);
mVisualDebuggerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mVisualDebuggerNode->attachObject(mVisualDebuggerRenderable);
mVisualDebugger->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);


NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0, -9.8f, 0);
sceneDesc.mName = "MyTestApp";
//attach scene to the world
mScene = mWorld->createScene(sceneDesc);

// Setup default physical attributes of the world
mScene->getMaterial(0)->setStaticFriction(0.5);
mScene->getMaterial(0)->setDynamicFriction(0.5);
mScene->getMaterial(0)->setRestitution(0.1);

// Declare rendering engine
mRenderSystem = new OGRE3DRenderSystem(mScene);
}
};


Application FrameListener Code

class NxOgre_testappFrameListener : public ExampleFrameListener
{
private:
SceneManager* mSceneMgr;

protected:
NxOgre::TimeController* mTimeController;

NxOgre::VisualDebugger* mVisualDebugger;
Ogre::SceneNode* mVisualDebuggerNode;

public:
NxOgre_tutorial1FrameListener(RenderWindow* win, Camera* cam, NxOgre::VisualDebugger* visualDebugger, Ogre::SceneNode* node)
: ExampleFrameListener(win, cam)
{
mTimeController = NxOgre::TimeController::getSingleton();
mVisualDebugger = visualDebugger;
mVisualDebuggerNode = node;
}

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

bool ret = ExampleFrameListener::frameStarted(evt);


return ret;

}

};

joaopccosta

22-10-2010 12:02:35

help anyone?
:?

betajaen

22-10-2010 12:15:06

That seems a little strange. Do you have any screenshots of it? This is just with the Visual Debugger right? With it turned off, everything is normal?

joaopccosta

22-10-2010 12:23:55

Hi betajaen (and congrats on your great work :) )

Yeah i've just taken 2 screenshot. here they are

Initial State



Final State


It happens whether the Visual Debugger is on or off :S
It seems that the objects are chopped in half by the ground plane, hence my deduction about the collisions occuring at the "object center" :S
Btw, I'm using bloodymess.

Thanks for your help!

joaopccosta

22-10-2010 12:26:43

argh sorry for the broken picture links...

Initial State


Uploaded with ImageShack.us

Final State


Uploaded with ImageShack.us

betajaen

22-10-2010 13:02:54

Ahh, right. Okay either the meshes are offset (all of the vertices are above +Y 0), or the cube and sphere in NxOgre are very very very small. I vote for the first one. Have you tried using my meshes that come with the tutorials?

joaopccosta

22-10-2010 14:29:29

I've been just trying this with the cube, and changed the mesh to the cube.1m.mesh :P and it worked with a different scale :D:D
It seems i was working with a very small scale.
So the problem here is with the .mesh files right? I've tested with some cubes (which work fine now) but the sphere is messed up.

And i still get no debug information :\
Shouldn't the bounding boxes wireframes be drawn, etc? :\

Anyway, this is just a test app to work my way around the NxOgre :P I'll be using humanoid meshes and other objects. Can you suggest how this can be done?

Many thanks :D

betajaen

22-10-2010 14:57:33

Are those the cube/sphere meshes that come with Ogre? If yes; then they are massive. NxOgre works in metres, and I think the cube is 100x100x100 big!

Are you using Detritus or Bloody Mess?

joaopccosta

25-10-2010 11:03:41

Hi there! Sorry for answering so late. Had to take the weekend off :P

Yeah, I was working with the sphere from Ogre. (The cube is now the NxOgre One) But i'll be working with some custom meshes in my project. I hope they work alright! If not, i'll let you know :)

Working with bloody mess ;)
Should i switch to detritus?

cheers

betajaen

25-10-2010 11:12:28

Always use Detritus. Bloody Mess is almost two years old now.

joaopccosta

25-10-2010 11:54:12

:O alright then!

On the wikipage there's only a like for the bloodymess github :\ so i downloaded it. I'll try to get the detritus and work around. If I get into some trouble, i'll let you know.

Thanks for your help! ;)