-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Closed
Description
In the raycaster examples (e.g. https://github.com/mrdoob/three.js/blob/dev/examples/webgl_instancing_raycast.html#L112), the mouse coordinates are not calculated correctly. Сode in the example works when the width of the canvas is equal to the width
window. And its position is 0 0.
Code
This is correct example for raycaster with https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect :
const rect = this.renderer.domElement.getBoundingClientRect();
mouse.x = ( ( event.clientX - rect.left ) / ( rect.width - rect.left ) ) * 2 - 1;
mouse.y = - ( ( event.clientY - rect.top ) / ( rect.bottom - rect.top) ) * 2 + 1;Screenshots
Platform:
- Device: [Desktop, Mobile]
- OS: [Windows, MacOS, Linux, Android, iOS]
- Browser: [Chrome, Firefox, Safari, Edge]
- Three.js version: [r136]
Metadata
Metadata
Assignees
Labels
No labels