gl的矩阵模式及其相应的矩阵变换函数

以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);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值