初识open GL es 组合动画
?
Translate & Rotate (平移和旋转组合变换)
按照正常的理解,先平移和先旋转没什么区别吧,但是经测试,的确是有很大的区别的。甚至是结果完全的不同。示例如下:
先画一个方块绕着中心点自转。
?
// SQUARE A// Save the current matrix.gl.glPushMatrix();// Rotate square A counter-clockwise.gl.glRotatef(angle, 0, 0, 1);// Draw square A.square.draw(gl);// Restore the last matrix.gl.glPopMatrix();// 恢复了变换矩阵
?然后再画一个方块B绕着方块A做旋转,正常代码(先旋转再平移)应该如下:
?
?
// SQUARE B// Save the current matrixgl.glPushMatrix();// Rotate square B before moving it, making it rotate around A.gl.glRotatef(-angle, 0, 0, 1);// Move square B.gl.glTranslatef(2, 0, 0);// Scale it to 50% of square Agl.glScalef(.5f, .5f, .5f);// Draw square B.square.draw(gl);gl.glPopMatrix();
?但是如果先平移再旋转:
gl.glTranslatef(2, 0, 0);// 先平移gl.glRotatef(-angle, 0, 0, 1);//再旋转
?
就造成方块A和方块B同轴旋转了。
再有旋转
public abstract void glRotatef (float angle, float x, float y, float z)
?中参数X,Y,Z是一个整体,应该是(x,y,z)的向量坐标。
原理性的问题进一步了解中。
?
?
?
?