Skip to content

Commit a61e56b

Browse files
committed
Fix mouse position calculation for highlighting
1 parent 2285f85 commit a61e56b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/client/interactionHelper.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,19 @@ export function getPlanePosition (event, renderer, z) {
9595
/*
9696
* Determines the position of an event in canvas space
9797
* @param {Object} event usually a mouse or tap or pointer event
98-
* @param {Number} event.pageX the x coordinate on the screen
99-
* @param {Number} event.pageY the y coordinate on the screen
98+
* @param {Number} event.clientX the x coordinate relative to the viewport
99+
* @param {Number} event.clientY the y coordinate relative to the viewport
100100
* @param {Renderer} renderer the renderer that provides the camera and canvas
101101
* @return {Object} a three vector
102102
* @memberOf interactionHelper
103103
*/
104104
export function calculatePositionInCanvasSpace (event, renderer) {
105105
const canvas = renderer.getDomElement()
106+
const rect = canvas.getBoundingClientRect()
106107

107108
return new THREE.Vector3(
108-
((event.pageX / canvas.width) * 2) - 1,
109-
((-event.pageY / canvas.height) * 2) + 1,
109+
(((event.clientX - rect.left) / rect.width) * 2) - 1,
110+
((-(event.clientY - rect.top) / rect.height) * 2) + 1,
110111
0.5,
111112
)
112113
}

0 commit comments

Comments
 (0)