Options for collision

This commit is contained in:
Thomas FORGIONE 2015-04-22 11:02:54 +02:00
parent 7b5b94947a
commit 8a486cd723
3 changed files with 15 additions and 11 deletions

View File

@ -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);
}

View File

@ -16,7 +16,10 @@
the camera at anytime by clicking on the reset button.
</p>
<button id="reset" style="margin-bottom:10px">Reset camera</button>
<button id="fullarrow" style="margin-bottom:10px">Full arrow</button>
<input type="checkbox" id="fullarrow" style="margin-bottom:10px">
<label for="fullarrow">Full arrow</label>
<input type="checkbox" id="collisions" style="margin-bottom:10px" checked>
<label for="collisions">Collisions</label>
<div style="border-width:1px; border-style: solid;" id="container"></div>
#
</section>

17
prototype/js/main.js vendored
View File

@ -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');