I am encountering an AttributeError in my Pygame program. The error message says that the module 'pygame.math' has no attribute 'Matrix44'
. I am using the Matrix44 class from the pyrr library, which I have installed using pip. I am not sure what is causing this error or how to fix it.
import pygame
from pyrr.matrix44 import Matrix44
from pygame.math import Vector3
class Camera:
def __init__(self, position, fov=90):
self.position = Vector3(*position)
self.rotation = Vector3(0, 0, 0)
self.fov = fov
self.aspect_ratio = 1.0
self.near_clip = 0.1
self.far_clip = 100.0
def get_projection_matrix(self):
return pygame.math.Matrix44.perspective(
self.fov, self.aspect_ratio, self.near_clip, self.far_clip)
def get_view_matrix(self):
rotation = pygame.math.Matrix44.from_euler(self.rotation)
translation = pygame.math.Matrix44.from_translation(-self.position)
return rotation @ translation
def move(self, direction):
if direction == 'right':
self.position.x += 1
elif direction == 'left':
self.position.x -= 1
elif direction == 'up':
self.position.y += 1
elif direction == 'down':
self.position.y -= 1
elif direction == 'forward':
self.position.z -= 1
elif direction == 'backward':
self.position.z += 1
def rotate(self, axis, angle):
setattr(self.rotation, axis, getattr(self.rotation, axis) + angle)
Steps I tried to solve the error:
Checked that we have installed the pyrr library using pip.
- Imported the Matrix44 class from the correct module, which is pyrr.matrix44.
- Upgraded Pygame to the latest version using pip.
- Uninstalled and reinstalled Pygame using pip.
- Uninstalled and reinstalled pyrr using pip.
- Manually downloaded and installed pyrr from the Pyrr GitHub repository.
Here is the full-detailed error that I got:
Traceback (most recent call last):
File "/home/pi/Desktop/Project/loader.py", line 188, in <module>
main()
File "/home/pi/Desktop/Project/loader.py", line 144, in main
projection_matrix = camera.get_projection_matrix()
File "/home/pi/Desktop/Project/utilities.py", line 15, in get_projection_matrix
return pygame.math.Matrix44.perspective(
AttributeError: module 'pygame.math' has no attribute 'Matrix44'
Despite trying all of these steps, we are still encountering the same AttributeError in our Pygame program. We are not sure what else we can try to fix the error. Any help would be greatly appreciated.