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
Callback
Players
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
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
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 );
Callback
void 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
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