2018-04-01 10:45:41 -07:00
|
|
|
from constants import *
|
|
|
|
|
2018-08-15 16:23:29 -07:00
|
|
|
from continual_animation.update import ContinualGrowValue
|
2018-04-01 10:45:41 -07:00
|
|
|
from animation.transform import ApplyMethod
|
|
|
|
from camera.three_d_camera import ThreeDCamera
|
|
|
|
from scene.scene import Scene
|
|
|
|
|
|
|
|
|
|
|
|
class ThreeDScene(Scene):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"camera_class": ThreeDCamera,
|
|
|
|
"ambient_camera_rotation": None,
|
2018-04-01 10:45:41 -07:00
|
|
|
}
|
|
|
|
|
2018-08-15 16:23:29 -07:00
|
|
|
def set_camera_orientation(self, phi=None, theta=None, distance=None, gamma=None):
|
|
|
|
if phi is not None:
|
|
|
|
self.camera.set_phi(phi)
|
|
|
|
if theta is not None:
|
|
|
|
self.camera.set_theta(theta)
|
|
|
|
if distance is not None:
|
|
|
|
self.camera.set_distance(distance)
|
|
|
|
if gamma is not None:
|
|
|
|
self.camera.set_gamma(gamma)
|
2018-04-01 10:45:41 -07:00
|
|
|
|
2018-08-27 16:33:55 -07:00
|
|
|
def begin_ambient_camera_rotation(self, rate=0.05):
|
2018-08-15 16:23:29 -07:00
|
|
|
self.ambient_camera_rotation = ContinualGrowValue(
|
|
|
|
self.camera.theta_tracker,
|
2018-04-06 13:58:59 -07:00
|
|
|
rate=rate
|
2018-04-01 10:45:41 -07:00
|
|
|
)
|
|
|
|
self.add(self.ambient_camera_rotation)
|
|
|
|
|
|
|
|
def stop_ambient_camera_rotation(self):
|
|
|
|
if self.ambient_camera_rotation is not None:
|
|
|
|
self.remove(self.ambient_camera_rotation)
|
|
|
|
self.ambient_camera_rotation = None
|
|
|
|
|
2018-08-15 16:23:29 -07:00
|
|
|
def move_camera(self,
|
2018-08-15 17:30:24 -07:00
|
|
|
phi=None,
|
|
|
|
theta=None,
|
|
|
|
distance=None,
|
|
|
|
gamma=None,
|
|
|
|
frame_center=None,
|
2018-08-15 16:23:29 -07:00
|
|
|
added_anims=[],
|
|
|
|
**kwargs):
|
|
|
|
anims = []
|
|
|
|
value_tracker_pairs = [
|
|
|
|
(phi, self.camera.phi_tracker),
|
|
|
|
(theta, self.camera.theta_tracker),
|
|
|
|
(distance, self.camera.distance_tracker),
|
|
|
|
(gamma, self.camera.gamma_tracker),
|
|
|
|
]
|
|
|
|
for value, tracker in value_tracker_pairs:
|
|
|
|
if value is not None:
|
|
|
|
anims.append(
|
|
|
|
ApplyMethod(tracker.set_value, value, **kwargs)
|
|
|
|
)
|
2018-08-15 17:30:24 -07:00
|
|
|
if frame_center is not None:
|
|
|
|
anims.append(ApplyMethod(
|
|
|
|
self.camera.frame_center.move_to,
|
|
|
|
frame_center
|
|
|
|
))
|
2018-04-01 10:45:41 -07:00
|
|
|
is_camera_rotating = self.ambient_camera_rotation in self.continual_animations
|
|
|
|
if is_camera_rotating:
|
|
|
|
self.remove(self.ambient_camera_rotation)
|
2018-08-15 16:23:29 -07:00
|
|
|
self.play(*anims + added_anims)
|
2018-04-01 10:45:41 -07:00
|
|
|
if is_camera_rotating:
|
|
|
|
self.add(self.ambient_camera_rotation)
|
|
|
|
|
|
|
|
def get_moving_mobjects(self, *animations):
|
|
|
|
moving_mobjects = Scene.get_moving_mobjects(self, *animations)
|
2018-08-15 16:23:29 -07:00
|
|
|
camera_mobjects = self.camera.get_value_trackers()
|
|
|
|
if any([cm in moving_mobjects for cm in camera_mobjects]):
|
|
|
|
return self.mobjects
|
2018-04-01 10:45:41 -07:00
|
|
|
return moving_mobjects
|
2018-08-22 14:48:42 -07:00
|
|
|
|
2018-08-23 14:46:22 -07:00
|
|
|
def add_fixed_orientation_mobjects(self, *mobjects, **kwargs):
|
|
|
|
self.camera.add_fixed_orientation_mobjects(*mobjects, **kwargs)
|
2018-08-22 14:48:42 -07:00
|
|
|
|
|
|
|
def add_fixed_in_frame_mobjects(self, *mobjects):
|
|
|
|
self.camera.add_fixed_in_frame_mobjects(*mobjects)
|
|
|
|
|
|
|
|
def remove_fixed_orientation_mobjects(self, *mobjects):
|
|
|
|
self.camera.remove_fixed_orientation_mobjects(*mobjects)
|
|
|
|
|
|
|
|
def remove_fixed_in_frame_mobjects(self, *mobjects):
|
|
|
|
self.camera.remove_fixed_in_frame_mobjects(*mobjects)
|