标准化设备坐标 [英] Normalized Device Coordinates

查看:42
本文介绍了标准化设备坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个处理 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 向我们隐瞒了硬件的三个令人讨厌的现实:

  1. xy 中的实际像素数.

  2. xy 中的非均匀像素间距.

  3. 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:

  1. The actual number of pixels in x and y.

  2. Non-uniform pixel spacing in x and y.

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆