I'm writing a library that deals with 2D graphical shapes.
I'm just wondering why should my coordinate system range from [-1, 1] for both the x and y axis
instead of [0, width] for x and [0, height] for y ?
I went for the latter system because I felt it was straight forward to implement.
YNorm = Y / height; Where X and Y are the original pixel coordinates, width and height are the width and height of the Digitizer window, and xNorm and yNorm are the normalized X and Y coordinates for the pixel. If the width and height are not identical, then the normalized scaling in X and Y will be different.
Window to Viewport Transformation is the process of transforming 2D world-coordinate objects to device coordinates. Objects inside the world or clipping window are mapped to the viewport which is the area on the screen where world coordinates are mapped to be displayed.
No, clip space and NDC space are not the same thing. Clip space is actually one step away from NDC, all coordinates are divided by Clip. W to produce NDC. Anything outside of the range [-1,1] in resulting NDC space corresponds to a point that is outside of the clipping volume.
The clip coordinate system is a homogeneous coordinate system in the graphics pipeline that is used for clipping. In OpenGL, clip coordinates are positioned in the pipeline just after view coordinates and just before normalized device coordinates (NDC).
From Jim Blinn's A Trip Down The Graphics Pipeline, p. 138.
Let's start with what might at first seem the simplest transformation: normalized device coordinates to pixel space. The transform is
s_x * X_NDC + d_x = X_pixel
s_y * Y_NDC + d_y = Y_pixel
A user/programmer does all screen design in NDC. There are three nasty realities of the hardware that NDC hides from us:
The actual number of pixels in x and y.
Non-uniform pixel spacing in x and y.
Up versus down for the Y coordinate. The NDC-to-pixel transformation will invert Y if necessary so that Y in NDC points up.
...
s_x = ( N_x - epsilon ) / 2
d_x = ( N_x - epsilon ) / 2
s_y = ( N_y - epsilon ) / (-2*a)
d_y = ( N_y - epsilon ) / 2
epsilon = .001
a = N_y/N_x (physical screen aspect ratio)
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