Gravity not properly working

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Gravity not properly working

Postby agsh » Tue Jul 14, 2009 6:22 am

Hi all,

I'm trying to implement a flight simulation but I've notice my objects does not act correctly. In free fall, the objects increase their velocities up to approximately 5 m/s. Then, they begin to slow down until they reach a constant velocity of 6.7 m/s. Strangely, in debug mode the speed reach to 66 m/s and then it remains constant. :? I can't find what I'm doing wrong. :(

I'm using NGD 1.53 through OgreNewt and the code involved is the following
Code: Select all
OgreNewt::Body* PhysicEngine::makeBody(Ogre::SceneNode* sceneNode, float mass, Ogre::Vector3 centerOfGravity)
{
    OgreNewt::ConvexCollision* col = new OgreNewt::CollisionPrimitives::ConvexHull(mWorld, sceneNode );
    Ogre::Vector3 calculatedInertia;
    Ogre::Vector3 calculatedCenterOfGravity;
    col->calculateInertialMatrix(calculatedInertia,calculatedCenterOfGravity );
   
    OgreNewt::Body* bod = new OgreNewt::Body( mWorld, col );
    delete col;

    bod->attachToNode( sceneNode );
    if(mass!=0)
    {
        bod->setMassMatrix( mass , calculatedInertia );
        bod->setCenterOfMass(centerOfGravity);       
    }
    return bod;
}

mBody = PhysicEngine::getSingleton().makeBody( this->getSceneNode(), mass, mRotationLocalToGlobal * this->mLocalGravityCenter );
mBody->setStandardForceCallback();
mBody->setAutoFreeze(0);

Where mass=100, the body is a cube (1x1x1) and

Code: Select all
void Body::standardForceCallback( OgreNewt::Body* me )
{
   //apply a simple gravity force.
   Ogre::Real mass;
   Ogre::Vector3 inertia;

   me->getMassMatrix(mass, inertia);
   Ogre::Vector3 force(0,-9.8,0);
   force *= mass;

   me->addForce( force );
}


Hope you can help me.

Thanks in advance,
Alberto
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Gravity not properly working

Postby kallaspriit » Tue Jul 14, 2009 6:34 am

Newton applies linear damping that is proportional to the square of the magnitude of the velocity to the body in the opposite direction of the velocity of the body. I am guessing that at certain speed, the gravity is cancelled out by the opposite damping force, the same actually happens is real world where the damping is caused by air drag and when an object falls from the sky, it will not speed up indefenately but reach certain speed - terminal velocity - and remain at that speed.

In debug mode, you are probably getting much less FPS so the damping is applied less times so it will cancel out gravity at larger speed :P
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: Gravity not properly working

Postby JernejL » Tue Jul 14, 2009 7:55 am

you can simply set the dampening to zero and objects will continue going on likely accelerating forever.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Gravity not properly working

Postby agsh » Tue Jul 14, 2009 9:14 am

Many thanks kallaspriit and Delfi for so quick replies! That was the problem. I though the damping had to do with slow moving objets.
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm

Re: Gravity not properly working

Postby JernejL » Tue Jul 14, 2009 10:29 am

just note that there's not only linear dampening but also a angular one, if you want precise control over everything you should set both to zero.

Slow moving objects have autofreeze, which stops simulation when they are not moving, you probably meant that?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Gravity not properly working

Postby agsh » Tue Jul 14, 2009 12:24 pm

Delfi wrote:Slow moving objects have autofreeze, which stops simulation when they are not moving, you probably meant that?

I knew I had read something about that but, as you probably have noticed, I was a bit messed about that concepts. :roll: Many thanks again for your help!
agsh
 
Posts: 11
Joined: Fri Apr 17, 2009 12:26 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron