视点和视线

返回首页

移动视点与移动被观察对象等效

20220303_wxIlyc

20220303_nBiulf

模型视图矩阵

u_ViewMatrix * u_ModelMatrix 20220303_2617Wb

    const VSHADER_SOURCE = `
            attribute vec4 a_Position;
            attribute vec4 a_Color;
            uniform mat4 u_ModelViewMatrix;
            varying vec4 v_Color;
            void main() {
                gl_Position = u_ModelViewMatrix *  a_Position;
                gl_PointSize = 10.0;
                v_Color = a_Color;
            }
    `;
    // 视图矩阵
        const viewMatrix = new Matrix4();
        viewMatrix.setLookAt(
            0.20, 0.25, 0.25,
            0, 0, 0,
            0, 1, 0,
        );
        //模型矩阵
        const modelMatrix = new Matrix4();
        modelMatrix.setRotate(10, 0, 0, 1);
        //模型视图矩阵 两个矩阵相乘
        const viewModelMatrix = viewMatrix.multiply(modelMatrix);

        const u_ModelViewMatrix = gl.getUniformLocation(gl.program, 'u_ModelViewMatrix');
        // 将矩阵传给uniform变量
        gl.uniformMatrix4fv(u_ModelViewMatrix, false, viewModelMatrix.elements);

修复默认可视空间导致的显示不全

下一节讲了正射投影矩阵及可视空间,可以去看下一节 ch7/OrthoView

20220304_Pngy0P 20220304_Q5xTGk

按方向键【上】【下】旋转视角当前 viewMatrix eyeX: 0.2