From cb2c9360d2d0a05112f1adfa0d0e6c360b31b013 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 5 May 2015 16:52:39 +0200 Subject: [PATCH] Merge 2389763c5f0912f4d15f832194214a3a996b049c Author: Thomas FORGIONE Date: Tue May 5 16:49:00 2015 +0200 Added movement with angle with arrows --- static/js/PointerCamera.js | 43 ++++++++++++++++++++++++++++++ static/js/prototype/arrows/main.js | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/static/js/PointerCamera.js b/static/js/PointerCamera.js index f176b5e..55399f6 100644 --- a/static/js/PointerCamera.js +++ b/static/js/PointerCamera.js @@ -77,6 +77,21 @@ PointerCamera.prototype.update = function() { this.anglesFromVectors(); } + } else if (this.movingHermite) { + // Hermite polynom version + var eval = this.hermitePosition.eval(this.t); + this.position.x = eval.x; + this.position.y = eval.y; + this.position.z = eval.z; + + this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t)); + + this.t += 0.005; + + if (this.t > 1) { + this.movingHermite = false; + this.anglesFromVectors(); + } } else { // Update angles if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; } @@ -181,6 +196,34 @@ PointerCamera.prototype.move = function(otherCamera, toSave) { } } +PointerCamera.prototype.moveHermite = function(otherCamera, toSave) { + if (toSave === undefined) + toSave = true; + + this.movingHermite = true; + this.t = 0; + + this.hermitePosition = new Hermite.special.Polynom( + this.position.clone(), + otherCamera.position.clone(), + Tools.diff(otherCamera.target, otherCamera.position) + ); + + this.hermiteAngles = new Hermite.special.Polynom( + Tools.diff(this.target, this.position), + Tools.diff(otherCamera.target, otherCamera.position), + new THREE.Vector3() + ); + + if (toSave) { + if (this.changed) { + this.save(); + this.changed = false; + } + this.history.addState({position: otherCamera.position.clone(), target: otherCamera.target.clone()}); + } +} + PointerCamera.prototype.isColliding = function(direction) { this.raycaster.set(this.position, direction.clone().normalize()); var intersects = this.raycaster.intersectObjects(this.collidableObjects, true); diff --git a/static/js/prototype/arrows/main.js b/static/js/prototype/arrows/main.js index 1fffe41..da6c657 100644 --- a/static/js/prototype/arrows/main.js +++ b/static/js/prototype/arrows/main.js @@ -505,7 +505,7 @@ function updateMouse(event) { function click(event) { var newCamera = pointedCamera(event); if (newCamera !== undefined) { - cameras.mainCamera().move(newCamera); + cameras.mainCamera().moveHermite(newCamera); updateElements(); } }