ソースを参照

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.
Angelo Wang 8 年 前
コミット
5b1b197305
1 ファイル変更4 行追加2 行削除
  1. 4 2
      examples/js/controls/DragControls.js

+ 4 - 2
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 );