[英]Perspective Projection Matrix in OpenGL appears black
我正在尝试使用Haskell和OpenGL实现透视投影转换。
我的顶点设置如下:
let vertices =
[ -0.3, 0.3, 0, -- Front Top Left 0
0.3, 0.3, 0, -- Front Top Right 1
0.3, -0.3, 0, -- Front Bottom Right 2
-0.3, -0.3, 0, -- Front Bottom Left 3
0.3, 0.3, 0, -- Back Top Left 4
0.3, 0, 0, -- Back Top Right 5
0.3, 0, 0, -- Back Bottom Right 6
0.3, 0.3, 0 -- Back Bottom Left 7 ]
而且,不使用任何转换,或仅使用“视图”转换,一切都会按应有的方式显示(灰色方块)。
视图转换是
view = [cos ty * cos tz, cos tz * sin tx * sin ty - cos tx * sin tz, cos tx * cos tz * sin ty + sin tx * sin tz, -cx,
cos ty * sin tz, cos tx * cos tz + sin tx * sin ty * sin tz, -1 * cos tz * sin tx + cos tx * sin ty * sin tz, -cy,
-1 * sin ty, cos ty * sin tx, cos tx * cos ty, -cz,
0, 0, 0, 1]
其中(cx, cy, cz)
是摄影机的位置,而(tx, ty, tz)
是摄影机绕轴以弧度欧拉角旋转的角度。
当我应用透视变换时出现问题
perspective = [scale, 0, 0, 0,
0, scale, 0, 0,
0, 0, -1 * (far + near) / diff, -1,
0, 0, -2 * near * far / diff, 0]
其中diff = far - near
且scale = 1.0 / tan (fov / 2.0)
和fov = 0.785
。
我的远近平面分别是10和0.01。
应用后,使用以下GLSL代码,将不会显示任何内容(即,只有黑屏)。
void main()
{
Color = color;
gl_Position = perspective * view * vec4(position, 1.0);
}
我尝试从多个不同的角度和位置查看正方形,并且禁用了剔除功能。
我的透视投影矩阵或其应用有什么问题?
这是通过转置视图矩阵解决的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.