为什么 OpenGL 使用度数而不是弧度?
OpenGL 设计者从不害怕数学,线性代数知识对于除了最简单的 OpenGL 应用程序之外的所有应用程序都是必不可少的。我认为可以放心地假设 OpenGL 程序员熟悉以弧度表示的角度。
从数学上来说,弧度在各个方面都比度数更优雅。它们还具有实际优点:
- C 标准库使用弧度。
- 几乎任何其他库也使用弧度。
- 弧度在某些计算中更方便,例如圆弧的长度。
那么,为什么 OpenGL 设计者决定指定 glRotatef
和 gluPerspective
等函数来使用度数呢?
(我知道这没有实际意义,而且无论如何也不会改变。我只是很好奇,而且我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
因为普通人更习惯于计算度数——OpenGL 就是为了简单易用而设计的。请注意,所有对度数进行操作的函数都是“高级”函数。
对于 OpenGL 本身来说,无论接收弧度还是度数都没有区别——无论如何,它们都会在内部转换为变换矩阵,因此使用其中之一不会带来计算增益。
那么,如果你可以允许人们使用学位,为什么还要让他们的事情变得复杂呢?无论如何,任何认真使用 OpenGL 进行编码的人都会提供他们自己的由四元数计算得出的矩阵。
本着同样的精神,我们可以问,既然矩阵在各个方面都更优雅,并且允许更高级别的控制,为什么还要有
glRotatef
和gluPerspective
呢?一点一点:
另请注意:所有使用角度的函数在当前标准(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
andgluPerspective
anyway, since matrices are more elegant in every respect, and allow a higher grade of control.Point by point:
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, andgluPerspective(... 60.0f..)
is much more readable and "standard" in terms of supplying FOV thangluPerspective( ... M_PI / 3.0f ... )
would be.Final notes:
我想说,由于 OpenGL 的设计考虑到了最终用户,因此使用度数是因为可以指定重要的角度(
90
、180
、270< /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 pointGL_PI
constant.我认为这是因为您应该能够获得某些角度(例如 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.
代码更容易阅读,它简化了新手的学习曲线并允许快速破解。
如前所述 - 度数具有优势 - 人类更习惯度数,比较: 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.
好吧,在大多数情况下,您使用数学库将弧度转换为度数,然后再转换回弧度。我同意之前精彩海报中所说的大部分内容。
它更具人类可读性。
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.