From 8a486cd723d768a59a99d385d1e7235709ac84c3 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Wed, 22 Apr 2015 11:02:54 +0200 Subject: [PATCH] Options for collision --- js/PointerCamera.js | 4 +++- prototype/index.html | 5 ++++- prototype/js/main.js | 17 ++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/js/PointerCamera.js b/js/PointerCamera.js index b253115..c3cca82 100644 --- a/js/PointerCamera.js +++ b/js/PointerCamera.js @@ -52,6 +52,8 @@ var PointerCamera = function() { listenerTarget.addEventListener('mousemove', onMouseMove, false); listenerTarget.addEventListener('mouseup', onMouseUp, false); listenerTarget.addEventListener('mouseout', onMouseUp, false); + + this.collisions = true; } PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); PointerCamera.prototype.constructor = PointerCamera; @@ -137,7 +139,7 @@ PointerCamera.prototype.update = function() { if (this.moveLeft) direction.add(Tools.mul(left, speed)); if (this.moveRight) direction.sub(Tools.mul(left, speed)); - if (!this.isColliding(direction)) { + if (!this.collisions || !this.isColliding(direction)) { this.position.add(direction); } diff --git a/prototype/index.html b/prototype/index.html index 55284fe..6d2e0a8 100644 --- a/prototype/index.html +++ b/prototype/index.html @@ -16,7 +16,10 @@ the camera at anytime by clicking on the reset button.

- + + + +
# diff --git a/prototype/js/main.js b/prototype/js/main.js index c590972..e7c03b7 100644 --- a/prototype/js/main.js +++ b/prototype/js/main.js @@ -22,19 +22,18 @@ function init() { // Add the listener on the button document.getElementById('reset').onclick = function() { cameras.mainCamera().reset(); }; var fullarrow = document.getElementById('fullarrow'); - fullarrow.onclick = function() { - if (fullarrow.innerHTML === 'Full arrow') { - fullarrow.innerHTML = "Half arrow"; - } else { - fullarrow.innerHTML = "Full arrow"; - } - + fullarrow.onchange = function() { cameras.map(function(camera) { if (camera instanceof FixedCamera) { - camera.fullArrow = !camera.fullArrow; + camera.fullArrow = fullarrow.checked; } }); - }; + } + + var collisions = document.getElementById('collisions'); + collisions.onchange = function() { + cameras.mainCamera().collisions = collisions.checked; + } // on initialise le moteur de rendu container = document.getElementById('container');