标准化的设备坐标 [英] Normalized Device Coordinates
问题描述
我只是想知道为什么我的坐标系应该从 [ - 1, 1] 为x和y轴
而不是 [0,width] for x和 [0,height]
I因为我觉得这很容易实现。
让我们从看起来最简单的转换开始:标准化设备坐标到像素空间。这个变换是:
$ /
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' d_y = Y_pixel
用户/程序员在NDC中执行所有屏幕设计。 NDC从我们这里隐藏的硬件有三个令人讨厌的现实: x的实际像素数和 y 。 和 y中的非均匀像素间距。
。 Y 坐标的向上与向下。如果需要NDC到像素的转换将颠倒 Y ,以便NDC中的 Y 指向。
$ b...
s_x =(N_x (ε)/ 2
d_x =(N_x-ε)/ 2
$ b s_y =(N_y-ε)/(-2 * a)
d_y =(N_y - epsilon) )/ 2
epsilon = .001
a = N_y / N_x(物理屏幕宽高比)
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.
解决方案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)
这篇关于标准化的设备坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!