为什么 OpenGL 使用度数而不是弧度?

发布于 2024-08-19 04:43:35 字数 385 浏览 6 评论 0原文

OpenGL 设计者从不害怕数学,线性代数知识对于除了最简单的 OpenGL 应用程序之外的所有应用程序都是必不可少的。我认为可以放心地假设 OpenGL 程序员熟悉以弧度表示的角度。

从数学上来说,弧度在各个方面都比度数更优雅。它们还具有实际优点:

  • C 标准库使用弧度。
  • 几乎任何其他库也使用弧度。
  • 弧度在某些计算中更方便,例如圆弧的长度。

那么,为什么 OpenGL 设计者决定指定 glRotatefgluPerspective 等函数来使用度数呢?

(我知道这没有实际意义,而且无论如何也不会改变。我只是很好奇,而且我在 OpenGL.org 上找不到答案。)

The OpenGL designers were never afraid of mathematics, and knowledge of linear algebra is essential for all but the simplest OpenGL applications. I think it can safely be assumed that OpenGL programmers are familiar with angles in radians.

Mathematically, radians are more elegant than degrees in every respect. They also have practical advantages:

  • The C standard library uses radians.
  • Pretty much any other library out there uses radians as well.
  • Radians are more convenient in some computations, e.g. the length of a circular arc.

Why, then, did the OpenGL designers decide to specify functions like glRotatef and gluPerspective to use degrees?

(I know it's of no practical importance, and it's not going to change anyway. I'm just curious, and I couldn't find the answer on OpenGL.org.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

盛夏已如深秋| 2024-08-26 04:43:35

因为普通人更习惯于计算度数——OpenGL 就是为了简单易用而设计的。请注意,所有对度数进行操作的函数都是“高级”函数。

对于 OpenGL 本身来说,无论接收弧度还是度数都没有区别——无论如何,它们都会在内部转换为变换矩阵,因此使用其中之一不会带来计算增益。

那么,如果你可以允许人们使用学位,为什么还要让他们的事情变得复杂呢?无论如何,任何认真使用 OpenGL 进行编码的人都会提供他们自己的由四元数计算得出的矩阵。

本着同样的精神,我们可以问,既然矩阵在各个方面都更优雅,并且允许更高级别的控制,为什么还要有 glRotatefgluPerspective 呢?

一点一点:

  • 优雅 - 矩阵在各个方面都更优雅
  • C 库 - C 库由于计算原因而使用它们,GL 函数取角度并不意味着用于计算繁重的任务(直接使用矩阵),并且可能的实现无论如何,都有一个度数查找表。
  • 任何其他库 - 出于与 Clib 相同的原因遵循 C 库 - 而且,这是不正确的 - 许多 C++ 库允许选择,有些使用后者
  • 计算方便 - 无关紧要 - 内部表示是矩阵,计算可能使用完成如果要高效,则查找表 - 没有对角度的直接操作,因此表示并不重要

另请注意:所有使用角度的函数在当前标准(3.2)中均已弃用。 glRotatef唯一获取度数(或者事实上,获取角度)的函数。 glu 是一个实用程序库,不适合重型部署,因此它是针对可读性而定制的,并且 gluPerspective(... 60.0f..) 更具可读性,并且“就提供 FOV 而言,“标准”比 gluPerspective( ... M_PI / 3.0f ... ) 更好。

最后注意事项:

Because normal people are more used to calculating degrees -- OpenGL is meant to be used simple. Note that all the functions that operate on degrees are "high level" functions.

For OpenGL itself, it's no difference whether it receives radians or degrees -- they are internally converted to transformation matrices anyway, so there's no computational gain of using one or the other.

So why complicate stuff for people if you can allow them using degrees? Anyone coding seriously in OpenGL will provide their own matrices computated from quaternions anyway.

In the same spirit we could ask, why have glRotatef and gluPerspective anyway, since matrices are more elegant in every respect, and allow a higher grade of control.

Point by point:

  • Elegancy - matrices are more elegant in every aspect
  • C library - C library uses them because of computational reasons, GL functions taking angles are not meant to be used for computational heavy tasks (use matrices directly), and probably the implementation has a lookup table for degrees anyway.
  • any other library - following C library for the same reasons as Clib -- also, it's untrue -- many C++ libraries allow a choice, some use the latter
  • Computation conviniency - doesn't matter -- internal representation is matrices, calculations probablye done using lookup tables if meant to be efficient -- there's no direct operation on angles, so representation doesn't matter

Also note: all of the functions using degrees are in the current standard (3.2) deprecated. glRotatef is the only function taking degrees, or as a matter of fact, an angle at all. glu is a utility library not meant for heavy-duty deployment, hence it's tailored towards readability, and gluPerspective(... 60.0f..) is much more readable and "standard" in terms of supplying FOV than gluPerspective( ... M_PI / 3.0f ... ) would be.

Final notes:

述情 2024-08-26 04:43:35

我想说,由于 OpenGL 的设计考虑到了最终用户,因此使用度数是因为可以指定重要的角度(90180270< /code> ...) 仅包含整数,因此不需要浮点 GL_PI 常量。

I'd say that since OpenGL was designed with the end-user in mind, degrees were used because one can specify important angles (90, 180, 270 ...) with integers only, and so there is no need for a floating point GL_PI constant.

℡Ms空城旧梦 2024-08-26 04:43:35

我认为这是因为您应该能够获得某些角度(例如 90 度或 180 度)的精确旋转矩阵。正如这里的其他人所指定的,如果您使用 pi/2 而不是 90 度,舍入误差可能会导致变换矩阵几乎执行 90 度的旋转。

I think it is because you should be able to get an exact rotation matrix for certain angles like 90 or 180 degrees. Like other people here has specified, if you use pi/2 instead of 90 degrees, rounding errors may lead to a transformation matrix that almost performs a rotation by 90 degrees.

浅忆流年 2024-08-26 04:43:35

代码更容易阅读,它简化了新手的学习曲线并允许快速破解。

如前所述 - 度数具有优势 - 人类更习惯度数,比较: 0.78539816339744830961566084581988... 到 45 度,例如:/。

对于 OpenGL 的高级使用,您无论如何都需要提供自己的矩阵。

Code is easier to read, it eases learning curve for newbies and allows quick hacking.

As stated already - degrees HAVE advantage - humans are better used to degrees, compare: 0.78539816339744830961566084581988... to 45 degrees for example :/.

For advanced uses of OpenGL you provide your own matrices anyway.

莫多说 2024-08-26 04:43:35

好吧,在大多数情况下,您使用数学库将弧度转换为度数,然后再转换回弧度。我同意之前精彩海报中所说的大部分内容。

它更具人类可读性。

Well, what happens in most cases is that you use a Math library to convert from radians to degrees and back to radians. I agree with most of what was said by the previous awesome posters.

It's more human readable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文