Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalized Device Coordinates to window coordinates

I just read some stuff about the theory behind 3d graphics. As I understand it, normalized device coordinates (NDC) are coordinates that describe a point in the interval from -1 to 1 on both the horizontal and vertical axis. On the other hand window coordinates describe a point somewhere between (0,0) and (width,height) of the window. So my formula to convert a point from the NDC coordinate system to the window system would be

xwin = width + xndc * 0.5 * width
ywin = height + ynfv * 0.5 * height

The problem now is that in the OpenGL documentation for glViewport there is an other formula:

xwin = ( xndc + 1 ) * width * 0.5 + x
ywin = ( yndc + 1 ) * height * 0.5 + y

Now I'm wondering what I am getting wrong. Especially I'm wondering what the additional "x" and "y" mean.

Hope the question isn't too "not programming related", but I thought somehow it is related to graphics programming.

like image 256
okoman Avatar asked Dec 07 '25 20:12

okoman


1 Answers

Viewport doesn't necessarily start at (0; 0), so 'x' and 'y' in OpenGL documentation refers to viewport starting position.

To see what's wrong with your equation, try transforming (0; 0) normalized position, and you will get (width; height) instead of (width / 2; height / 2).

like image 52
NULL_PTR Avatar answered Dec 11 '25 09:12

NULL_PTR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!