以Android的GL10为例,说明一下矩阵模式及其相应的矩阵变换函数。
矩阵模式一共分为两种:
gl.glMatrixMode(GL10.GL_MODELVIEW);
和
gl.glMatrixMode(GL10.GL_PROJECTION);
我们操作矩阵的变换函数是要在对应的矩阵模式下才起作用。通过以上的矩阵模式设置函数将当前要操作的矩阵选中。
调用矩阵变换函数之前,通常还要重置当前的矩阵为单位矩阵。
gl.glLoadIdentity();
好了,下面谈谈这两种矩阵模式对应的矩阵变换函数:
1. MODELVIEW
glTranslatef, glRotatef, glScalef, gluLookAt
分别是平移,旋转,缩放,视图变换
2. PROJECTION
glOrthof, gluPerspective
设置正交投影和透视投影的参数。其中gluPerspective的实现是基于glFrustumf的封装:
/**
* Set up a perspective projection matrix
*
* @param gl a GL10 interface
* @param fovy specifies the field of view angle, in degrees, in the Y
* direction.
* @param aspect specifies the aspect ration that determins the field of
* view in the x direction. The aspect ratio is the ratio of x
* (width) to y (height).
* @param zNear specifies the distance from the viewer to the near clipping
* plane (always positive).
* @param zFar specifies the distance from the viewer to the far clipping
* plane (always positive).
*/
public static void gluPerspective(GL10 gl, float fovy, float aspect,
float zNear, float zFar) {
float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0));
float bottom = -top;
float left = bottom * aspect;
float right = top * aspect;
gl.glFrustumf(left, right, bottom, top, zNear, zFar);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)