开发者

Android Matrix.rotateM results in NaN

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开发者_Python百科.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?


As stated in the doc :

Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜