mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Move frame resizing to get_gl_Position so that the screen rotation matrix remains det 1
This commit is contained in:
parent
be904774dd
commit
5d34cee014
9 changed files with 28 additions and 36 deletions
|
@ -26,10 +26,7 @@ from manimlib.utils.space_ops import quaternion_mult
|
||||||
|
|
||||||
class CameraFrame(Mobject):
|
class CameraFrame(Mobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
# TODO, package these togeher
|
"frame_shape": (FRAME_WIDTH, FRAME_HEIGHT),
|
||||||
# Also, interpolation doesn't yet do anything with them.
|
|
||||||
"width": FRAME_WIDTH,
|
|
||||||
"height": FRAME_HEIGHT,
|
|
||||||
"center_point": ORIGIN,
|
"center_point": ORIGIN,
|
||||||
# Theta, phi, gamma
|
# Theta, phi, gamma
|
||||||
"euler_angles": [0, 0, 0],
|
"euler_angles": [0, 0, 0],
|
||||||
|
@ -37,7 +34,10 @@ class CameraFrame(Mobject):
|
||||||
}
|
}
|
||||||
|
|
||||||
def init_points(self):
|
def init_points(self):
|
||||||
self.points = np.array([self.center_point])
|
self.points = np.array([UR, UL, DL, DR])
|
||||||
|
self.set_width(self.frame_shape[0], stretch=True)
|
||||||
|
self.set_height(self.frame_shape[1], stretch=True)
|
||||||
|
self.move_to(self.center_point)
|
||||||
self.euler_angles = np.array(self.euler_angles, dtype='float64')
|
self.euler_angles = np.array(self.euler_angles, dtype='float64')
|
||||||
|
|
||||||
def to_default_state(self):
|
def to_default_state(self):
|
||||||
|
@ -53,8 +53,6 @@ class CameraFrame(Mobject):
|
||||||
result[:3, 3] = -self.get_center().T
|
result[:3, 3] = -self.get_center().T
|
||||||
# Rotate based on camera orientation
|
# Rotate based on camera orientation
|
||||||
result[:3, :3] = np.dot(self.get_inverse_camera_rotation_matrix(), result[:3, :3])
|
result[:3, :3] = np.dot(self.get_inverse_camera_rotation_matrix(), result[:3, :3])
|
||||||
# Scale to have height 2 (matching the height of the box [-1, 1]^2)
|
|
||||||
result *= 2 / self.height
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_inverse_camera_rotation_matrix(self):
|
def get_inverse_camera_rotation_matrix(self):
|
||||||
|
@ -98,28 +96,21 @@ class CameraFrame(Mobject):
|
||||||
self.euler_angles[2] += dgamma
|
self.euler_angles[2] += dgamma
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def scale(self, scale_factor, **kwargs):
|
# def scale(self, scale_factor, **kwargs):
|
||||||
# TODO, handle about_point and about_edge?
|
# # TODO, handle about_point and about_edge?
|
||||||
self.height *= scale_factor
|
# self.frame_dimensions *= scale_factor
|
||||||
self.width *= scale_factor
|
# return self
|
||||||
return self
|
|
||||||
|
|
||||||
def set_height(self, height):
|
# def set_height(self, height, stretch=False):
|
||||||
self.height = height
|
# self.height = height
|
||||||
return self
|
# return self
|
||||||
|
|
||||||
def set_width(self, width):
|
# def set_width(self, width, stretch=False):
|
||||||
self.width = width
|
# self.width = width
|
||||||
return self
|
# return self
|
||||||
|
|
||||||
def get_height(self):
|
def get_shape(self):
|
||||||
return self.height
|
return (self.get_width(), self.get_height())
|
||||||
|
|
||||||
def get_width(self):
|
|
||||||
return self.width
|
|
||||||
|
|
||||||
def get_center(self):
|
|
||||||
return self.points[0]
|
|
||||||
|
|
||||||
def get_focal_distance(self):
|
def get_focal_distance(self):
|
||||||
return self.focal_distance
|
return self.focal_distance
|
||||||
|
@ -389,7 +380,7 @@ class Camera(object):
|
||||||
transformed_light = np.dot(transform, [*light, 1])[:3]
|
transformed_light = np.dot(transform, [*light, 1])[:3]
|
||||||
mapping = {
|
mapping = {
|
||||||
'to_screen_space': tuple(transform.T.flatten()),
|
'to_screen_space': tuple(transform.T.flatten()),
|
||||||
'aspect_ratio': (pw / ph), # AR based on pixel shape
|
'frame_shape': self.frame.get_shape(),
|
||||||
'focal_distance': self.frame.get_focal_distance(),
|
'focal_distance': self.frame.get_focal_distance(),
|
||||||
'anti_alias_width': anti_alias_width,
|
'anti_alias_width': anti_alias_width,
|
||||||
'light_source_position': tuple(transformed_light),
|
'light_source_position': tuple(transformed_light),
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Assumes the following uniforms exist in the surrounding context:
|
// Assumes the following uniforms exist in the surrounding context:
|
||||||
// uniform float aspect_ratio;
|
// uniform vec2 frame_shape;
|
||||||
// uniform float focal_distance;
|
// uniform float focal_distance;
|
||||||
|
|
||||||
vec4 get_gl_Position(vec3 point){
|
vec4 get_gl_Position(vec3 point){
|
||||||
point.x /= aspect_ratio;
|
point.x *= 2 / frame_shape.x;
|
||||||
|
point.y *= 2 / frame_shape.y;
|
||||||
point.z /= focal_distance;
|
point.z /= focal_distance;
|
||||||
point.xy /= max(1 - point.z, 0);
|
point.xy /= max(1 - point.z, 0);
|
||||||
// Todo, does this discontinuity add weirdness? Theoretically, by this point,
|
// Todo, does this discontinuity add weirdness? Theoretically, by this point,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
uniform mat4 to_screen_space;
|
uniform mat4 to_screen_space;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
|
|
|
@ -5,7 +5,7 @@ layout (triangle_strip, max_vertices = 5) out;
|
||||||
|
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
// Needed for get_gl_Position
|
// Needed for get_gl_Position
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
uniform vec3 light_source_position;
|
uniform vec3 light_source_position;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ layout (triangles) in;
|
||||||
layout (triangle_strip, max_vertices = 5) out;
|
layout (triangle_strip, max_vertices = 5) out;
|
||||||
|
|
||||||
// Needed for get_gl_Position
|
// Needed for get_gl_Position
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
uniform vec3 light_source_position;
|
uniform vec3 light_source_position;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Assumes the following uniforms exist in the surrounding context:
|
// Assumes the following uniforms exist in the surrounding context:
|
||||||
// uniform float aspect_ratio;
|
// uniform vec2 frame_shape;
|
||||||
// TODO, rename
|
// TODO, rename
|
||||||
|
|
||||||
vec3 get_gl_Position(vec3 point){
|
vec3 get_gl_Position(vec3 point){
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
uniform mat4 to_screen_space;
|
uniform mat4 to_screen_space;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
uniform mat4 to_screen_space;
|
uniform mat4 to_screen_space;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
uniform float aspect_ratio;
|
uniform vec2 frame_shape;
|
||||||
uniform float anti_alias_width;
|
uniform float anti_alias_width;
|
||||||
uniform mat4 to_screen_space;
|
uniform mat4 to_screen_space;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
|
|
Loading…
Add table
Reference in a new issue