Convierta las coordenadas de event.offsetX y event.offsetY en coordenadas nativas webGL

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?

preguntado el 27 de noviembre de 13 a las 06:11

1 Respuestas

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 or haz tu propia pregunta.