From 2dccb1eede73f06067faf794bb5523165c187e11 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 12 May 2015 10:03:45 +0200 Subject: [PATCH] First attempt to correct U-turn arrows --- controllers/prototype/views/prototype.jade | 4 ++- static/js/prototype/ArrowCamera.js | 33 ++++++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/controllers/prototype/views/prototype.jade b/controllers/prototype/views/prototype.jade index 5fd9d4d..aa997b1 100644 --- a/controllers/prototype/views/prototype.jade +++ b/controllers/prototype/views/prototype.jade @@ -58,8 +58,10 @@ block content input#collisions(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked) label(for="collisions" style={'margin-right':'10px'}) Collisions - input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked) label(for="showarrows" style={'margin-right':'10px'}) Show arrows + //- audio(controls, autoplay) + //- source(src="/static/data/music/bobomb.mp3") + #container(style={'padding': '0px', 'margin': '0px'}, tabindex="1") diff --git a/static/js/prototype/ArrowCamera.js b/static/js/prototype/ArrowCamera.js index 402ba12..7c19e40 100644 --- a/static/js/prototype/ArrowCamera.js +++ b/static/js/prototype/ArrowCamera.js @@ -117,18 +117,35 @@ ArrowCamera.prototype.update = function(mainCamera) { ArrowCamera.prototype.regenerateArrow = function(mainCamera) { var vertices = new Array(); - var t = [0,1]; + + // First point of curve var f0 = mainCamera.position.clone(); f0.add(Tools.sum(Tools.mul(this.up,-1), Tools.diff(this.target, this.position).normalize())); - var f = [Tools.sum(mainCamera.position, Tools.diff(this.target, this.position)).normalize(), this.position.clone()]; - var first = Tools.diff(mainCamera.target, mainCamera.position); - first.normalize(); + // Last point of curve + var f1 = this.position.clone(); - var fp = [Tools.mul(first,40), Tools.diff(this.target, this.position)]; - fp[1].normalize(); - fp[1].multiplyScalar(4); - var hermite = new Hermite.special.Polynom(f0, f[1], fp[1]); + // Last derivative of curve + var fp1 = Tools.diff(this.target, this.position); + fp1.normalize(); + + // Camera direction + var dir = Tools.diff(this.position, mainCamera.position); + dir.normalize(); + + if (fp1.dot(dir) < -0.5) { + // Regen polynom with better stuff + var new_dir = Tools.cross(Tools.diff(this.position, mainCamera.position).normalize(), mainCamera.up); + new_dir.multiplyScalar(new_dir.dot(fp1) < 0 ? 1 : -1); + new_dir.add(dir); + new_dir.add(dir); + new_dir.multiplyScalar(2); + f0.add(new_dir); + } + + fp1.multiplyScalar(4); + + var hermite = new Hermite.special.Polynom(f0, f1, fp1); var up = this.up.clone(); var point;