Commit 7bacd2cb authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Accuracy of the animation frame timer improved.

parent a8491a88
......@@ -859,7 +859,7 @@ void GLViewer::manageAnimations()
if( !m_ActiveAnimations.contains(anim) )
{
m_ActiveAnimations[anim] = 0.0f;
m_ActiveAnimations[anim] = 0.0;
anim->onAnimationStart();
}
}
......@@ -893,11 +893,21 @@ void GLViewer::manageAnimations()
}
// Make all active animated objects to execute a new animation step.
// Accurate measurement of the time elapsed since the last animation step.
double dt = 0.0;
QTime currentTime = QTime::currentTime();
float dt = 0.001f * m_AnimationFrameTime.msecsTo( currentTime );
m_AnimationFrameTime = currentTime;
if( m_AnimationsRunningAtPreviousFrame )
{
TimeMeasurement now = std::chrono::high_resolution_clock::now();
dt = 0.000001 * std::chrono::duration_cast< std::chrono::microseconds >( now - m_AnimationFrameTime ).count();
m_AnimationFrameTime = now;
}
else
m_AnimationFrameTime = std::chrono::high_resolution_clock::now();
// Make all active animated objects to execute a new animation step.
if( animationsRunning )
{
......
......@@ -13,6 +13,7 @@
#include "../GPU/GPU.h"
#include "DisplayableInterface.h"
#include <set>
#include <chrono>
#include "MetricGrid.h"
#include "PickedPoint.h"
#include "UIData.h"
......@@ -70,6 +71,9 @@ protected:
typedef std::map<int,DisplayableList> PriorityMap;
typedef std::map<const GenericUIData*,DisplayableInfo> DisplayableMap;
using TimeMeasurement = std::chrono::high_resolution_clock::time_point;
class DisplayableInfo
{
QMatrix4x4 userTransform;
......@@ -135,8 +139,8 @@ protected:
QList<DisplayableInterface*> m_AnimationStartingQueue;
QList<DisplayableInterface*> m_AnimationStoppingQueue;
QTime m_AnimationFrameTime;
QMap<DisplayableInterface*,float> m_ActiveAnimations;
TimeMeasurement m_AnimationFrameTime;
QMap<DisplayableInterface*,double> m_ActiveAnimations;
bool m_AnimationsRunningAtPreviousFrame;
bool m_SelectionEnabled;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment