Newton update world

marco565

26-04-2010 15:24:51

Hello, I use newton and ogre to make a racing game, I have one problem when I want update the world. I must put evt.timeSinceLastFrame if I wand have a correct render. If I dont put this value, the car have'nt fluid motion.

can you help me please.

koirat

26-04-2010 15:52:27

Try updating your physical world with a constant time, this time is not dependent of the graphic time update.
read this http://gafferongames.com/game-physics/fix-your-timestep/

marco565

26-04-2010 16:34:10

I have tried to implement with constant time, I have copied the code of the fuction update in OgreNewt but not done great.

if you have a camera that follow an object in move and you haven't this problem can you post a message.

thanks.

koirat

26-04-2010 22:21:32

So the car have not fluid motion or your camera following the car is not fluid ?

marco565

26-04-2010 22:27:51

is a car motion.

this is my code who update the world
int OgreNewtonPhysic::updateWorld(Ogre::Real time, Ogre::Real framerate, Ogre::Real speed)
{
static Ogre::Real mAccumulatedTime = 0;
Real timeStep = 1.0f/framerate;
int stepLimit = 7;
int currentStep = 0;
mAccumulatedTime += time;

while(mAccumulatedTime >= timeStep && currentStep <= stepLimit)
{
NewtonUpdate(mWorld, timeStep * speed);

if (currentStep == stepLimit)
mAccumulatedTime = 0.0f;
else
mAccumulatedTime -= timeStep;

currentStep++;
}


return currentStep;
}


I call the world update in this fonction
//S'occupe du rendu
void Course::update(Ogre::Real delta, OIS::Keyboard *keyboard, int volumeSon)
{
static float timer = 0;
timer -= delta;

//On met a jour la physique
int count = mPhysic->updateWorld(delta, FRAMERATE_GAME);

//for(int i=0; i<count; i++)
{
//On met a jour chaque pilote
for(int i=0; i<mPilotes.size(); i++)
{
mPilotes[i]->concours(delta, keyboard);
}

mPilotes[1]->controleManuelle2(delta, keyboard);



//quand on appui sur p on marque la position
if( keyboard->isKeyDown(OIS::KC_P) && timer <= 0 )
{
marquerPosition();
timer = 0.5;
}


//------------------------
//---Mettre a jour le son
//------------------------
//Changer le volume du son
mSonSys->setSoundVolume( (float)(volumeSon / 100.0) );
Vector3 posCam = mScene->getCamera("CameraPlayer")->getPosition();
Vector3 posCar = mPilotes[0]->getVoiture()->getVehiclePhysic()->getChassisNode()->getPosition();
irrklang::vec3df position( posCam.x, posCam.y, posCam.z );
irrklang::vec3df direction( posCar.x - posCam.x, posCar.y - posCam.y, posCar.z - posCam.z );

//changer la position du point d'ecoute du son
mSonSys->setListenerPosition(position, direction);
}


//try a camera motion but the result is good, the problem isn't camera.
//mPilotes[0]->getVoiture()->getVehiclePhysic()->getChassisNode()->translate(Vector3(0, 0, -40*delta));

//On fais suivre la voiture par la camera
mCamera->suivreObjet(delta);
}



my program struture

game //simple class who start root
---ExampleFrameListener
-------course.update //race render call in frameStarted
------------world update
------------vehicle update //not physic
------------ sound update


I have try to make 2 frameListener, one for physic and an other for all.

kallaspriit

01-05-2010 12:06:14

With the latest OgreNewt, you should not use accumulating, just set desired FPS using OgreNewt::World::setUpdateFPS() or in constructor and call world update in every frame. OgreNewt will make sure it updates the with desired FPS and also interpolate the graphics if no update is needed.

koirat

01-05-2010 17:04:59

@kallaspriit
Is this OgreNewt feature or Newton feature ?

kallaspriit

01-05-2010 17:53:52

This is a new OgreNewt feature :wink:

marco565

01-05-2010 20:20:01

Hello I have solve the probleme, I have aply the accumulator at all content of frameStarted. It works great