Take a transformation matrix like you're used to constructing with WebGL, and project arbitrary 3D points onto your 2D screen.
You can use this to take a point in your WebGL scene and get its onscreen position on the canvas, e.g. to add DOM element overlays, or bootstrapping your own canvas/SVG.
Usage
transform(out, position, matrix)
Given a 3-element array position
and a 16-element array matrix
, update
the out
array to contain your new 2D points – each of them ranging from 0 to
- For example:
var mat4 = mat4var camera =var transform =var projection = 16var view = 16var pvMatrix = 16var point = 2{// get your camera/view matrix from something like orbit-cameracamera// perspective projectionmat4// Combine your matrix transformations into// a single transform by multiplying them togethermat4// get your 2d point from your 3d point:var x = point0var y = point1}
See Also
License
MIT. See LICENSE.md for details.