Hide camera when clicking on it

This commit is contained in:
Thomas FORGIONE 2015-04-13 09:48:50 +02:00
parent b5d2822d00
commit f4d28a6ee6
3 changed files with 18 additions and 2 deletions

View File

@ -58,3 +58,7 @@ CameraContainer.prototype.nextCamera = function() {
this.current_camera%=this.cameras.length; this.current_camera%=this.cameras.length;
} }
} }
CameraContainer.prototype.map = function(callback) {
this.cameras.map(callback);
}

View File

@ -105,3 +105,8 @@ FixedCamera.prototype.addToScene = function(scene) {
scene.add(this.mesh); scene.add(this.mesh);
scene.add(this.line); scene.add(this.line);
} }
FixedCamera.prototype.traverse = function(callback) {
callback(this.mesh);
callback(this.line);
}

11
prototype/js/main.js vendored
View File

@ -204,6 +204,9 @@ function click(event) {
var intersects = raycaster.intersectObjects(scene.children, true); var intersects = raycaster.intersectObjects(scene.children, true);
// Re-show all cameras
cameras.map(function(elt) { show(elt); });
if ( intersects.length > 0 ) { if ( intersects.length > 0 ) {
var minDistance; var minDistance;
var bestIndex; var bestIndex;
@ -221,14 +224,18 @@ function click(event) {
if (bestIndex !== undefined) { if (bestIndex !== undefined) {
if (cameras.getById(intersects[bestIndex].object.id) !== undefined) { if (cameras.getById(intersects[bestIndex].object.id) !== undefined) {
cameras.get(0).move(cameras.getById(intersects[bestIndex].object.id)); var new_camera = cameras.getById(intersects[bestIndex].object.id);
hide(new_camera)
cameras.get(0).move(new_camera);
} }
} }
// Looking for objects // Looking for objects
for (o in objects) { for (o in objects) {
if ( intersects[bestIndex].object.id == objects[o].id && cameras.get(objects[o].seen_by[0]) !== undefined) { if ( intersects[bestIndex].object.id == objects[o].id && cameras.get(objects[o].seen_by[0]) !== undefined) {
cameras.get(0).move(cameras.get(objects[o].seen_by[0])); var new_camera = cameras.get(objects[o].seen_by[0]);
hide(new_camera);
cameras.get(0).move(new_camera);
break; break;
} }
} }