Problem with setting hinge joint [solved]

nonter

30-01-2010 23:16:26

Hi went through the tutorial in the wiki but they seem a bit outdated to me.
My problem is that i want my character to collide with the surrounding objects.
I saw the tutorial with the capsule and the sphere connected with hinge joint.
So the sphere must rotate and so on ..
But I am far from that state.
I am new to physics at all and compiled ode 1 week ago.
Since then I have no progress.
I am actually working on a school project.
I registered it in sourceforge.net by the name Operation Kuda for my teammates so we have some version control.
I use ogre 1.61, ode 0.11 and ogre ode the version from cvs and also everything is on top of the Advanced Ogre Framework Demo.

So, here is how i define the geometries and the world:
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(false);

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);
/// //////////////// Setting Up Physics //////////////////////////////////////////////


m_pSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); //Sky
m_pSceneMgr->createLight("Light")->setPosition(75,75,75); //Light
m_pSceneMgr->getLight("Light")->setCastShadows(true);

Ogre::DotSceneLoader* pDotSceneLoader = new Ogre::DotSceneLoader(); //MAP
pDotSceneLoader->parseDotScene("ice.scene.xml", "General", m_pSceneMgr, m_pSceneMgr->getRootSceneNode()); //MAP


/** CHARACTER ****************************************************************************
Ogre::Entity *SoldierEntity = m_pSceneMgr->createEntity("Soldier", "soldier.mesh");
Ogre::SceneNode *SoldierNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("Soldier");
SoldierNode->attachObject(SoldierEntity);
SoldierNode->setScale(0.5,0.5,0.5);
//SceneNode* SoldPhysModel = SoldierNode->createChildSceneNode("soldier_model");

AxisAlignedBox aab = SoldierNode->getAttachedObject("Soldier")->getBoundingBox();
Ogre::Vector3 min = aab.getMinimum()*SoldierNode->getScale();
Ogre::Vector3 max = aab.getMaximum()*SoldierNode->getScale();
Ogre::Vector3 center = aab.getCenter()*SoldierNode->getScale();
Ogre::Vector3 size(fabs(max.x-min.x),fabs(max.y-min.y),fabs(max.z-min.z));
//Ogre::Real radius = (size.x>size.z)?size.z:size.x;
Ogre::Real radius = (size.x>size.z)?size.z/2.0f:size.x/2.0f;

/// feet Sphere for Physics-----------
OgreOde::Body* dollFeetBody = new OgreOde::Body(mWorld,"feet");
dollFeetBody->setMass(OgreOde::SphereMass(70*2.5,radius));
OgreOde::SphereGeometry* feetGeom = new OgreOde::SphereGeometry(radius, mWorld, mSpace);
OgreOde::TransformGeometry* feetTrans = new OgreOde::TransformGeometry(mWorld, mSpace);
//SoldierNode->translate(Vector3(0,-radius/SoldierNode->getScale().y,0));

feetTrans->setBody(dollFeetBody);
feetTrans->setEncapsulatedGeometry(feetGeom);
SoldierNode->attachObject(dollFeetBody);
/// feet Sphere for Physics-----------

/// body Capsule for Physics-----------
OgreOde::Body* dollTorsoBody = new OgreOde::Body(mWorld, "torso");
dollTorsoBody->setMass(OgreOde::CapsuleMass(70*2.5,radius,Vector3::UNIT_Y,radius));
dollTorsoBody->setAffectedByGravity(false);
//dollTorsoBody->setDamping(0,50000);
OgreOde::TransformGeometry* torsoTrans = new OgreOde::TransformGeometry(mWorld, mSpace);
OgreOde::CapsuleGeometry* torsoGeom = new OgreOde::CapsuleGeometry(radius, size.y-4*radius, mWorld, mSpace);
torsoGeom->setPosition(Ogre::Vector3(0,5 size.y-((size.y-4*radius)/2+2*radius) ,0)); //can't find a good way to explain this
torsoGeom->setOrientation(Quaternion(Degree(90),Vector3::UNIT_X));
torsoTrans->setBody(dollTorsoBody);
torsoTrans->setEncapsulatedGeometry(torsoGeom);
SoldierNode->attachObject(dollTorsoBody);
RootBone = SoldierEntity->getSkeleton()->getBone("Bone.001");

/// body Capsule for Physics-----------

/// vrazka mejdu AKO SE KOMMENTNE GEROQ SE POQVQVA
OgreOde::HingeJoint* joint = new OgreOde::HingeJoint(mWorld);
joint->attach(dollFeetBody,dollTorsoBody);
joint->setAxis(Ogre::Vector3::UNIT_X); //set the rotation axis
/// Vrazka AKO SE KOMMENTNE GEROQ SE POQVQVA*/

/// Physics Debug View On/Off -----------
torsoGeom->createDebugObject();
feetGeom->createDebugObject();
//torsoGeom->destroyDebugObject();
//feetGeom->destroyDebugObject();
/// Physics Debug View On/Off -----------

mAnimState = SoldierEntity->getAnimationState("run"); ///------------------------------
mAnimState->setEnabled(true); ///Na4alna to4ka na animaciqta Run koqto prili4a po skoro na Walk :D
mAnimState->setLoop(true); ///------------------------------

///Glavnata kost na tqloto @todo rename to Root in soldier.mesh
RotateBone = SoldierEntity->getSkeleton()->getBone("Rot");


if you compare it to the walking character tutorial it's almost the same but just see the result


you can also download the whole stuff from svn: https://operationkuda.svn.sourceforge.net/svnroot/operationkuda/ and debug directly.
Hope somebody has idea. :)

shanefarris

02-02-2010 14:59:34

looks like maybe your collision geom is attached to your root bone, but your root bone is at the bottom of your mesh. You want to surround most of your mesh with the collision geom, is that what you're trying to do?

nonter

02-02-2010 16:20:48

Actually there wasn't problem. (The answer is always where you don't look for it! :lol: )
I just created the debug object for the torsoGeom instead for the torsoTrans.
It was not explained which exactly geometry actually moves with the player.
I am too lazy at the moment to post screen shot of the new result and after all it is like in the tutorial.
thanks for the reply :)

shanefarris

02-02-2010 18:18:48

If your code differs from the tutorial, maybe you should put an updated example up for people. :mrgreen: