因此,此维基百科页面向您展示了如何将 3d 空间中的点透视投影到 x/y 平面上。有谁知道如何在 y/z 平面上进行等效操作?这就是我现在正在做的事情(只是维基百科页面的东西。):
class Shape(object):
...
def apply_perspective(self, camera_pos, orientation, viewer_pos):
a, b, c = viewer_pos
cx, cy, cz = map(cos, orientation)
sx, sy, sz = map(sin, orientation)
transformed_vertices = []
append = transformed_vertices.append
for v in self.vertices:
x, y, z = v - camera_pos
t1 = sz*y + cz*x
t2 = cz*y - sz*x
x_ = cy*t1 - sy*z
t3 = cy*z + sy*t1
y_ = sx*t3 + cx*t2
z_ = cx*t3 - sx*t2
t4 = c/z_
newx = t4*x_ - a
newy = t4*y_ - b
append((newx, newy))
return transformed_vertices
您可以在github repo中查看所有代码。特别是其中的文件是 shapes.py。