From 5071d8c87238b90e42daf6d406cf4b5564d67e37 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 24 Aug 2017 23:12:06 -0700 Subject: [PATCH] Better ambient camera movements for ThreeDScenes --- topics/three_dimensions.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/topics/three_dimensions.py b/topics/three_dimensions.py index ed5a93ed..6c3cd0d8 100644 --- a/topics/three_dimensions.py +++ b/topics/three_dimensions.py @@ -30,7 +30,7 @@ class ThreeDCamera(CameraWithPerspective): "shading_factor" : 0.5, "distance" : 5, "phi" : 0, #Angle off z axis - "theta" : 0, #Rotation about z axis + "theta" : -np.pi/2, #Rotation about z axis } def __init__(self, *args, **kwargs): Camera.__init__(self, *args, **kwargs) @@ -41,7 +41,7 @@ class ThreeDCamera(CameraWithPerspective): def get_color(self, method): color = method() vmobject = method.im_self - if is_3d(vmobject): + if should_shade_in_3d(vmobject): return Color(rgb = self.get_shaded_rgb( color_to_rgb(color), normal_vect = self.get_unit_normal_vect(vmobject) @@ -80,7 +80,7 @@ class ThreeDCamera(CameraWithPerspective): def z_cmp(*vmobs): #Compare to three dimensional mobjects based on their #z value, otherwise don't compare. - three_d_status = map(is_3d, vmobs) + three_d_status = map(should_shade_in_3d, vmobs) has_points = [vm.get_num_points() > 0 for vm in vmobs] if all(three_d_status) and all(has_points): cmp_vect = self.get_unit_normal_vect(vmobs[1]) @@ -128,7 +128,7 @@ class ThreeDCamera(CameraWithPerspective): def get_view_transformation_matrix(self): return np.dot( rotation_matrix(self.get_phi(), LEFT), - rotation_about_z(self.get_theta()), + rotation_about_z(-self.get_theta() - np.pi/2), ) def points_to_pixel_coords(self, points): @@ -144,7 +144,7 @@ class ThreeDScene(Scene): def set_camera_position(self, phi = None, theta = None, distance = None): self.camera.set_position(phi, theta, distance) - def begin_ambient_camera_rotation(self, rate = -0.02*np.pi): + def begin_ambient_camera_rotation(self, rate = -0.01*np.pi): self.ambient_camera_rotation = AmbientRotation( self.camera.position_mobject, axis = OUT, @@ -159,7 +159,6 @@ class ThreeDScene(Scene): **kwargs ): target_point = self.camera.spherical_coords_to_point(phi, theta, distance) - print phi, theta, distance movement = ApplyMethod( self.camera.position_mobject.move_to, target_point, @@ -177,23 +176,19 @@ class ThreeDScene(Scene): return moving + static, [] return moving, static - - - ############## -def is_3d(mobject): - return hasattr(mobject, "part_of_3d_mobject") +def should_shade_in_3d(mobject): + return hasattr(mobject, "shade_in_3d") -def make_3d(mobject): +def shade_in_3d(mobject): for submob in mobject.submobject_family(): - submob.part_of_3d_mobject = True + submob.shade_in_3d = True class ThreeDMobject(VMobject): def __init__(self, *args, **kwargs): VMobject.__init__(self, *args, **kwargs) - for submobject in self.submobject_family(): - submobject.part_of_3d_mobject = True + shade_in_3d(self) class Cube(ThreeDMobject): CONFIG = {