Skip to content

Commit

Permalink
pause support for interpolation in demos
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Apr 4, 2015
1 parent 4624d1e commit 379a809
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions demos/js/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Object.defineProperty(Renderer.prototype, 'paused', {
return this.settings['paused [p]'];
},
set: function(value) {
this.resetCallTime = true;
this.settings['paused [p]'] = value;
this.updateGUI();
}
Expand Down Expand Up @@ -266,7 +267,7 @@ Renderer.prototype.setupGUI = function() {
that.paused = p;
});
worldFolder.add(settings, 'manualStep [s]');
worldFolder.add(settings, 'fps', 10, 60*10).step(60).onChange(function(freq){
worldFolder.add(settings, 'fps', 10, 60*10).step(10).onChange(function(freq){
that.timeStep = 1 / freq;
});
worldFolder.add(settings, 'maxSubSteps', 0, 10).step(1);
Expand Down Expand Up @@ -532,7 +533,11 @@ Renderer.prototype.startRenderingLoop = function(){
function update(){
if(!demo.paused){
var now = Date.now() / 1000,
timeSinceLastCall = now-lastCallTime;
timeSinceLastCall = now - lastCallTime;
if(demo.resetCallTime){
timeSinceLastCall = 0;
demo.resetCallTime = false;
}
lastCallTime = now;
demo.world.step(demo.timeStep, timeSinceLastCall, demo.settings.maxSubSteps);
}
Expand Down
4 changes: 2 additions & 2 deletions demos/js/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ WebGLRenderer.prototype.drawPath = function(g,path,color,fillColor,lineWidth,isS
};

WebGLRenderer.prototype.updateSpriteTransform = function(sprite,body){
if(this.useInterpolatedPositions){
if(this.useInterpolatedPositions && !this.paused){
sprite.position.x = body.interpolatedPosition[0];
sprite.position.y = body.interpolatedPosition[1];
sprite.rotation = body.interpolatedAngle;
Expand Down Expand Up @@ -634,7 +634,7 @@ WebGLRenderer.prototype.render = function(){
bA = s.bodyA,
bB = s.bodyB;

if(this.useInterpolatedPositions){
if(this.useInterpolatedPositions && !this.paused){
p2.vec2.toGlobalFrame(worldAnchorA, s.localAnchorA, bA.interpolatedPosition, bA.interpolatedAngle);
p2.vec2.toGlobalFrame(worldAnchorB, s.localAnchorB, bB.interpolatedPosition, bB.interpolatedAngle);
} else {
Expand Down

0 comments on commit 379a809

Please sign in to comment.