I've seen alot of Screen-Coordinate to world coordinate posts, but have not seen the opposite. Is there an easy way of getting screen coordinates from a 3d point, from any angle I view it from? I'm using C++ and opengl
erjot's answer is incomplete.
There are 2 additional things to take into account.
homogeneous = P . M . world
, the homogeneous
vector is a 4-d vector in homogeneous space. In particular, to bring it back to the [-1:1]^3 cube, you need to divide its first 3 coordinates by homogeneous.w
. cube.x = homogeneous.x / homogeneous.w
(what some people call the projection divide). window.x = viewport.x + viewport.width * (cube.x+1)/2
In case you care about the final Z, the transformation is not going through viewport, but DepthRange instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With