pygame+numpy实现3D图形引擎 第四节创建世界坐标系与相对坐标系
abc_sheep
2024年12月30日 19:50

我这边因为直接or不能用,作了点修改,结果没法解决 15:12 的问题,求教qwq

def screen_projection(self):

    vertexes = self.vertexes @ self.render.camera.camera_matrix()

    vertexes = vertexes @ self.render.projection.projection_matrix

    vertexes /= vertexes[:, -1].reshape(-1, 1)

    #print(vertexes)

    #print((vertexes > 1))

    vertexes[np.logical_or((vertexes > 2), (vertexes < -2))] = 0

    vertexes = vertexes @ self.render.projection.to_screen_matrix

    vertexes = vertexes[:, :2]

    # 绘制面

    for index, color_face in enumerate(self.color_faces):

       

      # 当前绘制的多边形

      color, face = color_face

      polygon = vertexes[face]

      #print(polygon)

      #if not np.any((polygon == self.render.screen_x) or (polygon == self.render.screen_y)):

      if not (np.any(polygon == self.render.screen_x) or np.any(polygon == self.render.screen_y)): #

      #if not (np.any(polygon >= [self.render.screen_x, self.render.screen_y])): #

        pygame.draw.polygon(self.render.screen, color, polygon, 3) # 边框

        #pygame.draw.polygon(self.render.screen, pygame.Color("yellow"), polygon, 0) # 面

        # 绘制标签(如果有)

        if self.lable:

          text = self.font.render(self.lable[index], True, "white")

          self.render.screen.blit(text, polygon[-1])

    # 绘制顶点

    if self.draw_vertexes:   

      for vertexe in vertexes:

        if not (np.any(vertexe == self.render.screen_x) or np.any(vertexe == self.render.screen_y)): #

          pygame.draw.circle(self.render.screen, "white", vertexe, 6)