I am trying to convert from mouse position to map position in react-threejs
. Using hook useThree
I can get the mouse position where x,y in [-1,1]. However unproject(camera)
returns the values in [-screen pixel/2, -screen pixel/2] instead of the world position.
const { mouse } = useThree();
...
var vector = new THREE.Vector3();
vector.set(mouse.x, mouse.y, 1);
vector.unproject(camera); // -1,1 => -screen width/2,screen width/2
My canvas:
<Canvas
camera={{
position: [0, 0, 100],
up: [0, 0, 1],
}}
>
<OrbitControls ref={controlsRef} />
<ambientLight />
<Map />
</Canvas>
Any idea please?