Problem with collision listener

nonter

03-02-2010 11:28:33

So, I read probably all thread about collision.
I found most of my answers in the wiki collision handling tutorial.
However I can't make it work :( .

Here is how I set up the physics and the collision listener:

The Listener
class GameState : virtual public AppState , public OgreOde::CollisionListener
{
...
virtual bool collision(OgreOde::Contact*);
OgreOde::World *mWorld;
OgreOde::Space *mSpace;
OgreOde::StepHandler *mStepper;
OgreOde::Body *playerBodyTorso;
OgreOde::CollisionListener *PhDetector;
...
}
bool GameState::collision(OgreOde::Contact* Contact)
{
OgreFramework::getSingletonPtr()->m_pLog->logMessage("Detected Collision!!!!!!!!!!!!!!!!!!!");
// 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;
}


The physics world
OgreFramework::getSingletonPtr()->m_pLog->logMessage("Setting Up Physics...");
mWorld = new OgreOde::World(m_pSceneMgr);
mWorld->setGravity(Ogre::Vector3(0,-9.80665,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); /// I am not sure about this but in both cases the result is the same
mWorld->setShowDebugGeometries(true);
mWorld->setCollisionListener(this);


the torso (I have a single capsule for the character)
OgreOde::SimpleSpace *playerSpace = new OgreOde::SimpleSpace(mWorld, mSpace);
Ogre::Entity *SoldierEntity = m_pSceneMgr->createEntity("Soldier", "soldier.mesh");
Ogre::SceneNode *SoldierNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("Soldier");
SceneNode* SoldPhysModel = SoldierNode->createChildSceneNode("soldier_model");
SoldPhysModel->attachObject(SoldierEntity);

// mass of the player. Experiment with setting.
Real playerMass = 2.5;

// Dimentions of body to represent player
Real playerWidth = 2;
Real playerHight = 7;

// Setup a capsule geometry to represent the rest of the player.
playerBodyTorso = new OgreOde::Body(mWorld);
playerBodyTorso->setMass(OgreOde::CapsuleMass(playerMass,playerWidth/2,Vector3::UNIT_Y,playerWidth/2));
playerBodyTorso->setAffectedByGravity(false);
// playerBodyTorso->setDamping(1,100);
OgreOde::TransformGeometry* torsoTrans = new OgreOde::TransformGeometry(mWorld,playerSpace);
OgreOde::CapsuleGeometry* torsoGeom = new OgreOde::CapsuleGeometry(playerWidth/2,5,mWorld, playerSpace);
torsoGeom->setPosition(Ogre::Vector3(0,3.5,0));
torsoGeom->setOrientation(Quaternion(Degree(90),Vector3::UNIT_X));
torsoTrans->setBody(playerBodyTorso);
torsoTrans->setEncapsulatedGeometry(torsoGeom);
SoldierNode->attachObject(playerBodyTorso);
SoldierEntity->setUserObject(torsoTrans);


the wall (I created it )
AxisAlignedBox aab = m_pSceneMgr->getSceneNode("wall.1")->getAttachedObject("wall.1")->getBoundingBox();
Ogre::Vector3 min = aab.getMinimum();//m_pSceneMgr->getSceneNode("wall.1")->getScale();
Ogre::Vector3 max = aab.getMaximum();//*m_pSceneMgr->getSceneNode("wall.1")->getScale();
Ogre::Vector3 center = aab.getCenter();//*m_pSceneMgr->getSceneNode("wall.1")->->getScale();
Ogre::Vector3 size(fabs(max.x-min.x),fabs(max.y-min.y),fabs(max.z-min.z));

OgreOde::Body* wallBody = new OgreOde::Body(mWorld);
wallBody->setMass(OgreOde::BoxMass(0.5,Vector3(size.x,size.y,size.z))) ; // (playerMass,playerWidth/2,Vector3::UNIT_Y,playerWidth/2));
wallBody->setAffectedByGravity(false);
// playerBodyTorso->setDamping(1,100);

OgreOde::TransformGeometry* wallTrans = new OgreOde::TransformGeometry(mWorld,playerSpace);
OgreOde::BoxGeometry* wallGeom = new OgreOde::BoxGeometry(size, mWorld, playerSpace);
//wallGeom->setPosition(m_pSceneMgr->getSceneNode("wall.1")->getPosition());
//wallGeom->setOrientation(Quaternion(Degree(90),Vector3::UNIT_X));
wallTrans->setBody(wallBody);
wallTrans->setEncapsulatedGeometry(wallGeom);
m_pSceneMgr->getSceneNode("wall.1")->attachObject(wallBody);


I also move the player by calling:
playerBodyTorso ->wake();
playerBodyTorso ->setLinearVelocity(Vector3(0,0,-0.4));


So, the torso moves together with the soldier, collides the wall but I don't even get the log message (OgreFramework::getSingletonPtr()->m_pLog->logMessage("Detected Collision!!!!!!!!!!!!!!!!!!!");)

Pease help :roll:

shanefarris

03-02-2010 13:11:03

Maybe I missed it but did you set GameState::collision(OgreOde::Contact* Contact) to be the callback?

nonter

03-02-2010 17:48:12

I don't know if I mentioned but i am completely new to ode so I don't know the sequence yet. Could you tell me how to do this. :)
Thanks for the fast reply
While waiting for the next I will go through the simplescenes to see how this is done there.
I didn't notice such thing :D

shanefarris

03-02-2010 23:27:14

Someone correct me if I am wrong, but to my understanding there is a default collision method that OgreOde uses. If you wanted to use your own custom method (which I believe you are trying to do), then you need to tell the wrapper. Look for something like "setListener" or something to that extent. Let me know if that helps or not.

nonter

04-02-2010 07:11:30

mWorld->setCollisionListener(this);

I thought this solves the problem because i call it in the GameState which is declared like this:

class GameState : virtual public AppState , public OgreOde::CollisionListener

Do you mean that I shouldn't declare the collision function? Will this force ogreode to use the default.
Then Where do I tell the wrapper the settings of the contact. :shock:

Thank you for spending time replying a noob! :wink:

shanefarris

04-02-2010 16:22:22

No, you're right, I just missed it. That should be fine, but it is not logging? Could it just be something wrong with your logger?

nonter

05-02-2010 02:16:54

No I'm sure because I get the other messages like "Setting up physics ... " etc .
if you use code::blocks on windows you could see how everything is set up int my project file everything is there the libs i use heathers dll's

so this is school project and it will never get to final state but it is just for education,
I uploaded it to sourcefourge so we have some versioncontrol.
What I am really trying to do is something like improved version of OgreAdvancedFramework to suit my needs (physics, sound, etc) and use it later for some game and also share it if it is useful for somebody.

https://operationkuda.svn.sourceforge.n ... rationkuda
:) have a nice day (or evening it depends :D)

shanefarris

05-02-2010 16:02:14

Where are you stepping Ode at?

nonter

06-02-2010 10:22:36

void GameState::update(double timeSinceLastFrame)
{
if(m_bQuit == true)
{
this->popAppState();
return;
}

m_MoveScale = m_MoveSpeed * timeSinceLastFrame;
m_RotScale = m_RotateSpeed * timeSinceLastFrame;

m_TranslateVector = Vector3::ZERO;

///Animation Step //////////////////////////////////////////////////////////////////////////
mAnimState->addTime(timeSinceLastFrame*0.0012); /// Animation jumps to next frame
RotateBone->setPosition(RootBone->getPosition());
///Animation Step //////////////////////////////////////////////////////////////////////////
Quaternion q = playerBodyTorso->getOrientation();

Vector3 x = q.xAxis();
Vector3 y = q.yAxis();
Vector3 z = q.zAxis();

playerBodyTorso->wake();
playerBodyTorso->setOrientation(Quaternion(x,Vector3::UNIT_Y,z));
//playerBodyFeet->setOrientation(Quaternion(x,Vector3::UNIT_Y,z));

///Physics Step //////////////////////////////////////////////////////////////////////////
mStepper->step(timeSinceLastFrame);
mWorld->synchronise();
///Physics Step //////////////////////////////////////////////////////////////////////////

getInput();
moveCamera();
}


I think you spent enough time dealing with my problem :( sorry for this as i said i am new to ode and i just can't get how to do even simple things
So at this time i give up ode ....