标准化设备坐标 [英] Normalized Device Coordinates
问题描述
我正在编写一个处理 2D 图形形状的库.
我只是想知道为什么我的坐标系的 x 轴和 y 轴都应该在 [-1, 1] 范围内
而不是 [0, width] 用于 x 和 [0, height] 用于 y ?
我选择了后一种系统,因为我觉得实施起来很简单.
摘自 Jim Blinn 的 图形管道之旅,第 10 页.138.
<块引用>让我们从乍一看似乎是最简单的转换开始:将设备坐标归一化到像素空间.变换是
s_x * X_NDC + d_x = X_pixels_y * Y_NDC + d_y = Y_pixel
<块引用>
用户/程序员在 NDC 中完成所有屏幕设计.NDC 向我们隐瞒了硬件的三个令人讨厌的现实:
x 和 y 中的实际像素数.
x 和 y 中的非均匀像素间距.
Y 坐标的上下.如有必要,NDC 到像素的转换将反转 Y,以便 NDC 中的 Y 指向上方.
...
s_x = ( N_x - epsilon )/2d_x = ( N_x - epsilon )/2s_y = ( N_y - epsilon )/(-2*a)d_y = ( N_y - epsilon )/2ε = .001a = 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屋!