Speed changes with framerates.

Nudel

06-11-2006 16:35:45

Using the search, ive found 2 possible solutions to make newton update its scenes at the same speed at different frame rates. A time slicer and lower values for linear and angular damping. Im using the basic frame listener with its time slicer and ive lowered the dampin values to 0.001 and Vector3(0.001,0.001,0.001).
There is still a very noticable difference in speed however. Ive run my application in debug(~15fps) and release mode(~100fps) in order to test it with different frame rates. In debug mode, the character moved about half as fast as in release mode.

Here a small part of the newton frame listener logs:

Debug Mode:

17:10:36: Newton Frame Listener... m_elapsed: 0 m_update:0.0166667
17:10:36: Newton updates this loop: 0
17:10:36: Newton Frame Listener... m_elapsed: 0.185 m_update:0.0166667
17:10:36: Newton updates this loop: 11
17:10:37: Newton Frame Listener... m_elapsed: 0.0986667 m_update:0.0166667
17:10:37: Newton updates this loop: 5
17:10:37: Newton Frame Listener... m_elapsed: 0.0853334 m_update:0.0166667
17:10:37: Newton updates this loop: 5
17:10:37: Newton Frame Listener... m_elapsed: 0.065 m_update:0.0166667
17:10:37: Newton updates this loop: 3
17:10:37: Newton Frame Listener... m_elapsed: 0.087 m_update:0.0166667
17:10:37: Newton updates this loop: 5
17:10:37: Newton Frame Listener... m_elapsed: 0.0686667 m_update:0.0166667
17:10:37: Newton updates this loop: 4
17:10:37: Newton Frame Listener... m_elapsed: 0.065 m_update:0.0166667
17:10:37: Newton updates this loop: 3


Release Mode:

17:08:52: Newton Frame Listener... m_elapsed: 0 m_update:0.0166667
17:08:52: Newton updates this loop: 0
17:08:52: Newton Frame Listener... m_elapsed: 0.247 m_update:0.0166667
17:08:52: Newton updates this loop: 14
17:08:52: Newton Frame Listener... m_elapsed: 0.0616667 m_update:0.0166667
17:08:52: Newton updates this loop: 3
17:08:52: Newton Frame Listener... m_elapsed: 0.0196667 m_update:0.0166667
17:08:52: Newton updates this loop: 1
17:08:52: Newton Frame Listener... m_elapsed: 0.011 m_update:0.0166667
17:08:52: Newton updates this loop: 0
17:08:52: Newton Frame Listener... m_elapsed: 0.018 m_update:0.0166667
17:08:52: Newton updates this loop: 1


And this is the force callback for the character movement(from one of walabers posts with little modifications.)

void MachbarkeitsstudieFrameListener::richtungsForceCallback(OgreNewt::Body* bod)
{
Ogre::Real mass;
Ogre::Vector3 inertia;
Ogre::Real desiredVelocity = 0.030;
Ogre::String debugInfo = "\n";

Ogre::Vector3 V0 = bod->getVelocity();
Ogre::Vector3 V1 = richtung*richtung.normalise();
V1 = V1*desiredVelocity;
debugInfo += "\tV0: " + Ogre::StringConverter::toString(V0) + "\n";
debugInfo += "\tV1: " + Ogre::StringConverter::toString(V1) + "\n";
debugInfo += "\tTimestep: " + Ogre::StringConverter::toString(bod->getWorld()->getTimeStep());
Ogre::LogManager::getSingleton().getLog("Prototyp.log")->logMessage(debugInfo);

Ogre::Vector3 acel((V1-V0)/bod->getWorld()->getTimeStep());
acel *= 0.3f;

bod->getMassMatrix(mass, inertia);
Ogre::Vector3 force(acel.x,-9.81,acel.z);
force *= mass;

bod->addForce(force);

// heading forces.
Ogre::Vector3 goalHeading = mCamera->getDerivedDirection();
goalHeading.y = 0.0f;
goalHeading.normalise();

Ogre::Vector3 curHeading = bod->getOgreNode()->getOrientation() * Ogre::Vector3::UNIT_Z;

// angle between these vectors.
Ogre::Degree delta_o = Ogre::Math::ACos( curHeading.dotProduct( goalHeading ) );
Ogre::Vector3 rot_axis = curHeading.crossProduct( goalHeading ).normalisedCopy();
Ogre::Vector3 tAdd = (rot_axis * delta_o.valueDegrees() * 40.0f) - (bod->getOmega()*100.0f);
bod->addTorque(tAdd);
}

Does anyone know, what the problem might be?