Android Matrix.rotateM 结果为 NaN
我正在尝试做一个 Matrix.rotateM();我注意到如果矩阵本身旁边的所有参数都是 0.0f 那么矩阵就会被一些 NaN 值搞乱。
mModelMatrix = new float[16];
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, 0.0f, 0.0f, 0.0f, 0.0f);
结果是这样的矩阵。
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 1.0]
在旋转之前,矩阵看起来像这样
[1.0, 0.0, 0.0, 0.0]
[0.0, 1.0, 0.0, 0.0]
[0.0, 0.0, 1.0, 0.0]
[0.0, 0.0, 0.0, 1.0]
但是如果我对 Matrix.rotateM() 的调用包含不是 0.0f 的值,那么矩阵看起来很好。这是预期的行为吗?或者我做错了什么?
Im trying to do a Matrix.rotateM(); and i noticed if all the parameters beside the matrix itself is 0.0f then the Matrix will get messed up with some NaN values.
mModelMatrix = new float[16];
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, 0.0f, 0.0f, 0.0f, 0.0f);
Results in a Matrix like this.
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 0.0]
[NaN, NaN, NaN, 1.0]
Before the rotation the Matrix looks like this
[1.0, 0.0, 0.0, 0.0]
[0.0, 1.0, 0.0, 0.0]
[0.0, 0.0, 1.0, 0.0]
[0.0, 0.0, 0.0, 1.0]
But if my call to Matrix.rotateM() contains values that are not 0.0f then the matrix looks fine. Is that a expected behavior? Or am i doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如文档中所述:
您尝试围绕的旋转轴为空。没有办法绕零轴旋转,它只是不知道如何旋转,并且失败。我通常对 x、y 或 z 使用 1.0f,对另外 2 个使用 0.0f。这样可以围绕给定轴进行旋转。
As stated in the doc :
The axis you are trying to rotate around is null. There's no way to rotate around a null axis, it just doesn't know how to rotate, and fails. I generally use 1.0f for either x, y, or z, and 0.0f for the other 2. That gives you a rotation around a given axis.