15,907,906 members
See more:
I'm looking to convert screen coordinates (from event.clientX, event.clientY) on jQuery mousemove, to world coordinates in my isometric WebGL project. I'm, also using gl-matrix.

I initialise my viewport with;
JavaScript
`gl.viewport(0, 0, width, height)`
where width and height are `\$(window).width()` and `\$(window).height()` respectively

The bounds are calculated as such;
JavaScript
```left = -width / 2;
right = width / 2;
bottom = -height / 2;
top = height / 2;```
The orthographic projection matrix is set up as such;
JavaScript
`mat4.ortho(mat4.create(), left, right, bottom, top, -1000000, 1000000);`
I then make the projection isometric by rotating the projection matrix to a pitch of `Math.asin(1 / Math.sqrt(3))` and a yaw of `Math.PI / 4`.

With some cubes placed randomly on a grid, it looks like this:
View screenshot[^]

So given any (x, y) from (0, 0) to (width, height), how can I calculate the world coordinate, given that an object in the very centre of the scene is (0, 0, 0) in world coordinates?

What I have tried:

Using other people's projects' unproject methods
Posted
Updated 19-Nov-22 8:12am
v2
Peter_in_2780 20-Nov-22 16:41pm
If I understand what you're trying to do, it's impossible. You are trying to convert a 2D screen location (x,y) into a 3D world location (x', y', z'). All world points along a line of sight share the same screen location. The initial projection destroyed the "depth" information, and you can never recover it.
sorauts 20-Nov-22 20:51pm
Given an orthographic projection rotated to (1/sqrt(3), pi/4, 0) to make it isometric, the rotation can be used to directly calculate the screen point's corresponding world point, I'm just not sure what that calculation is.
Peter_in_2780 21-Nov-22 22:41pm
Forget about rotation for a moment. Let's consider a simple orthographic projection along the z axis, so the x and y screen coordinates map to world x and y (with appropriate scaling). What I am saying is that the world points (x,y,0) and (x,y,1) and (x,y,2) etc all map to the same screen point. From the screen coordinates, there is no way to recover the "depth" dimension, in this example the z direction.
In a rotated projection, the same thing applies to whatever the "line of sight" direction happens to be.
Looking at your random cubes example, every point on a visible face of a cube shares a screen point with a point on a hidden face (and an infinite number of others in front and behind along that line of sight).
sorauts 22-Nov-22 4:26am
All I need to know is the position on the plane, no collision or 'up' direction necessary
Peter_in_2780 23-Nov-22 2:42am
If you just want to undo the rotation, find the matrix used in the rotation, invert it and apply that inverse rotation matrix.