mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
fix mouse position
This commit is contained in:
parent
d9265d03f3
commit
3f166776ca
@ -216,12 +216,19 @@ export default function useThree() {
|
|||||||
this.renderer.dispose();
|
this.renderer.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function updateMouse(e) {
|
||||||
|
const rect = e.target.getBoundingClientRect();
|
||||||
|
mouse.x = ((e.clientX - rect.left) / size.width) * 2 - 1;
|
||||||
|
mouse.y = -((e.clientY - rect.top) / size.height) * 2 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* click listener
|
* click listener
|
||||||
*/
|
*/
|
||||||
function onClick(e) {
|
function onClick(e) {
|
||||||
mouse.x = (e.clientX / size.width) * 2 - 1;
|
updateMouse(e);
|
||||||
mouse.y = -(e.clientY / size.height) * 2 + 1;
|
|
||||||
raycaster.setFromCamera(mouse, obj.camera);
|
raycaster.setFromCamera(mouse, obj.camera);
|
||||||
const objects = raycaster.intersectObjects(intersectObjects);
|
const objects = raycaster.intersectObjects(intersectObjects);
|
||||||
for (let i = 0; i < objects.length; i++) {
|
for (let i = 0; i < objects.length; i++) {
|
||||||
@ -234,8 +241,7 @@ export default function useThree() {
|
|||||||
* mousemove listener
|
* mousemove listener
|
||||||
*/
|
*/
|
||||||
function onMousemove(e) {
|
function onMousemove(e) {
|
||||||
mouse.x = (e.clientX / size.width) * 2 - 1;
|
updateMouse(e);
|
||||||
mouse.y = -(e.clientY / size.height) * 2 + 1;
|
|
||||||
onMousechange(e);
|
onMousechange(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user