我正在使用 javascript、webgl2 和 gl-matrix 构建一个简单的粒子系统。我有一个圆形网格、一些颜色、一些位置、一个相机视图矩阵和一个投影矩阵。我可以像这样渲染未旋转的点:
render(viewMatrix, projectionMatrix){
const matrix = mat4.create();
for (let index = 0; index < this.particleCount; index++){
mat4.fromTranslation(matrix, this.positions[index]);
mat4.multiply(matrix, viewMatrix, matrix);
mat4.multiply(matrix, projectionMatrix, matrix);
this.renderer.render(this.mesh, this.indices, this.colors[index], matrix, this.gl.TRIANGLE_FAN);
}
}
显然,他们没有面对镜头。
我确信有一种方法可以导出一个矩阵,将相机的面向和向上向量与圆心的位置相结合,但矩阵数学对我来说是巫术巫术。如何构建使用粒子位置平移并使用相机矩阵旋转的矩阵(包括或不包括投影)?我需要知道相机的位置吗?