u_ViewMatrix * u_ModelMatrix
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