From b1926e98e4099db74cc101d9567b3f53ce68398b Mon Sep 17 00:00:00 2001 From: Faleij Date: Sat, 14 Jul 2012 10:42:48 +0300 Subject: [PATCH] As it were, mouse position were incorrect if the camera were a child of any other object than the world directly. This fix enables the camera to be a child of any object by using it's world position instead of local position to cast rays. --- threex.domevent.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/threex.domevent.js b/threex.domevent.js index 649e523..f63d1a1 100644 --- a/threex.domevent.js +++ b/threex.domevent.js @@ -209,7 +209,8 @@ THREEx.DomEvent.prototype._onMove = function(mouseX, mouseY, origDomEvent) var vector = new THREE.Vector3( mouseX, mouseY, 1 ); this._projector.unprojectVector( vector, this._camera ); - var ray = new THREE.Ray( this._camera.position, vector.subSelf( this._camera.position ).normalize() ); + var pos = this._camera.matrixWorld.getPosition().clone(); + var ray = new THREE.Ray( pos, vector.subSelf( pos ).normalize() ); var intersects = ray.intersectObjects( this._boundObjs ); var oldSelected = this._selected; @@ -250,8 +251,9 @@ THREEx.DomEvent.prototype._onEvent = function(eventName, mouseX, mouseY, origDom var vector = new THREE.Vector3( mouseX, mouseY, 1 ); this._projector.unprojectVector( vector, this._camera ); - vector.subSelf( this._camera.position ).normalize() - var ray = new THREE.Ray( this._camera.position, vector ); + var pos = this._camera.matrixWorld.getPosition().clone(); + vector.subSelf( pos ).normalize() + var ray = new THREE.Ray( pos, vector ); var intersects = ray.intersectObjects( this._boundObjs ); // if there are no intersections, return now