Convierta las coordenadas de event.offsetX y event.offsetY en coordenadas nativas webGL
Frecuentes
Visto 278 veces
0
I have this webGL program written in JavaScript where I have to draw a point on a canvas on a spot where the user clicks. To do this, I need to get the coordinates of the spot where the user clicked. I accomplish this by using JavaScript's event.offsetX
y event.offsetY
to get coordinates of a spot relative to the top left of my canvas. The thing here is that webGL uses a different coordinate system where the coordinates are relative to the center of the canvas. Any ideas on how I can convert my event.offsetX
y event.offsetY
coordinates into webGL's coordinates?
1 Respuestas
1
WebGL, like any other 3d graphics environments, operates in a different coordinate system from what canvas deals with. Instead of pixels, X/Y/Z have value from -1.0 to 1.0. If you are trying to convert from the screen coordinate (pixels) to normalized device coordinates (NDC), the process is fairly straight forwards (see below), however if you are trying to convert into your scene's coordinate system then it is highly dependant on the way you are projecting the scene onto the screen.
In esta publicación, read the section titled Coordenadas de dispositivo normalizadas for more information and examples on converting between Screen Coordinates and NDCs.
contestado el 23 de mayo de 17 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript canvas webgl or haz tu propia pregunta.