From 7850b3bb40bb894fc4ed8af58574c5763a5532f9 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 20 Apr 2015 16:34:41 +0200 Subject: [PATCH] Update --- HermiteTest/js/HermiteTest.js | 6 +++--- js/FixedCamera.js | 33 ++++++++++++++++++++------------- js/Hermite.js | 30 ++++++++++++++++++++++++++++++ js/ProgressiveSphere.js | 2 +- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/HermiteTest/js/HermiteTest.js b/HermiteTest/js/HermiteTest.js index 7ad1c9d..b969388 100644 --- a/HermiteTest/js/HermiteTest.js +++ b/HermiteTest/js/HermiteTest.js @@ -25,19 +25,19 @@ t = [0,1]; f = [0,1]; fp = [-1,-1]; -var hermite = new Hermite.Polynom(t, f, fp); +var hermite = new Hermite.special.Polynom(0, 1, -1); print('M = ['); for (var t = 0; t < 1; t += 0.01) { var res = hermite.eval(t); - print(t + ',' + toString(res) + ';'); + print("\t" + t + ',' + toString(res) + ';'); } print('];'); print('MP = ['); for (var t = 0; t < 1; t += 0.01) { var res = hermite.prime(t); - print(t + ',' + toString(res) + ';'); + print("\t" + t + ',' + toString(res) + ';'); } print('];'); diff --git a/js/FixedCamera.js b/js/FixedCamera.js index bcda238..086d77a 100644 --- a/js/FixedCamera.js +++ b/js/FixedCamera.js @@ -129,12 +129,12 @@ FixedCamera.prototype.update = function(mainCamera) { } // Update opacity - this.mesh.material.transparent = new_value < 0.9; - this.border.material.transparent = new_value < 0.9; - this.arrow.material.transparent = new_value < 0.9; - this.mesh.material.opacity = new_value; - this.border.material.opacity = new_value; - this.arrow.material.opacity = new_value; + this.object3D.traverse(function(elt) { + if (elt instanceof THREE.Mesh) { + elt.material.transparent = new_value < 0.9; + elt.material.opacity = new_value; + } + }); this.regenerateArrow(mainCamera); } @@ -151,9 +151,17 @@ FixedCamera.prototype.regenerateArrow = function(mainCamera) { var hermite = new Hermite.Polynom(t,f,fp); var up = this.up.clone(); - for (var i = this.fullArrow ? 0 : 0.5; i <= 1.001; i += 0.05) { - var point = hermite.eval(i); - var deriv = hermite.prime(i); + var point; + var deriv; + // for (var i = this.fullArrow ? 0 : 0.5; i <= 1.001; i += 0.05) { + for (var i = 1; this.fullArrow ? i > 0 : i > 0.5; i -= 0.05) { + point = hermite.eval(i); + deriv = hermite.prime(i); + up.cross(deriv); + up.cross(deriv); + up.multiplyScalar(-1); + up.normalize(); + var left = Tools.cross(up, deriv); left.normalize(); left.multiplyScalar(0.1); var other = Tools.cross(deriv, left); other.normalize(); other.multiplyScalar(0.1); @@ -166,10 +174,6 @@ FixedCamera.prototype.regenerateArrow = function(mainCamera) { } var faces = new Array(); - faces.push( - new THREE.Face3(0,1,2), - new THREE.Face3(0,2,3) - ); for (var i = 0; i < vertices.length - 4; i+= 4) { faces.push(new THREE.Face3(i,i+1,i+5),new THREE.Face3(i,i+5,i+4), @@ -178,6 +182,9 @@ FixedCamera.prototype.regenerateArrow = function(mainCamera) { new THREE.Face3(i,i+7,i+3), new THREE.Face3(i,i+4,i+7)); } + var len = vertices.length; + faces.push(new THREE.Face3(len-4,len-3,len-2), new THREE.Face3(len-4,len-2,len-1)); + this.arrow.geometry.vertices = vertices; this.arrow.geometry.faces = faces; diff --git a/js/Hermite.js b/js/Hermite.js index 4bb58f6..990cfcf 100644 --- a/js/Hermite.js +++ b/js/Hermite.js @@ -169,3 +169,33 @@ Hermite.BaseFunction.prototype.prime = function(t) { return this.eval(t) * ret; } + +Hermite.special = {}; + +// This polynom interpolates with two coords and one derivative +// t = [0,1] +Hermite.special.Polynom = function(P0, P1, PP1) { + this.tools = {}; + if (P0 instanceof THREE.Vector3) { + this.tools.sum = Tools.sum; + this.tools.mul = Tools.mul; + this.tools.diff = Tools.diff; + this.c = P0.clone(); + } else { + this.tools.sum = function(a,b) { return a+b; }; + this.tools.mul = function(a,b) { return a*b; }; + this.tools.diff = function(a,b) { return a-b; }; + this.c = P0; + } + + this.a = this.tools.sum(PP1, this.tools.diff(P0, P1)); + this.b = this.tools.diff(this.tools.mul(this.tools.diff(P1,P0), 2), PP1); +} + +Hermite.special.Polynom.prototype.eval = function(t) { + return this.tools.sum(this.tools.mul(this.a, t*t), this.tools.sum(this.tools.mul(this.b, t), this.c)); +} + +Hermite.special.Polynom.prototype.prime = function(t) { + return this.tools.sum(this.tools.mul(this.a,2*t), this.b); +} diff --git a/js/ProgressiveSphere.js b/js/ProgressiveSphere.js index 0ed4b97..9547645 100644 --- a/js/ProgressiveSphere.js +++ b/js/ProgressiveSphere.js @@ -10,7 +10,7 @@ var ProgessiveSphere = function(loader, res) { res = 5; (function(self) { - loader.load('/data/spheres/' + res + '.obj', function(object) { + loader.load(static_path + 'data/spheres/' + res + '.obj', function(object) { object.traverse(function(child) { if (child instanceof THREE.Mesh) { child.up = new THREE.Vector3(0,0,1);