OgreOde collision listener problem...and more..

marc_antoine

14-05-2009 22:10:00

first of all, i will try to xplain what i have been doing..
I'm new to this physics stuff so i'm trying ogre ODE for the first time, and after having a hard time trying to compile ogrOde i finally got it and srtarted reading the WIKI tut. http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE everything went fine i got the program running, but i got somehow confusing, since at the beginning of the tutorial i thought that the crate will collide with my floor... so the crate will stop falling right when it hits the floor, but for my surprise i didn't. almost at the end, rewb0rn says the the crate will get through the floor, so ok, i move on to the collision tutorial http://www.ogre3d.org/wiki/index.php/OgreOde_Collision_Handling , i found interesting but is not a clear example of how to hanlde collision....what i got from that example is that i have to do a clas that implemests the collision callback in it so o came to this code...

myOgreOde.h

#include <Ogre.h>
#include <OIS/OIS.h>
#include "marcBasicFrameListener.h"
#include "OgreOSMScene.h"
#include "OgreOde_Core.h"

using namespace Ogre;
class Application: public OgreOde::CollisionListener
{
public:
void go();
~Application();

private:
Root *mRoot;
OIS::Keyboard *mKeyboard;
OIS::Mouse *mMouse;
OIS::InputManager *mInputManager;
ExitListener *mListener;
Ogre::RenderWindow *mWindow;
Ogre::Camera *mCamera;
Ogre::SceneManager *mSceneMgr;
Ogre::Viewport *vp;
Ogre::SceneNode* nodoMyCamera;
Ogre::SceneNode* nodoModelo;

///Ogre ODE/////////////////////////////////////
OgreOde::World *mWorld;
OgreOde::Space *mSpace;
OgreOde::StepHandler *mStepper;
////
OgreOde::InfinitePlaneGeometry *mGround;
OgreOde::Body *mBody;
OgreOde::Geometry *mGeom;
OgreOde::BoxMass mMass;
//////////////////////////////////////////////
Ogre::SceneNode *mNode;
Ogre::Entity *mEntity;
////////////////////////////////////////////////

void createRoot();
void defineResources();
void setupRenderSystem();
void createRenderWindow();
void initializeResourceGroups();
void setupScene();
void setupInputSystem();
void createFrameListener();
void startRenderLoop();
void cargarOSM();
void setupPhysics();
bool collision(OgreOde::Contact *);


};


myOgreOde.cpp---- i'm posting only the the two methods that has ogreOde code, to keep it easy to read... also i'm not loading the mesh directly, since i'm using the OFusion plugin to create my Meshes i have to use the Ofusion Loader.


#include "myOgreOde.h"
void Application::setupPhysics()
{
mWorld = new OgreOde::World(mSceneMgr);
mWorld->setGravity(Ogre::Vector3(0,-980.665,0));
mWorld->setCFM(10e-5);
mWorld->setERP(0.8);
mWorld->setAutoSleep(true);
mWorld->setAutoSleepAverageSamplesCount(10);
mWorld->setContactCorrectionVelocity(1.0);
mSpace = mWorld->getDefaultSpace();
mSpace->setInternalCollisions(true);
mWorld->setCollisionListener(this); //<-------since class Application: public OgreOde::CollisionListener
mWorld->setShowDebugGeometries(true);

////*/////////*/*/*//*/*/*/*/*/*/*/*/*/*/*////
const Ogre::Real _time_step = 0.5;
const Ogre::Real time_scale = Ogre::Real(1.7);
const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4);
mStepper = new OgreOde::StepHandler(mWorld, OgreOde::StepHandler::QuickStep,_time_step, max_frame_time,time_scale);
//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*
mGround = new OgreOde::InfinitePlaneGeometry(Plane(Ogre::Vector3(0,1,0),10), mWorld, mWorld->getDefaultSpace());
//*/**//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//
mBody = new OgreOde::Body(mWorld);
mNode=mSceneMgr->getSceneNode("caja"); //<----i get the crate like this becouse i'm using oFusion loader
mEntity=mSceneMgr->getEntity("caja"); //<----so i gotta get the entity liek this.... for the same reason...
mNode->attachObject(mBody);

Vector3 size(mEntity->getBoundingBox().getSize());//the model size is in cm, and is 1000, 1000,1000
OgreOde::BoxMass mMass(0.5,size);
mMass.setDensity(0.05,size);
mGeom = (OgreOde::Geometry*)new OgreOde::BoxGeometry(size, mWorld, mSpace);
mBody->setMass(mMass);
mGeom->setBody(mBody);
mEntity->setUserObject(mGeom);

}
bool Application::collision(OgreOde::Contact *contact)
{

MessageBoxA(NULL, "colision!!", "colision!!", MB_OK);
return false;

}



  1. so when the crate hits the floor, i get a collision callback :) but anyway it continues it way through the floor... [/list:u]
    1. also the collision box seems to be like in the middle of the crate?.. why's so? it is normal?[/list:u]
      1. even if the crate has gone through the floor, and it is no colliding anymore... the collision() is been called again, and again , and again, and never stops i have to kill the program...[/list:u]

        [attachment=1]colissionDoubt.jpg[/attachment]

        box continuing it's free fall, and the collision messageBox still appearing indicating that the collision() is still been called

        [attachment=0]colissionDoubt2.jpg[/attachment]
        any clues?, any clear simple way of how to implement this?. the ogreOde examples are fine, but they are an all topics in one example, project, PLEAAASEEEE!!!!...

        i'm sorry for bothering you guys...
        cheers!

dermont

14-05-2009 23:36:07

Your returning false from your collision callback, hence no collision. Take a look at the demos, SimpleScenes.cpp:


bool Application::collision(OgreOde::Contact* contact)
{
// Check for collisions between things that are connected and ignore them
OgreOde::Geometry * const g1 = contact->getFirstGeometry();
OgreOde::Geometry * const g2 = contact->getSecondGeometry();

if (g1 && g2)
{
const OgreOde::Body * const b1 = g1->getBody();
const OgreOde::Body * const b2 = g2->getBody();
if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2))
return false;
}

// Set the friction at the contact
contact->setCoulombFriction(OgreOde::Utility::Infinity);

contact->setBouncyness(0.1);
// Yes, this collision is valid
return true;
}

marc_antoine

15-05-2009 00:09:02

hi dermont, already did that, i tried returnin false and true, and nothing happens, i even used that same snippet


// Check for collisions between things that are connected and ignore them
OgreOde::Geometry * const g1 = contact->getFirstGeometry();
OgreOde::Geometry * const g2 = contact->getSecondGeometry();

if (g1 && g2)
{
const OgreOde::Body * const b1 = g1->getBody();
const OgreOde::Body * const b2 = g2->getBody();
if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2))
return false;
}

// Set the friction at the contact
contact->setCoulombFriction(OgreOde::Utility::Infinity);

contact->setBouncyness(0.1);
// Yes, this collision is valid
return true;


and still gets through the infinite plane, i have to setup a collision space or something?.. .. :S :( i have to use joints? wow ... i even found a guy that the box hitted the floor and jumped back...only witht he code of the first steps tutorial..... what i'm doing wrong here?...

marc_antoine

15-05-2009 20:12:55

by the way i'm using the CVS version of ogreOde, i ddon't know if it is faulty or something, but i think everyone did their first scene as mine, lol, the difference is that thaya re using ogre 1.4x and the stable ogreode sdk, am i wrong?.. .. well if not please help me guys!!! :(

dermont

15-05-2009 21:21:15

I think your problem may be since your working in cm and your crate object is 1000x1000x1000 cm that you are setting an extremely high mass via:
mMass.setDensity(0.05,size);

Try commenting out the above line and see if it makes a difference.

marc_antoine

17-05-2009 06:36:22

WELL..UMMM..yea maybe the mesh is to big, this means that everything in my scene should be resized, by any mean (ogre or 3dsMax)?....anyway, changuing that setting stopped the crate.. BUT ALSO leaving the original size of the crate, and setting a small OgreOde::BoxGeometry with a size 1x1x1 did the trick...... well maybe ODE is not for everyone... thanks dermont for replying

also you never told me, is it correct the position of the OgreOde::BoxGeometry ? as i spotted before, it appears in the middle of the crate (the collision geometry is represented by a green box) as you can see in the pics at the beginning of this thread... this is normal? i should adjust it by myself?

thank you
cheers..