Veg*_*ard 4 opengl matrix coordinates homogenous-transformation coordinate-transformation
我有一个 2D 齐次坐标的 3x3 变换矩阵:
a b c
d e f
g h i
Run Code Online (Sandbox Code Playgroud)
我想glMultMatrix在 2D 应用程序中将其传递给 OpenGL(使用 ),但 OpenGL 采用 4x4 矩阵作为 3D 齐次坐标。我希望 4x4 矩阵转换的所有坐标最终都为 和 ,x与y3x3 矩阵和 相同z=0。
我已经尝试解决了。对于一个向量,x, y, 1我最终会得到转换后的向量ax + by + c, dx + ey + f, gx + hy + i,所以这意味着对于一个向量x, y, 0, 1,我希望得到转换后的向量ax + by + c, dx + ey + f, 0, ?。可以做到这一点的一个矩阵是(据我所知):
a b 0 c
d e 0 f
0 0 1 0
0 0 0 1
Run Code Online (Sandbox Code Playgroud)
它是否正确?有效吗?我不认为这是唯一能给出我正在寻找的结果的矩阵,但我不太明白第三行和第四行(以及第四列)应该或不应该包含什么。
如果您希望 z 坐标为0,则必须传递零行。另外,在最后一行中包含透视部分:
a b 0 c
d e 0 f
0 0 0 0
g h 0 i
Run Code Online (Sandbox Code Playgroud)