lol? What's going on? Physics acting crazy

h3x0g3n

15-08-2006 21:30:21

Ok first of all, here you can see a little draft of my problem. A ball is falling from very high onto another ball, which can't move. And after that it is falling on the ground, but goes backward, not forward? Crazy!


And here you can see it in action: Movie
The balls are made of ellipsoid collision objects and the ground is made of an box collision object.

Does anyone has an idea, why this is happening and how to solve it?
Thanks!

lonwolf

16-08-2006 11:00:47

well in the real world this would be unlikely to happen. But can you post your code? Becoz, i think u didnt created some materilas for the balls and ground. I suggest you creat a OgreNewt material pair and set its friction 0 and elasticity lets say about 0.5 and then see whats the result.. It may be becoz of high friction between the balls and ground, and too heavy mass. I cant say pretty sure untill i see what parameters you've set t the falling ball, and what gravity u have... Its just becoz of some wrong parameters i guess

And i suggest stop showing bodyes every frame becoz this kills the frame-rate. I sugest u make it toggle-able, just to see if the bodyes are in place. If u want to make a larger, more complex simulation, get rid of recreating every frame the OgreNewt::Debuger... :?

h3x0g3n

16-08-2006 12:09:25

Here are my Materials:

mMatBlobby = new OgreNewt::MaterialID( mWorld );
mMatBall = new OgreNewt::MaterialID( mWorld );
mMatBoden = new OgreNewt::MaterialID( mWorld );
mMatSpielfeld = new OgreNewt::MaterialID( mWorld );

mMatPairBallBlobby = new OgreNewt::MaterialPair( mWorld, mMatBall, mMatBlobby );
CollisionDetectionBallBlobby = new TCollisionDetectionBallBlobby( BT_Ball );
mMatPairBallBlobby->setContactCallback( CollisionDetectionBallBlobby );
mMatPairBallBlobby->setDefaultFriction( 1.5, 1.4 );

Player[0][0] = new TPlayer(mSceneMgr,mWorld,mMatBlobby, "Player00", Vector3(100,+100,0),BT_Spieler00);
//Player[0][1] = new TPlayer(mSceneMgr,mWorld,mMatBlobby, "Player01", Vector3(+5,+100,0));

Ball = new TBall(mSceneMgr,mWorld,mMatBall, "Ball", Vector3(0,20,0));
Ball = new TBall(mSceneMgr,mWorld,mMatBall, "Ball2", Vector3(2,300,0));
Boden = new TBoden(mSceneMgr,mWorld,mMatBoden, "Boden", Vector3(0,0,0));
Spielfeld = new TSpielfeld(mSceneMgr,mWorld,mMatSpielfeld, "Spielfeld", Vector3(0,0,0));

This is how I create my Objects

void TModel::init(void)
{

mSceneNode = mMutterNode->createChildSceneNode(mBezeichnung);
if(mDateiName!="")
{
mEntity = mSceneMgr->createEntity( mBezeichnung, mDateiName );
mSceneNode->attachObject(mEntity);
}


//NEWTON
OgreNewt::Collision* col = createCollision();

phBody = new OgreNewt::Body( mWorld, col ,BT);
if(mMat!=NULL)
phBody->setMaterialGroupID( mMat );

phBody->setUserData(&A);

phBody->attachToNode( mSceneNode );
if(!surface)
setmyMassMatrix();

if(!surface)
phBody->setCustomForceAndTorqueCallback(fastdelegate::MakeDelegate( this, &TModel::gravity));
delete col;
//NEWTON ENDE

//TO BE REPLACED BY FUNCTION
phBody->setPositionOrientation( mPos , Ogre::Quaternion::IDENTITY );

}

void TModel::gravity(OgreNewt::Body* bod)
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;
bod->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,gravitation,0);
force *= mass;
Ogre::Vector3 luftwiderstand = bod->getVelocity()*bod->getVelocity()* *static_cast<float*>(bod->getUserData())*Widerstand;
force=force+luftwiderstand;
bod->addForce( force );
}

This are the overloaded funtcions in TBall

void TBall::setmyMassMatrix(void)
{
Ogre::Real mass = 0.160;//bis 0.280
phBody->setMassMatrix( mass, OgreNewt::MomentOfInertia::CalcSphereSolid( mass,radiusiU*radiusiU) );
}
//-------------------------------------------------------------------------------------------------------------------------
OgreNewt::Collision *TBall::createCollision(void)
{
mSceneNode->scale(Vector3(2,2,2));
return new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, Ogre::Vector3(radiusiU,radiusiU,radiusiU) );
}

And the floor:

void TBoden::setmyMassMatrix(void)
{

}
//-------------------------------------------------------------------------------------------------------------------------
OgreNewt::Collision *TBoden::createCollision(void)
{
return new OgreNewt::CollisionPrimitives::Box( mWorld, Ogre::Vector3(SFLaenge,1,SFBreite) );
}


Anything wrong? I hope so ;-)

lonwolf

16-08-2006 12:54:16

OMG :o no wonder your ball is stuck to the ground :lol:
change this line
mMatPairBallBlobby->setDefaultFriction( 1.5, 1.4 );
with this one
mMatPairBallBlobby->setDefaultFriction( 0.0f, 0.0f);
and add another after it:
mMatPairBallBlobby->setDefaultElasticity(0.5f);
this will make the ground material "bouncy" and will not attempt to stop the ball with friction forces when it hits. Try it :wink: im waitin 4 the result :roll:

h3x0g3n

16-08-2006 13:15:47

Hey lonwolf ;-)
Thanks for your fast answer! But you have overseen that this is the materialpair of the Blobby and the Ball, not the Ball and the Boden.
Nevertheless I have created a material pair mMatPairBallBoden and have adjusted the fritction and elasticity, like you described, and now IT WORKS!!!
I think it was because my default settings are wrong. So I have one last question: How can I adjust the default friction and elasticity!

Great Thanks to lonwolf

lonwolf

16-08-2006 13:24:24

Well the default friction and elasticity are applied by newton/OgreNewt. If u want to see them i suggest you look throughout theyr code. But there are some values that new bodyes inherit and i believe you cannot change them unless you recompile OgreNewt with your changes. But the simple and fast way to resolve this "problem" it to create 2 materials, one for your character/ball and one for the ground, create a material pair and play with friction and elasticity. And if u insert another object that you want to react like the ground, ex: a building, just set the material youve det to the ground, set it to the building. Im doing the same. And you dont need to create thousands of material pairs unless you want to change the material. Thats all i know about them :wink:

h3x0g3n

16-08-2006 13:34:43

Ok thanks a lot :mrgreen: !!!

lonwolf

16-08-2006 13:39:11

no prob, if u have anymore questions about OgreNewt and Ogre you can post them here (im watching this topic by mail :) ) or pm me. Ill be glad to help anyone.. Becoz were workin on a game and in one month it should be ready, so i know pretty well something about these enginges :D