【发布时间】:2017-10-16 05:00:55
【问题描述】:
我使用 webgl 并修改着色器(vs.glsls 和 fs.glsl)以了解 GLSL 和图形编程。我有一个想要缩放、旋转和平移的模型。缩放和旋转效果很好,但是当我乘以平移矩阵时,结果很奇怪。我知道这是一个非常基本的问题,但我遗漏了一些东西,我需要找出来。 我的模型在 y 轴上被无限拉伸。
白色区域应该是模型的眼睛:
这是我的顶点着色器代码:
mat4 rX = mat4 (
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, -1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
mat4 rZ = mat4 (
0.0, 1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
mat4 eyeScale = mat4 (
.50,0.0,0.0,0.0,
0.0,.50,0.0,0.0,
0.0,0.0,.50,0.0,
0.0,0.0,0.0,1.0
);
mat4 eyeTrans = mat4(
1.0,0.0,0.0,0.0,
0.0,1.0,0.0,4.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,1.0
);
mat4 iR = eyeTrans*rZ*rX*eyeScale;
gl_Position = projectionMatrix * modelViewMatrix *iR* vec4(position, 1.0);
}
【问题讨论】:
-
@Rabbid76 我又试了一次,结果一样。它不是翻译模型,而是拉伸模型。我将在问题中添加图片,以便您查看结果。
标签: matrix opengl-es glsl webgl coordinate-transformation