Skip to content

Commit

Permalink
fix(three): use Vector3, so mouse can take a z value
Browse files Browse the repository at this point in the history
  • Loading branch information
setsun committed Apr 5, 2019
1 parent 89c04bf commit 7276322
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Canvas = React.memo(
const [bind, size] = useMeasure()
const [intersects, setIntersects] = useState([])
const [raycaster] = useState(() => new THREE.Raycaster())
const [mouse] = useState(() => new THREE.Vector2())
const [mouse] = useState(() => new THREE.Vector3())
const [defaultCam, setDefaultCamera] = useState(() => {
const cam = new THREE.PerspectiveCamera(75, 0, 0.1, 1000)
cam.position.z = 5
Expand Down Expand Up @@ -168,7 +168,9 @@ export const Canvas = React.memo(
const canvasRect = state.current.canvasRect
const x = ((event.clientX - canvasRect.left) / (canvasRect.right - canvasRect.left)) * 2 - 1
const y = -((event.clientY - canvasRect.top) / (canvasRect.bottom - canvasRect.top)) * 2 + 1

mouse.set(x, y, 0.5)

raycaster.setFromCamera(mouse, state.current.camera)
}, [])

Expand Down

0 comments on commit 7276322

Please sign in to comment.