Skip to content
Snippets Groups Projects
Commit 7da46bca authored by dsehnal's avatar dsehnal
Browse files

scale move speed by frametime

parent 00ff1a1e
Branches
No related tags found
No related merge requests found
...@@ -371,11 +371,11 @@ namespace TrackballControls { ...@@ -371,11 +371,11 @@ namespace TrackballControls {
const moveDir = Vec3(); const moveDir = Vec3();
const moveEye = Vec3(); const moveEye = Vec3();
function moveCamera() { function moveCamera(deltaT: number) {
Vec3.sub(moveEye, camera.position, camera.target); Vec3.sub(moveEye, camera.position, camera.target);
Vec3.setMagnitude(moveEye, moveEye, camera.state.minNear); Vec3.setMagnitude(moveEye, moveEye, camera.state.minNear);
const moveSpeed = p.moveSpeed * (keyState.boostMove === 1 ? p.boostMoveFactor : 1); const moveSpeed = deltaT * (60 / 1000) * p.moveSpeed * (keyState.boostMove === 1 ? p.boostMoveFactor : 1);
if (keyState.moveForward === 1) { if (keyState.moveForward === 1) {
Vec3.normalize(moveDir, moveEye); Vec3.normalize(moveDir, moveEye);
...@@ -483,9 +483,11 @@ namespace TrackballControls { ...@@ -483,9 +483,11 @@ namespace TrackballControls {
/** Update the object's position, direction and up vectors */ /** Update the object's position, direction and up vectors */
function update(t: number) { function update(t: number) {
if (lastUpdated === t) return; if (lastUpdated === t) return;
const deltaT = t - lastUpdated;
if (lastUpdated > 0) { if (lastUpdated > 0) {
if (p.animate.name === 'spin') spin(t - lastUpdated); if (p.animate.name === 'spin') spin(deltaT);
else if (p.animate.name === 'rock') rock(t - lastUpdated); else if (p.animate.name === 'rock') rock(deltaT);
} }
Vec3.sub(_eye, camera.position, camera.target); Vec3.sub(_eye, camera.position, camera.target);
...@@ -501,7 +503,9 @@ namespace TrackballControls { ...@@ -501,7 +503,9 @@ namespace TrackballControls {
Vec3.add(camera.position, camera.target, _eye); Vec3.add(camera.position, camera.target, _eye);
checkDistances(); checkDistances();
moveCamera(); if (lastUpdated > 0 && deltaT < 1000) {
moveCamera(deltaT);
}
Vec3.sub(_eye, camera.position, camera.target); Vec3.sub(_eye, camera.position, camera.target);
checkDistances(); checkDistances();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment