Skip to content

Commit

Permalink
Add option to change Euler axes
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Feb 13, 2024
1 parent 4ce8a3b commit ed3ac74
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions manimlib/camera/camera_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
center_point: Vect3 = ORIGIN,
# Field of view in the y direction
fovy: float = 45 * DEGREES,
euler_axes: str = "zxz",
**kwargs,
):
super().__init__(**kwargs)
Expand All @@ -35,6 +36,7 @@ def __init__(
self.default_orientation = Rotation.identity()
self.view_matrix = np.identity(4)
self.camera_location = OUT # This will be updated by set_points
self.euler_axes = euler_axes

self.set_points(np.array([ORIGIN, LEFT, RIGHT, DOWN, UP]))
self.set_width(frame_shape[0], stretch=True)
Expand Down Expand Up @@ -62,7 +64,7 @@ def get_euler_angles(self) -> np.ndarray:
orientation = self.get_orientation()
if all(orientation.as_quat() == [0, 0, 0, 1]):
return np.zeros(3)
return orientation.as_euler("zxz")[::-1]
return orientation.as_euler(self.euler_axes)[::-1]

def get_theta(self):
return self.get_euler_angles()[0]
Expand Down Expand Up @@ -126,10 +128,27 @@ def set_euler_angles(
if all(eulers == 0):
rot = Rotation.identity()
else:
rot = Rotation.from_euler("zxz", eulers[::-1])
rot = Rotation.from_euler(self.euler_axes, eulers[::-1])
self.set_orientation(rot)
return self

def increment_euler_angles(
self,
dtheta: float | None = None,
dphi: float | None = None,
dgamma: float | None = None,
units: float = RADIANS
):
angles = self.get_euler_angles()
for i, value in enumerate([dtheta, dphi, dgamma]):
if value is not None:
angles[i] += value * units
self.set_euler_angles(*angles)
return self

def set_euler_axes(self, seq: str):
self.euler_axes = seq

def reorient(
self,
theta_degrees: float | None = None,
Expand Down Expand Up @@ -158,16 +177,16 @@ def set_phi(self, phi: float):
def set_gamma(self, gamma: float):
return self.set_euler_angles(gamma=gamma)

def increment_theta(self, dtheta: float):
self.rotate(dtheta, OUT)
def increment_theta(self, dtheta: float, units=RADIANS):
self.increment_euler_angles(dtheta=dtheta, units=units)
return self

def increment_phi(self, dphi: float):
self.rotate(dphi, self.get_inverse_camera_rotation_matrix()[0])
def increment_phi(self, dphi: float, units=RADIANS):
self.increment_euler_angles(dphi=dphi, units=units)
return self

def increment_gamma(self, dgamma: float):
self.rotate(dgamma, self.get_inverse_camera_rotation_matrix()[2])
def increment_gamma(self, dgamma: float, units=RADIANS):
self.increment_euler_angles(dgamma=dgamma, units=units)
return self

def add_ambient_rotation(self, angular_speed=1 * DEGREES):
Expand Down

0 comments on commit ed3ac74

Please sign in to comment.