PointerCamera take time into account

This commit is contained in:
Thomas FORGIONE 2015-05-13 09:11:54 +02:00
parent e82ce7fa57
commit d74b0bdef7
3 changed files with 11 additions and 7 deletions

View File

@ -31,8 +31,8 @@ CameraContainer.prototype.look = function() {
this.mainCamera().look(); this.mainCamera().look();
} }
CameraContainer.prototype.updateMainCamera = function() { CameraContainer.prototype.updateMainCamera = function(time) {
this.pointerCamera.update(); this.pointerCamera.update(time);
} }
CameraContainer.prototype.update = function(position) { CameraContainer.prototype.update = function(position) {

View File

@ -62,13 +62,13 @@ PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
PointerCamera.prototype.constructor = PointerCamera; PointerCamera.prototype.constructor = PointerCamera;
// Update function // Update function
PointerCamera.prototype.update = function() { PointerCamera.prototype.update = function(time) {
if (this.moving) { if (this.moving) {
this.linearMotion(); this.linearMotion();
} else if (this.movingHermite) { } else if (this.movingHermite) {
this.hermiteMotion(); this.hermiteMotion();
} else { } 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 // Update angles
if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; } if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; }
if (this.decreasePhi) {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); left.multiplyScalar(400.0 * delta);
// Move only if no collisions // Move only if no collisions
var speed = this.speed; var speed = this.speed * time / 60;
var direction = new THREE.Vector3(); var direction = new THREE.Vector3();
if (this.boost) speed *= 10; if (this.boost) speed *= 10;

View File

@ -16,6 +16,7 @@ var loader;
var coins; var coins;
var beenFullscreen = false; var beenFullscreen = false;
var isFullscreen = false; var isFullscreen = false;
var previousTime;
var main_section = document.getElementById('main-section'); var main_section = document.getElementById('main-section');
var offset = function() { var offset = function() {
@ -196,6 +197,7 @@ function stopFullscreen() {
} }
function render() { function render() {
var currentTime = Date.now() - previousTime;
cameraSelecter.update(); cameraSelecter.update();
// Update recommendations (set raycastable if shown) // Update recommendations (set raycastable if shown)
@ -214,11 +216,13 @@ function render() {
coins.forEach(function(coin) { coin.update(); }); coins.forEach(function(coin) { coin.update(); });
// Update main camera // Update main camera
cameras.updateMainCamera(); cameras.updateMainCamera(currentTime);
// Update the recommendations // Update the recommendations
cameras.update(cameras.mainCamera()); cameras.update(cameras.mainCamera());
previousTime = Date.now();
// Set current position of camera // Set current position of camera
cameras.look(); cameras.look();