ceacy
20-05-2007 11:43:10
Hi,
I'm currently trying to set up physics, with OgreODE, in a RPG project. Physics do not have to be accuracy, or realistic : the main purpose is
- to prevent things from entering in each others
- to simulate gravity
- not to make moves seeming weird
For the characters, i use the "wiki way" : a capsule and a sphere.
This is the code used to make moves/etc :
http://ceacy.free.fr/tmp/physics.htm
This is the OgreODE initialization code :
(i disabled the collision listener automatic stuff, because it seems to cause stack corruption under windows ; i manually call preStep() every TIME_STEP, even it is is much less accurate).
What i would like to know is : are these settings all right ? I mean, i don't know how to tune these values (cfm, erp, bouncyness, sofness, ...), i don't even know if the way i did this is right. What settings should i use to have collisions "normal" (objects not bouncing and not merging, just stopping) ?
Thank you,
Ceacy.
I'm currently trying to set up physics, with OgreODE, in a RPG project. Physics do not have to be accuracy, or realistic : the main purpose is
- to prevent things from entering in each others
- to simulate gravity
- not to make moves seeming weird
For the characters, i use the "wiki way" : a capsule and a sphere.
This is the code used to make moves/etc :
http://ceacy.free.fr/tmp/physics.htm
This is the OgreODE initialization code :
mWorld = new OgreOde::World( mSceneMgr );
mWorld->setGravity( Ogre::Vector3( 0, World::Physics::GRAVITY, 0 ) );
mWorld->setCFM( 100e-5 ); // http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3578
mWorld->setERP( 0.8 );
mWorld->setAutoSleep( true );
mWorld->setContactCorrectionVelocity( 1.0 );
mStepper = new OgreOde::ForwardFixedInterpolatedStepHandler( mWorld, OgreOde::StepHandler::QuickStep, World::Physics::TIME_STEP );
mStepper->setAutomatic( OgreOde::StepHandler::AutoMode_NotAutomatic, mRoot );
// mStepper->setStepListener( this );
mWorld->setCollisionListener( this );
(i disabled the collision listener automatic stuff, because it seems to cause stack corruption under windows ; i manually call preStep() every TIME_STEP, even it is is much less accurate).
bool PlayState::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.01 );
contact->setSoftness( 0.8, 10e-5 ); // http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3578
contact->setFrictionMode( OgreOde::Contact::Flag_FrictionPyramid );
// Yes, this collision is valid
return true;
}
What i would like to know is : are these settings all right ? I mean, i don't know how to tune these values (cfm, erp, bouncyness, sofness, ...), i don't even know if the way i did this is right. What settings should i use to have collisions "normal" (objects not bouncing and not merging, just stopping) ?
Thank you,
Ceacy.