mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Add get/set field_of_view for camera frame
This commit is contained in:
parent
a0ba9c8b30
commit
0610f331a4
1 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
import moderngl
|
import moderngl
|
||||||
from colour import Color
|
from colour import Color
|
||||||
import OpenGL.GL as gl
|
import OpenGL.GL as gl
|
||||||
|
import math
|
||||||
|
|
||||||
import itertools as it
|
import itertools as it
|
||||||
|
|
||||||
|
@ -27,13 +28,14 @@ class CameraFrame(Mobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"frame_shape": (FRAME_WIDTH, FRAME_HEIGHT),
|
"frame_shape": (FRAME_WIDTH, FRAME_HEIGHT),
|
||||||
"center_point": ORIGIN,
|
"center_point": ORIGIN,
|
||||||
"focal_distance": 2,
|
"focal_dist_to_height": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
def init_uniforms(self) -> None:
|
def init_uniforms(self) -> None:
|
||||||
super().init_uniforms()
|
super().init_uniforms()
|
||||||
# As a quaternion
|
# As a quaternion
|
||||||
self.uniforms["orientation"] = Rotation.identity().as_quat()
|
self.uniforms["orientation"] = Rotation.identity().as_quat()
|
||||||
|
self.uniforms["focal_dist_to_height"] = self.focal_dist_to_height
|
||||||
|
|
||||||
def init_points(self) -> None:
|
def init_points(self) -> None:
|
||||||
self.set_points([ORIGIN, LEFT, RIGHT, DOWN, UP])
|
self.set_points([ORIGIN, LEFT, RIGHT, DOWN, UP])
|
||||||
|
@ -114,6 +116,14 @@ class CameraFrame(Mobject):
|
||||||
self.rotate(dgamma, self.get_inverse_camera_rotation_matrix()[2])
|
self.rotate(dgamma, self.get_inverse_camera_rotation_matrix()[2])
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def set_focal_distance(self, focal_distance: float):
|
||||||
|
self.uniforms["focal_dist_to_height"] = focal_distance / self.get_height()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def set_field_of_view(self, field_of_view: float):
|
||||||
|
self.uniforms["focal_dist_to_height"] = 2 * math.tan(field_of_view / 2)
|
||||||
|
return self
|
||||||
|
|
||||||
def get_shape(self):
|
def get_shape(self):
|
||||||
return (self.get_width(), self.get_height())
|
return (self.get_width(), self.get_height())
|
||||||
|
|
||||||
|
@ -130,7 +140,10 @@ class CameraFrame(Mobject):
|
||||||
return points[4, 1] - points[3, 1]
|
return points[4, 1] - points[3, 1]
|
||||||
|
|
||||||
def get_focal_distance(self) -> float:
|
def get_focal_distance(self) -> float:
|
||||||
return self.focal_distance * self.get_height()
|
return self.uniforms["focal_dist_to_height"] * self.get_height()
|
||||||
|
|
||||||
|
def get_field_of_view(self) -> float:
|
||||||
|
return 2 * math.atan(self.uniforms["focal_dist_to_height"] / 2)
|
||||||
|
|
||||||
def get_implied_camera_location(self) -> np.ndarray:
|
def get_implied_camera_location(self) -> np.ndarray:
|
||||||
to_camera = self.get_inverse_camera_rotation_matrix()[2]
|
to_camera = self.get_inverse_camera_rotation_matrix()[2]
|
||||||
|
|
Loading…
Add table
Reference in a new issue