Skip to content

Commit 5ae8231

Browse files
authored
fix: implement relative positioning for mouse (#305)
* fix: implement relative positioning for mouse * reformat back to original state
1 parent 572c053 commit 5ae8231

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

javascript/src/URDFDragControls.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ export class PointerURDFDragControls extends URDFDragControls {
235235
const mouse = new Vector2();
236236

237237
function updateMouse(e) {
238-
239-
mouse.x = ((e.pageX - domElement.offsetLeft) / domElement.offsetWidth) * 2 - 1;
240-
mouse.y = -((e.pageY - domElement.offsetTop) / domElement.offsetHeight) * 2 + 1;
241-
238+
239+
const rect = domElement.getBoundingClientRect();
240+
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
241+
mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
242+
242243
}
243244

244245
this._mouseDown = e => {

0 commit comments

Comments
 (0)