【发布时间】:2016-02-29 21:52:16
【问题描述】:
我正在学习 WebGL,我正在尝试了解如何构建透视矩阵。我想我几乎拥有它......我只是遇到了一个小问题,那就是当我将顶点乘以投影矩阵时,我希望正在查看的盒子的前面会变大,但它反而会变得更大更小,背部变大。我附上了一个屏幕截图: (绿色的一面是正面)
我的透视矩阵是这样的..
var aspectRatio = 600 / 600;
var fieldOfView = 30;
var near = 1;
var far = 2;
myPerspectiveMatrix = [
1 / Math.tan(fieldOfView / 2), 0, 0, 0,
0, 1 / Math.tan(fieldOfView / 2), 0, 0,
0, 0, (near + far) / (near - far), (2 * (near * far)) / (near - far),
0, 0, -1, 0
];
app.uniformMatrix4fv(uPerspectiveMatrix, false, new Float32Array(myPerspectiveMatrix));
我的顶点着色器是..
attribute vec3 aPosition;
attribute vec4 aColor;
uniform mat4 uModelMatrix;
uniform mat4 uPerspectiveMatrix;
varying lowp vec4 vColor;
void main()
{
gl_Position = uPerspectiveMatrix * vec4(aPosition, 5.0);
//gl_Position = uPerspectiveMatrix * uModelMatrix * vec4(aPosition, 2.0);
vColor = aColor;
}
【问题讨论】:
-
如果您是 WebGL 新手,您可能会发现这些有用的 webglfundamentals.org。 This one specifically goes over perspective 和 this one covers culling