2013-05-07 38 views
0

典型旋轉公式(維基)的Android opengl.Matrix類問題

enter image description here

讓我們,對於圍繞X軸旋轉例如45度。 cos45 = sin45 = 0.707 ...

所以結果矩陣應該是

[1                                               0]

| 0         0.707         -0.707         0 |

| 0         0.707         0.707         0 |

[0                                             1]

因此,我使用android.opengl.Matrix

Matrix.setIdentityM(mModelMatrix,0);

Matrix.rotateM(mModelMatrix,0,mModelMatrix,0,45,1.0f,0.0f,0F);

然後我觀看結果,它是:

[1                                               0]

| 0         0.707         -0.499         0 |

| 0         0.707         0.207         0 |

[0                                             1]

請解釋這是什麼?一個錯誤?一個特徵?或者我可能會錯過一些數學和平等?

回答

2

有兩種不同版本的android.opengl.Matrix.rotateM

public static void rotateM (float[] m, int mOffset, float a, float x, float y, float z) 
// Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z) 

public static void rotateM (float[] rm, int rmOffset, float[] m, int mOffset, float a, float x, float y, float z) 
// Rotates matrix m by angle a (in degrees) around the axis (x, y, z) 

看起來要到位旋轉 - 源矩陣和結果矩陣是相同的浮動[] - 但你使用從一個矩陣讀取並寫入另一個矩陣的調用。看看rotateM的實現,看起來不支持。

+0

是的,這確實不支持:http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/opengl/Matrix.java/ ?v = source在內部做一個multriplyMM:「可以爲結果,lhs和/或rhs傳遞相同的浮點數組,但是如果結果元素與lhs或rhs元素重疊,則結果元素值是不確定的。 – Trax 2013-05-08 05:24:55