mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
A few edits to efvgt project
This commit is contained in:
@ -6,11 +6,26 @@ from topics.geometry import Square
|
||||
from scene import Scene
|
||||
from camera import Camera
|
||||
|
||||
class ThreeDCamera(Camera):
|
||||
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
|
||||
|
||||
return Camera.points_to_pixel_coords(self, adjusted_points)
|
||||
|
||||
class ThreeDCamera(CameraWithPerspective):
|
||||
CONFIG = {
|
||||
"sun_vect" : 3*UP+LEFT,
|
||||
"shading_factor" : 0.5,
|
||||
"camera_distance" : 20,
|
||||
}
|
||||
def __init__(self, *args, **kwargs):
|
||||
Camera.__init__(self, *args, **kwargs)
|
||||
@ -69,17 +84,6 @@ class ThreeDCamera(Camera):
|
||||
self, sorted(vmobjects, cmp = z_cmp)
|
||||
)
|
||||
|
||||
|
||||
def points_to_pixel_coords(self, points):
|
||||
distance_ratios = (self.camera_distance + points[:,2])/self.camera_distance
|
||||
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)
|
||||
|
||||
|
||||
class ThreeDScene(Scene):
|
||||
CONFIG = {
|
||||
"camera_class" : ThreeDCamera,
|
||||
|
Reference in New Issue
Block a user