Improved mouse event

This commit is contained in:
Thomas FORGIONE 2015-04-11 17:18:07 +02:00
parent 4d79ea6484
commit 35a8522088
2 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,11 @@
var PointerCamera = function() {
THREE.PerspectiveCamera.apply(this, arguments);
if (arguments[4] === undefined)
listenerTarget = document;
else
listenerTarget = arguments[4];
// Set Position
this.theta = Math.PI;
this.phi = Math.PI;
@ -40,9 +45,12 @@ var PointerCamera = function() {
document.addEventListener('keydown', onKeyDown, false);
document.addEventListener('keyup', onKeyUp, false);
document.addEventListener('mousedown', onMouseDown, false);
document.addEventListener('mousemove', onMouseMove, false);
document.addEventListener('mouseup', onMouseUp, false);
listenerTarget.addEventListener('mousedown', onMouseDown, false);
listenerTarget.addEventListener('mousemove', onMouseMove, false);
listenerTarget.addEventListener('mouseup', onMouseUp, false);
listenerTarget.addEventListener('mouseout', onMouseUp, false);
console.log(arguments[3]);
}
PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
PointerCamera.prototype.constructor = PointerCamera;

View File

@ -39,7 +39,7 @@ function init() {
scene.add(ambient_light);
// on initialise la camera que lon place ensuite sur la scène
var camera1 = new PointerCamera(50, container_size.width / container_size.height, 1, 100000);
var camera1 = new PointerCamera(50, container_size.width / container_size.height, 1, 100000, container);
var camera2 = new FixedCamera(50,
container_size.width / container_size.height,