From 9c1f8730e908a8c21d952799825f0286f7d8bfe7 Mon Sep 17 00:00:00 2001 From: waka Date: Mon, 18 May 2020 17:41:51 +0200 Subject: [PATCH] Fixed bug in mouse coordinates. Now set dom and in-view coordinates correctly. --- lib/hitTest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hitTest.js b/lib/hitTest.js index 197cc84..42670ba 100644 --- a/lib/hitTest.js +++ b/lib/hitTest.js @@ -126,11 +126,11 @@ function createHitTest(domElement) { function setMouseCoordinates(e) { var boundingRect = domElement.getBoundingClientRect(); - mouse.x = ((e.pageX - boundingRect.left) / boundingRect.width) * 2 - 1; - mouse.y = -((e.pageY - boundingRect.top) / boundingRect.height) * 2 + 1; + mouse.x = ((e.clientX - boundingRect.left) / boundingRect.width) * 2 - 1; + mouse.y = -((e.clientY - boundingRect.top) / boundingRect.height) * 2 + 1; - domMouse.x = e.clientX; - domMouse.y = e.clientY; + domMouse.x = e.pageX; + domMouse.y = e.pageY; } function update(scene, camera) {