From 5b1b197305a7bdfa58e118ece1ee7375a6560dbf Mon Sep 17 00:00:00 2001 From: Angelo Wang Date: Wed, 29 Mar 2017 14:39:59 +0800 Subject: [PATCH] Fix DragControls for containers not at (0,0) If the container (renderer.domElement) is not at the top-left corner of the browser, the hit-test will always fail. The `TransformControl` is using the correct way, so it doesn't have such issue. --- examples/js/controls/DragControls.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/js/controls/DragControls.js b/examples/js/controls/DragControls.js index 37fda3bcab..50d9d00ecc 100644 --- a/examples/js/controls/DragControls.js +++ b/examples/js/controls/DragControls.js @@ -52,8 +52,10 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) { event.preventDefault(); - _mouse.x = ( event.clientX / _domElement.clientWidth ) * 2 - 1; - _mouse.y = - ( event.clientY / _domElement.clientHeight ) * 2 + 1; + var rect = _domElement.getBoundingClientRect(); + + _mouse.x = ( (event.clientX - rect.left) / rect.width ) * 2 - 1; + _mouse.y = - ( (event.clientY - rect.top) / rect.height ) * 2 + 1; _raycaster.setFromCamera( _mouse, _camera ); -- GitLab