这是因为 OpenGL (ES) 矩阵是由向量按列主要顺序指定的。
见android.opengl.Matrix:
矩阵数学实用程序。这些方法对 OpenGL ES 格式矩阵和存储在浮点数组中的向量进行操作。
矩阵是以列优先顺序存储的 4 x 4 列向量矩阵:
m[offset + 0] m[offset + 4] m[offset + 8] m[offset + 12]
m[offset + 1] m[offset + 5] m[offset + 9] m[offset + 13]
m[offset + 2] m[offset + 6] m[offset + 10] m[offset + 14]
m[offset + 3] m[offset + 7] m[offset + 11] m[offset + 15]
参见OpenGL ES Shading Language 3.20 Specification, 5.4.2 Vector and Matrix Constructors,第 110 页:
要通过指定向量或标量来初始化矩阵,组件会以列优先顺序分配给矩阵元素
.
mat4(float, float, float, float, // first column
float, float, float, float, // second column
float, float, float, float, // third column
float, float, float, float); // fourth column
所以 GLSL mat4 可以通过轴和平移的 4 个向量来设置:
mat4 m44 = mat4(
vec4( Xx, Xy, Xz, 0.0),
vec4( Yx, Xy, Yz, 0.0),
vec4( Zx Zy Zz, 0.0),
vec4( Tx, Ty, Tz, 1.0) );
绕z轴(0, 0, 1)向右(逆时针)数学旋转后,x轴为(0, 1, 0) em>,y轴为(-1, 0, 0),由此引出矩阵:
0 1 0 0 // x axis vector
-1 0 0 0 // y axis vector
0 0 1 0 // z axis vector
0 0 0 1 // translation vector