浏览代码

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();
 		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 );
 		_raycaster.setFromCamera( _mouse, _camera );