Problems/question about CustomRigidJoint

StTwister

05-11-2007 18:57:38

Hey everyone,

I'm trying to build a Foosball game with Ogre and OgreNewt, but I've come across some problems in successfully integrating the physics part. This is how my foosball table looks:




You can see 8 bars, each having some dummy players attached. Now, each bar and player represents an object in the Newton world. I want each player from a bar to be connected to the bar via a CustomRigidJoint so they all move/rotate together. My problem is that the players don't remain attached to the bar when adding force/torque to the bar.

The code

Bar// create the bar body
// i use a null collision mesh because i want to use the bar only to group the players together
OgreNewt::CollisionPrimitives::Null* barcol = new OgreNewt::CollisionPrimitives::Null( mWorld );
OgreNewt::Body* bar = new OgreNewt::Body( mWorld, barcol );
bar->attachToNode( node );
node->attachObject( ent ); // ent is my bar Ogre::Entity
bar->setPositionOrientation( currPos, currOrient );

// just some pretty random values
Ogre::Real mass = 250;
bar->setMassMatrix(mass, OgreNewt::MomentOfInertia::CalcEllipsoidSolid( mass, Vector3(1, 1, 250000) ) );

// i want to restrict the bar to moving and rotating to the Z-axis
NewtonConstraintCreateCorkscrew( mWorld->getNewtonWorld(), currPos.ptr(), Ogre::Vector3(0,0,1).ptr(), bar->getNewtonBody(), 0 );

// simple debug callback function that just adds some torque
bar->setCustomForceAndTorqueCallback( (OgreNewt::Body::ForceCallback)myCallback );


Callbackvoid myCallback(OgreNewt::Body* me)
{
me->setOmega( Ogre::Vector3(0, 0, 10) );
}


Players// create the player body
OgreNewt::CollisionPrimitives::ConvexHull* col = new OgreNewt::CollisionPrimitives::ConvexHull( mWorld, node );
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( node );
node->attachObject(ent);
bod->setPositionOrientation( currPos2, currOrient2 );

// again some pretty random values
Ogre::Real mass = 25;
bod->setMassMatrix(mass, OgreNewt::MomentOfInertia::CalcEllipsoidSolid( mass, Vector3(0.2, 2, 0.7) ) );

// attach the players to the bar that we created just before
OgreNewt::PrebuiltCustomJoints::CustomRigidJoint* Joint = new OgreNewt::PrebuiltCustomJoints::CustomRigidJoint( bod, bar, Ogre::Vector3::UNIT_Z, (currPos + currPos2)/2 );


The problem
Well, instead of turning nicely in a group, all hell breaks loose. Both the corkscrew joint and the CustomRigidJoint seem to be working improperly. This is how it looks:




Some questions
There's one thing i don't get about CustomRigidJoint. What are the pos and dir parametrs for? If you join them with no DOF left, then there shouldn't be any point where the 2 bodies would bend/translate etc. Please tell me what's wrong in my thinking, I'm pretty newbie in this physics world :P


So, please tell me what you see wrong in my code or my thinking! Is it something I've done wrong or should I try to get the same effect in a different manner?

Thank you,
StTwister

walaber

07-11-2007 22:58:06

the pos and dir are just for internal calculations... pick the center of the joint for pos, and give it an axis for dir...

but first, can you try your game with just the corkscrew joint to make sure it's working properly in isolation?

StTwister

09-11-2007 13:26:00

Joining the players to the table or to the world directly with a corkscrew works very fine. So I guess the problem would be with the rigid joint.

Could it be the fact that the bars have no collision mesh ?

walaber

19-11-2007 04:58:13

if there is no rigid body for the bars, what are you connecting the players to? each other in a chain? that will probably cause problems...

StTwister

23-11-2007 12:42:17

No i dont connect the players in a chain, I connect each player to the parent bar, but it doesnt have any collision mesh, it's just a body used to group them in a set.

Unfortunately, I have lost the source code due to some serious hardware failure and I'll have to start rebuilding the application, so I can't test if adding a collision mesh to the bar would work.

But if I remember correctly, i think i did try that and it didn't work, not quite sure about that. Anyway, I'll come back with more test details once I rebuild it.

VictorMoran

26-11-2007 19:23:40

Unless I am missing something with rigid joint, you are making it to complex, why not make a compound collision that encompassed the bar and the players, then you only need a cylindrical constraint? I believe in Newton this is the corckscrew joint.

walaber

28-11-2007 19:37:54

yes, unless you want the players to be able to "break" off of the rod, you should just go with a compound collision and a single corkscrew joint on the entire body.

StTwister

29-11-2007 20:10:09

Sorry, but what is this "compound collision" ?

Is it another method of creating a collision mesh besides using the convex hull? Or does it combine the convex hulls? How do I implement it? I can't find any classes/functions regarding it.

Edit: Found some info here, I'm going to check it out

Later edit: Never mind, I think I found anything I needed to get going with this approach so I'm going to try it and post my results when I'm ready with it

oldfox

14-12-2007 22:24:41

Hi there!

I'm currently working on a flight sim, and I'm modeling separately every components like wings, fuselage and so on...

But how can I link them?? This rigid joint don't seem to work perfectly :/ I'm in fact trying to use it in the OgreNewt joint demo and the chain can still move be a litle amount... So I'm afraid it's not perfeclty rigid ....

Any other solution to group bodies?? Or to make the rigid joint perfectly rigid?

Thx!

walaber

15-12-2007 04:47:11

even if each component visually (model) is separate, you should use the cmpoundcollision system to make it all into 1 rigid body.

in the collision callback, you can determine which part collided and react accordingly.

oldfox

15-12-2007 12:29:44

It would be simple for the collision, but the idea is that every bodies has its own model. So if a part of a wing is detached, the plane would still behave correctly.

Dunno how to do it right without using this rigid joint... I'll do my first version with it and see how it works (or not :p )


If you have any other idea... :)