From bdb975e2f0b23242a3e70d01c34ab5bbefeb9b70 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 13 Apr 2015 10:11:42 +0200 Subject: [PATCH] Camera disappears progressively (classy :D) --- js/CameraContainer.js | 4 ++-- js/FixedCamera.js | 13 ++++++++++++- prototype/js/main.js | 7 +------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/js/CameraContainer.js b/js/CameraContainer.js index 3123c47..32afc85 100644 --- a/js/CameraContainer.js +++ b/js/CameraContainer.js @@ -23,8 +23,8 @@ CameraContainer.prototype.look = function() { this.cameras[this.current_camera].look(); } -CameraContainer.prototype.update = function() { - this.cameras[this.current_camera].update(); +CameraContainer.prototype.update = function(position) { + this.cameras.map(function (elt) { elt.update(position); }); } CameraContainer.prototype.push = function(camera) { diff --git a/js/FixedCamera.js b/js/FixedCamera.js index 280dd57..05a0a14 100644 --- a/js/FixedCamera.js +++ b/js/FixedCamera.js @@ -91,8 +91,19 @@ FixedCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); FixedCamera.prototype.constructor = FixedCamera; // Update function -FixedCamera.prototype.update = function() { +FixedCamera.prototype.update = function(position) { + // Compute distance between center of camera and position + dist = Tools.norm2(Tools.diff(position, this.position)); + var low_bound = 500; + var high_bound = 500000; + + if (dist < 500) + this.mesh.material.opacity = 0; + else if (dist > 500000) + this.mesh.material.opacity = 0.5; + else + this.mesh.material.opacity = (dist - 50)*0.5/(high_bound - low_bound); } // Look function diff --git a/prototype/js/main.js b/prototype/js/main.js index 16c296f..94f9a9b 100644 --- a/prototype/js/main.js +++ b/prototype/js/main.js @@ -167,7 +167,7 @@ function animate() { requestAnimationFrame(animate); stats.begin(); - cameras.update(); + cameras.update(cameras.mainCamera().position); cameras.look(); renderer.render(scene, cameras.mainCamera()); @@ -204,9 +204,6 @@ function click(event) { var intersects = raycaster.intersectObjects(scene.children, true); - // Re-show all cameras - cameras.map(function(elt) { show(elt); }); - if ( intersects.length > 0 ) { var minDistance; var bestIndex; @@ -225,7 +222,6 @@ function click(event) { if (bestIndex !== undefined) { if (cameras.getById(intersects[bestIndex].object.id) !== undefined) { var new_camera = cameras.getById(intersects[bestIndex].object.id); - hide(new_camera) cameras.get(0).move(new_camera); } } @@ -234,7 +230,6 @@ function click(event) { for (o in objects) { if ( intersects[bestIndex].object.id == objects[o].id && cameras.get(objects[o].seen_by[0]) !== undefined) { var new_camera = cameras.get(objects[o].seen_by[0]); - hide(new_camera); cameras.get(0).move(new_camera); break; }