-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setMouse / Faulty mouse coordinates #76
Comments
moritzsalla
changed the title
Faulty mouse coordinates
setMouse / Faulty mouse coordinates
Nov 6, 2021
Same issue. Any good workaround? |
Couldn't make it happen with glsl-canvas but made a custom implementation by passing a import Canvas from 'glsl-canvas-js/dist/cjs/canvas/canvas'
import { useMove } from '@use-gesture/react'
const canvasElemRef = useRef()
const shaderProgramRef = useRef()
const matchesFine = useMatchMedia(MEDIA_QUERIES.fine)
useEffect(() => {
const canvasElem = canvasElemRef.current
// Check if a canvas element exists...
if (!canvasElem) return
// instantiate glsl-canvas
shaderProgramRef.current = new Canvas(canvasElem, {})
// cleanup glsl-canvas
return () => {
shaderProgramRef.current.pause()
shaderProgramRef.current = null
}
}, [canvasElemRef.current])
// https://use-gesture.netlify.app/docs/gestures/
useMove(
({ xy: [x, y] }) => {
// If the program has not been initialised yet, return early.
if (!canvasElemRef.current) return
const normalisedCoords = [x, window.innerHeight - y * 0.5]
canvasElemRef.current.setUniforms({ u_pointer: normalisedCoords })
},
{
// ssr check - I'm using next.js
target: typeof window === 'undefined' ? null : window,
// ignore coarse pointers
enabled: matchesFine,
},
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
.setMouse()
function returns faulty values. Please excuse if I am using the function incorrectly.For example, when passing
sandbox.useMouse({ x: 0, y: 0 })
and loggingsandbox.uniforms
,u_mouse
returns as follows:In case the function maps the coordinates to the canvas element, here is my react implementation:
The text was updated successfully, but these errors were encountered: