2D Coordinates from 3D View and Projection Matricies,
Members - Reputation: 100
Posted 25 March 2012 - 03:06 PM
V = view Matrix
P = projection Matrix
M = V * P
s = screen space coordinates
w = game world space coordinates
w * M = s
I then took the inverse of M with s so i could figure out the corner of the screen in "w". I split the coordinates using x = w.X * w.W and y = w.Y * w.W, because it was a 4th dimentional vector.
w= M^-1 * s
Members - Reputation: 130
Posted 28 March 2012 - 03:00 PM
x=-w..w, y=-w..w, z=-w..w,w=z, so you might want to devide each projected coordinate additionally by w, to get
your screen values in range x=-1..1,y=-1..1,z=-1..1, the normalized device coords ( NDC ).
M*w = c (in HCS)
s = c / c.w ( divide by homogeneous coordinate c.w )
To get back into world space, store your c.w per fragment/pixel/screen coord.
For each screen coord:
c = s * c.w
w = M^-1 * c