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();
}
CameraContainer.prototype.updateMainCamera = function() {
this.pointerCamera.update();
CameraContainer.prototype.updateMainCamera = function(time) {
this.pointerCamera.update(time);
}
CameraContainer.prototype.update = function(position) {

View File

@ -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;

View File

@ -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();