fix issue with interpolation in testbed application
This commit is contained in:
parent
e35db3f150
commit
28b7a0c059
|
@ -216,6 +216,7 @@ void Box::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the box
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -172,6 +172,7 @@ void Capsule::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the sphere
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -173,6 +173,8 @@ void Cone::updateTransform(float interpolationFactor) {
|
|||
transform,
|
||||
interpolationFactor);
|
||||
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the cone
|
||||
rp3d::decimal matrix[16];
|
||||
interpolatedTransform.getOpenGLMatrix(matrix);
|
||||
|
|
|
@ -211,6 +211,7 @@ void ConvexMesh::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the sphere
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -172,6 +172,7 @@ void Cylinder::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the cylinder
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -208,6 +208,7 @@ void Dumbbell::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the sphere
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -172,6 +172,7 @@ void Sphere::updateTransform(float interpolationFactor) {
|
|||
rp3d::Transform interpolatedTransform = rp3d::Transform::interpolateTransforms(mPreviousTransform,
|
||||
transform,
|
||||
interpolationFactor);
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Compute the transform used for rendering the sphere
|
||||
rp3d::decimal matrix[16];
|
||||
|
|
|
@ -37,6 +37,11 @@ struct EngineSettings {
|
|||
|
||||
float elapsedTime; // Elapsed time (in seconds)
|
||||
float timeStep; // Current time step (in seconds)
|
||||
|
||||
/// Constructor
|
||||
EngineSettings() : elapsedTime(0.0f), timeStep(0.0f) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Class Scene
|
||||
|
|
|
@ -52,6 +52,8 @@ TestbedApplication& TestbedApplication::getInstance() {
|
|||
// Constructor
|
||||
TestbedApplication::TestbedApplication() : mFPS(0), mNbFrames(0), mPreviousTime(0){
|
||||
|
||||
mCurrentScene = NULL;
|
||||
mEngineSettings.timeStep = DEFAULT_TIMESTEP;
|
||||
mIsMultisamplingActive = true;
|
||||
mWidth = 1000;
|
||||
mHeight = 800;
|
||||
|
@ -174,22 +176,26 @@ void TestbedApplication::updatePhysics() {
|
|||
mTimer.update();
|
||||
|
||||
// While the time accumulator is not empty
|
||||
while(mTimer.isPossibleToTakeStep()) {
|
||||
while(mTimer.isPossibleToTakeStep(mEngineSettings.timeStep)) {
|
||||
|
||||
// Take a physics simulation step
|
||||
mCurrentScene->updatePhysics();
|
||||
|
||||
// Update the timer
|
||||
mTimer.nextStep();
|
||||
mTimer.nextStep(mEngineSettings.timeStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestbedApplication::update() {
|
||||
|
||||
// Update the physics
|
||||
updatePhysics();
|
||||
|
||||
// Compute the interpolation factor
|
||||
float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep);
|
||||
assert(factor >= 0.0f && factor <= 1.0f);
|
||||
std::cout << "Factor : " << factor << std::endl;
|
||||
|
||||
// Notify the scene about the interpolation factor
|
||||
mCurrentScene->setInterpolationFactor(factor);
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include "Timer.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
// Constants
|
||||
const float DEFAULT_TIMESTEP = 1.0f / 60.0f;
|
||||
|
||||
/// Class TestbedApplication
|
||||
/// Singleton class representing the application.
|
||||
class TestbedApplication {
|
||||
|
|
|
@ -52,9 +52,6 @@ class Timer {
|
|||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Timestep dt of the physics engine (timestep > 0.0)
|
||||
double mTimeStep;
|
||||
|
||||
/// Last time the timer has been updated
|
||||
long double mLastUpdateTime;
|
||||
|
||||
|
@ -98,13 +95,13 @@ class Timer {
|
|||
bool isRunning() const;
|
||||
|
||||
/// True if it's possible to take a new step
|
||||
bool isPossibleToTakeStep() const;
|
||||
bool isPossibleToTakeStep(float timeStep) const;
|
||||
|
||||
/// Compute the time since the last update() call and add it to the accumulator
|
||||
void update();
|
||||
|
||||
/// Take a new step => update the timer by adding the timeStep value to the current time
|
||||
void nextStep();
|
||||
void nextStep(float timeStep);
|
||||
|
||||
/// Compute the interpolation factor
|
||||
float computeInterpolationFactor(float timeStep);
|
||||
|
@ -141,16 +138,16 @@ inline void Timer::stop() {
|
|||
}
|
||||
|
||||
// True if it's possible to take a new step
|
||||
inline bool Timer::isPossibleToTakeStep() const {
|
||||
return (mAccumulator >= mTimeStep);
|
||||
inline bool Timer::isPossibleToTakeStep(float timeStep) const {
|
||||
return (mAccumulator >= timeStep);
|
||||
}
|
||||
|
||||
// Take a new step => update the timer by adding the timeStep value to the current time
|
||||
inline void Timer::nextStep() {
|
||||
inline void Timer::nextStep(float timeStep) {
|
||||
assert(mIsRunning);
|
||||
|
||||
// Update the accumulator value
|
||||
mAccumulator -= mTimeStep;
|
||||
mAccumulator -= timeStep;
|
||||
}
|
||||
|
||||
// Compute the interpolation factor
|
||||
|
|
Loading…
Reference in New Issue
Block a user