glRotate 除零
我想我明白为什么调用 glRotate(#, 0, 0, 0) 会导致被零除。旋转向量 a 已标准化:a' = a/|a| = a/0
这是 glRotate 可能导致被零除的唯一情况吗?是的,我知道 glRotate 已被弃用。是的,我知道矩阵位于 OpenGL 手册上。不,我对线性代数的了解不足以自信地回答矩阵的问题。是的,我认为这会有帮助。是的,我已经在 #opengl 中问过这个问题了(你能告诉我吗?)。不,我没有得到答案。
I think I understand why calling glRotate(#, 0, 0, 0) results in a divide-by-zero. The rotation vector, a, is normalized: a' = a/|a| = a/0
Is that the only situation glRotate could result in a divide-by-zero? Yes, I know glRotate is deprecated. Yes, I know the matrix is on the OpenGL manual. No, I don't know linear algebra enough to confidently answer the question from the matrix. Yes, I think it would help. Yes, I asked this already in #opengl (can you tell?). And no, I didn't get an answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会说是的。我想说,你对标准化步骤的看法也是正确的。 OpenGL 手册中显示的矩阵仅由乘法组成。向量相乘也会得到相同的结果。当然,如果你得到一个
(0,0,0)
向量,它会做奇怪的事情。 OpenGL 在同一个手册中声明|x, y,z|=1
(或者 OpenGL 将标准化)。因此,如果它不正常化,您最终会得到一个非常空的矩阵:
这将以最奇怪的方式使您的对象内爆。所以不要用零向量调用这个函数。如果您愿意,请告诉我原因。
我建议使用像 GLM 这样的库来进行矩阵计算,如果它对于一些简单的<代码>glRotates。
I would say yes. And I would say that you are right about the normalization step as well. The matrix shown in the OpenGL manual only consists of multiplications. And multiplying a vector would result into the same. Of course, it would do strange things if you result in a vector of
(0,0,0)
. OpenGL states in the same manual that|x,y,z|=1
(or OpenGL will normalize).So IF it wouldn't normalize, you would end up with a very empty matrix of:
Which will implode your object in the strangest ways. So DON'T call this function with a zero-vector. If you would like to, tell me why.
And I recommend using a library like GLM to do your matrix calculations if it gets too complicated for some simple
glRotate
s.当您可以检查时,为什么它应该除以零那?:
Why should it divide by zero when you can check for that?: