camera-unproject
Unprojects a 2D screen space point into 3D space using the inverse of your camera's combined matrix.
var mat4 = var unproject = //projection * view matrixvar combinedProjView = mat4 //now invert itvar invProjView = mat4 //viewport boundsvar viewport = x y width height //2D point in screen space//z=0 means "near plane"var point = 123 52 0 //vec3 outputvar output =
Usage
vec3 = unproject(out, point, viewport, invCombined)
Unprojects the 2D point
into 3D space using the viewport
bounds (screen x, y, width, height) and invCombined
matrix.
Where point
[x, y, z] uses window coordinates for XY and a range between 0.0 (near plane) and 1.0 (far plane) for Z. invCombined
is typically the invert of the combined projection * view
matrix for your camera.
The [x, y, z]
result is stored in out
and returned.
See Also
License
MIT, see LICENSE.md for details.