Should i use joint? How?

nord666

11-06-2008 20:49:57

Hi!

I have a question that will be easy for you but i can't find any post that can help me.

The situation:
I want a box that can move(i can do that) with a cylinder that follow the box on one side. I want the cylinder to keep the same position on the box's side. Also, i want it able to rotate on X and Y axis.

Here is what i have done:


mainNode = mgr->getRootSceneNode()->createChildSceneNode();

boxEnt = mgr->createEntity("box1", "box.mesh");
boxEnt->setQueryFlags(1<<2);
boxEnt->setMaterialName("Examples/DarkMaterial");
boxNode = mainNode->createChildSceneNode();
boxNode->attachObject(entity);
boxNode->scale(2, 1, 3);

OgreNewt::Collision * col = new OgreNewt::CollisionPrimitives::Box(mWorld, Ogre::Vector3(2, 1, 3));
boxBody = new OgreNewt::Body(mWorld, col);
boxBody->attachToNode(mainNode);
boxBody->setUserData(this);
delete col;
Ogre::Real mass = 60.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid(mass, Ogre::Vector3(2, 1, 3));
boxBody->setMassMatrix(mass, inertia);
boxBody->setStandardForceCallback();
boxBody->setAutoFreeze(0);


For now, i have a box that fall. Then, i add the cylinder:


//They are initialysed in function call.
//Ogre::Vector3 pos; It's the position on box
//Ogre::Quaternion orient; It's the orientation

//_node is mainNode see above

Ogre::Vector3 size(0.5, 0.3, 0.3);
ent = mgr->createEntity(_cylinderName, "cylinder.mesh");
cylNode = _node->createChildSceneNode();
cylNode->attachObject(ent);
cylNode->setScale(size);

OgreNewt::Collision * col = new OgreNewt::CollisionPrimitives::Cylinder(mWorld, 0.3, 0.5);
body = new OgreNewt::Body(mWorld, col);
body->attachToNode(node);
delete col;
Ogre::Real mass = 12.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid(mass, 0.3, 0.5);
body->setMassMatrix(mass, inertia);
body->setPositionOrientation(pos, orient);


Now, when i start my application, the cylinder fall 2x faster than the box(certainly because of the shape). As i said in the situation, i want to keep the cylinder at the same position on the box's side. I have tried a lot of thing with joint but none worked.

Anyone has an idea?

Thanks all!

PS: sorry for my English.