Moderators: Sascha Willems, walaber
m_elapsed += evt.timeSinceLastFrame;
int count = 0;
// loop through and update as many times as necessary (up to 10 times maximum).
if ((m_elapsed > m_update) && (m_elapsed < (m_update * 10)) )
{
while (m_elapsed > m_update)
{
m_World->update( m_update );
m_elapsed -= m_update;
count++;
}
}
else
{
if (m_elapsed < (m_update))
{
// not enough time has passed this loop, so ignore for now.
}
else
{
// too much time has passed (would require more than 10 updates!), so just update once and reset.
// this often happens on the first frame of a game, where assets and other things were loading, then
// the elapsed time since the last drawn frame is very long.
m_World->update( m_elapsed );
count++;
m_elapsed = 0.0f; // reset the elapsed time so we don't become "eternally behind".
}
}
m_World->update( evt.timeSinceLastFrame ); :roll:
if (m_timestep > 1.0f / 60.0f) {
//m_timestep = 1.0 / 60.0f;
}
void World::update( Ogre::Real t_step )
{
// clean up all pending bodies for update
for( BodyVectorVector::iterator it = m_bodyUpdateNodeRequests.begin(); it != m_bodyUpdateNodeRequests.end(); it++ )
{
for( BodyVector::iterator body = it->begin(); body != it->end(); body++ )
{
(*body)->SetNodeUpdateState (false);
}
it->clear();
}
#ifdef _DEBUG
// Ogre::LogManager::getSingleton().logMessage(" Newton Frame Listener... m_elapsed: "+Ogre::StringConverter::toString( t_step)+
// " m_update:"+Ogre::StringConverter::toString(m_update));
#endif
// clamp thE step if necessary
if (t_step > (m_timestep * m_maxTicksPerFrames)) {
t_step = m_timestep * m_maxTicksPerFrames;
}
// advance the accumulator;
m_timeAcumulator += t_step;
while (m_timeAcumulator >= m_timestep) {
NewtonUpdate (m_world, m_timestep);
m_timeAcumulator -= m_timestep;
}
#ifdef _DEBUG
// Ogre::LogManager::getSingleton().logMessage(" Newton updates this loop: "+Ogre::StringConverter::toString(count));
#endif
Ogre::Real param = m_timeAcumulator * m_invTimestep;
//if (param < 0.999)
//param = 1.0f;
for( BodyVectorVector::iterator it = m_bodyUpdateNodeRequests.begin(); it != m_bodyUpdateNodeRequests.end(); it++ )
{
for( BodyVector::iterator body = it->begin(); body != it->end(); body++ )
{
(*body)->updateNode(param);
}
}
}
if (m_timestep > 1.0f / 60.0f) {
//m_timestep = 1.0 / 60.0f; //< Comment this out
}
mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 10 );
void OgreNewtonApplication::createFrameListener()
{
mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 10 );
mRoot->addFrameListener(mNewtonListener);
mFrameListener = new OgreNewtonFrameListener( mWindow, mCamera, mSceneMgr, m_World);
mRoot->addFrameListener(mFrameListener);
}
void World::SetUpdateFPS(Ogre::Real desiredFps, int maxUpdatesPerFrames)
{
if (maxUpdatesPerFrames < 2) {
maxUpdatesPerFrames = 2;
}
if (maxUpdatesPerFrames > 5) {
maxUpdatesPerFrames = 5;
}
m_maxTicksPerFrames = maxUpdatesPerFrames;
m_timestep = 1.0f / desiredFps;
if (m_timestep > 1.0f / 60.0f) {
m_timestep = 1.0 / 60.0f;
}
if (m_timestep < 1.0f / 1000.0f) {
m_timestep = 1.0 / 1000.0f;
}
m_invTimestep = 1.0f / m_timestep;
m_timeAcumulator = m_timestep;
}
m_timestep = 1.0f / desiredFps;
if (m_timestep > 1.0f / 60.0f) {
// recalculate the iteration count to met the desire fps
m_maxTicksPerFrames += ceilf (m_timestep / (1.0f / 60.0f));
m_timestep = 1.0 / 60.0f;
}
kallaspriit wrote:try to place the resources in the correct folders - demos\media\primitives should only contain the collision primitives, not models like the car, place those in demos\media\models. Also place .material files in media\materials\scripts and textures in demos\media\materials\textures
Users browsing this forum: No registered users and 0 guests