From d74b0bdef7088923a71b45706a7403c61d2961b5 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Wed, 13 May 2015 09:11:54 +0200 Subject: [PATCH] PointerCamera take time into account --- static/js/CameraContainer.js | 4 ++-- static/js/PointerCamera.js | 8 ++++---- static/js/prototype/main.js | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/static/js/CameraContainer.js b/static/js/CameraContainer.js index 58e8883..b4edb20 100644 --- a/static/js/CameraContainer.js +++ b/static/js/CameraContainer.js @@ -31,8 +31,8 @@ CameraContainer.prototype.look = function() { this.mainCamera().look(); } -CameraContainer.prototype.updateMainCamera = function() { - this.pointerCamera.update(); +CameraContainer.prototype.updateMainCamera = function(time) { + this.pointerCamera.update(time); } CameraContainer.prototype.update = function(position) { diff --git a/static/js/PointerCamera.js b/static/js/PointerCamera.js index 31e3c15..b9f2fca 100644 --- a/static/js/PointerCamera.js +++ b/static/js/PointerCamera.js @@ -62,13 +62,13 @@ PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); PointerCamera.prototype.constructor = PointerCamera; // Update function -PointerCamera.prototype.update = function() { +PointerCamera.prototype.update = function(time) { if (this.moving) { this.linearMotion(); } else if (this.movingHermite) { this.hermiteMotion(); } else { - this.normalMotion(); + this.normalMotion(time); } } @@ -102,7 +102,7 @@ PointerCamera.prototype.hermiteMotion = function() { } } -PointerCamera.prototype.normalMotion = function() { +PointerCamera.prototype.normalMotion = function(time) { // Update angles if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; } if (this.decreasePhi) {this.phi -= this.sensitivity; this.changed = true; } @@ -136,7 +136,7 @@ PointerCamera.prototype.normalMotion = function() { left.multiplyScalar(400.0 * delta); // Move only if no collisions - var speed = this.speed; + var speed = this.speed * time / 60; var direction = new THREE.Vector3(); if (this.boost) speed *= 10; diff --git a/static/js/prototype/main.js b/static/js/prototype/main.js index 150395a..9234996 100644 --- a/static/js/prototype/main.js +++ b/static/js/prototype/main.js @@ -16,6 +16,7 @@ var loader; var coins; var beenFullscreen = false; var isFullscreen = false; +var previousTime; var main_section = document.getElementById('main-section'); var offset = function() { @@ -196,6 +197,7 @@ function stopFullscreen() { } function render() { + var currentTime = Date.now() - previousTime; cameraSelecter.update(); // Update recommendations (set raycastable if shown) @@ -214,11 +216,13 @@ function render() { coins.forEach(function(coin) { coin.update(); }); // Update main camera - cameras.updateMainCamera(); + cameras.updateMainCamera(currentTime); // Update the recommendations cameras.update(cameras.mainCamera()); + previousTime = Date.now(); + // Set current position of camera cameras.look();