Pygame - 我怎样才能旋转表面,使其在行进方向上 "looking"?

Pygame - How can I rotate a surface so it is "looking" in the direction that it is travelling?

我写了一个程序,让一个矩形按许多向量的方向依次移动。 Arbitrary Example.

如何计算表面必须旋转的角度,以便它“看”在其行进的矢量方向上。

    def __FindAngle(self, previous, next):
        angle2 = -math.degrees(math.atan2(next.y, next.x))
        angle1 = -math.degrees(math.atan2(previous.y, previous.x))
        if angle1 == angle2:
            return 0
        return round(angle2 - angle1 - self.TaxiCorrection)

这是我目前的尝试,其中 previous 是其路径的前一个向量,next 是其路径的下一个向量。 (self.TaxiCorrection 是根据图像方向的校正角度)

我是堆栈溢出的新手,如果我的问题不是很清楚,我深表歉意。

物体的角度可以根据方向向量计算出来。 参见
请注意 y-axis 需要反转,因为在 PyGame 坐标系中 y-axis 指向下方:

angle = math.degrees(math.atan2(previous.y-next.y, next.x-previous.x))

参见How do I rotate an image around its center using PyGame?

def blitRotateCenter(target_surf, surf, center, angle):
    rotated_surf = pygame.transform.rotate(surf, angle)
    bounding_rect = rotated_image.get_rect(center = center)
    target_surf.blit(rotated_surf, bounding_rect)

另见 How do I gently change the direction of movement when moving forward?, and