A community-maintained Python framework for creating mathematical animations.
Small setup for possible shift to general camera implementation
Grant Sanderson2eebaccde208
diff --git a/camera/moving_camera.py b/camera/moving_camera.pyindex 16585f548..99a384738 100644--- a/camera/moving_camera.py+++ b/camera/moving_camera.py@@ -1,13 +1,29 @@from __future__ import absolute_importfrom constants import FRAME_HEIGHT+from constants import FRAME_WIDTH+from constants import ORIGINfrom constants import WHITEfrom camera.camera import Camerafrom mobject.frame import ScreenRectangle+from mobject.types.vectorized_mobject import VGroup+from mobject.types.vectorized_mobject import VectorizedPointfrom utils.config_ops import digest_config+# TODO, think about how to incorporate perspective+class CameraFrame(VGroup):+ CONFIG = {+ "width": FRAME_WIDTH,+ "height": FRAME_HEIGHT,+ "center": ORIGIN,+ }++ def __init__(self, **kwargs):+ pass++class MovingCamera(Camera):"""Stays in line with the height, width and position of it's 'frame', which is a Rectanglediff --git a/camera/three_d_camera.py b/camera/three_d_camera.pyindex 2bcb750a4..d2777a335 100644--- a/camera/three_d_camera.py+++ b/camera/three_d_camera.py@@ -4,7 +4,7 @@ import numpy as npfrom constants import *-from camera.camera import Camera+from camera.moving_camera import MovingCamerafrom mobject.types.vectorized_mobject import VectorizedPointfrom mobject.three_dimensions import should_shade_in_3d@@ -15,41 +15,40 @@ from utils.space_ops import rotation_matrix# TODO: Make sure this plays well with latest camera updates-class CameraWithPerspective(Camera):- CONFIG = {- "camera_distance": 20,- }+# class CameraWithPerspective(Camera):+# CONFIG = {+# "camera_distance": 20,+# }- def points_to_pixel_coords(self, points):- distance_ratios = np.divide(- self.camera_distance,- self.camera_distance - points[:, 2]- )- scale_factors = interpolate(0, 1, distance_ratios)- adjusted_points = np.array(points)- for i in 0, 1:- adjusted_points[:, i] *= scale_factors+# def points_to_pixel_coords(self, points):+# distance_ratios = np.divide(+# self.camera_distance,+# self.camera_distance - points[:, 2]+# )+# scale_factors = interpolate(0, 1, distance_ratios)+# adjusted_points = np.array(points)+# for i in 0, 1:+# adjusted_points[:, i] *= scale_factors- return Camera.points_to_pixel_coords(self, adjusted_points)+# return Camera.points_to_pixel_coords(self, adjusted_points)-class ThreeDCamera(CameraWithPerspective):+class ThreeDCamera(MovingCamera):CONFIG = {"sun_vect": 5 * UP + LEFT,"shading_factor": 0.2,"distance": 5.,- "default_distance": 5.,"phi": 0, # Angle off z axis"theta": -TAU / 4, # Rotation about z axis}def __init__(self, *args, **kwargs):- Camera.__init__(self, *args, **kwargs)+ MovingCamera.__init__(self, *args, **kwargs)self.unit_sun_vect = self.sun_vect / np.linalg.norm(self.sun_vect)# rotation_mobject lives in the phi-theta-distance space# TODO, use ValueTracker for this insteadself.rotation_mobject = VectorizedPoint()- # moving_center lives in the x-y-z space+ # Moving_center lives in the x-y-z space# It representes the center of rotationself.moving_center = VectorizedPoint(self.frame_center)self.set_position(self.phi, self.theta, self.distance)@@ -88,9 +87,9 @@ class ThreeDCamera(CameraWithPerspective):return normal / lengthdef display_multiple_vectorized_mobjects(self, vmobjects):- camera_point = self.spherical_coords_to_point(- *self.get_spherical_coords()- )+ # camera_point = self.spherical_coords_to_point(+ # *self.get_spherical_coords()+ # )def z_cmp(*vmobs):# Compare to three dimensional mobjects based ondiff --git a/scene/three_d_scene.py b/scene/three_d_scene.pyindex c7dcb47b4..937fc748f 100644--- a/scene/three_d_scene.py+++ b/scene/three_d_scene.py@@ -18,8 +18,10 @@ class ThreeDScene(Scene):def set_camera_position(self, phi=None, theta=None, distance=None,center_x=None, center_y=None, center_z=None):- self.camera.set_position(phi, theta, distance,- center_x, center_y, center_z)+ self.camera.set_position(+ phi, theta, distance,+ center_x, center_y, center_z+ )def begin_ambient_camera_rotation(self, rate=0.01):self.ambient_camera_rotation = ContinualMovement(