Mildly more efficient CameraFrame.get_view_matrix()

This commit is contained in:
Grant Sanderson 2024-08-19 16:54:29 -05:00
parent c064b11e2a
commit 058914fdd2

View file

@ -38,6 +38,7 @@ class CameraFrame(Mobject):
self.default_orientation = Rotation.identity()
self.view_matrix = np.identity(4)
self.id4x4 = np.identity(4)
self.camera_location = OUT # This will be updated by set_points
self.euler_axes = euler_axes
@ -100,17 +101,15 @@ class CameraFrame(Mobject):
into the camera's internal coordinate system
"""
if self._data_has_changed:
shift = np.identity(4)
rotation = np.identity(4)
scale_mat = np.identity(4)
shift = self.id4x4.copy()
rotation = self.id4x4.copy()
scale = self.get_scale()
shift[:3, 3] = -self.get_center()
rotation[:3, :3] = self.get_inverse_camera_rotation_matrix()
scale = self.get_scale()
np.dot(rotation, shift, out=self.view_matrix)
if scale > 0:
scale_mat[:3, :3] /= self.get_scale()
self.view_matrix = np.dot(scale_mat, np.dot(rotation, shift))
self.view_matrix[:3, :4] /= scale
return self.view_matrix