Fixed pixel_coords_to_space_coords

This commit is contained in:
Grant Sanderson 2020-02-14 10:52:39 -08:00
parent 0912043248
commit 1a0b0e748c
3 changed files with 5 additions and 9 deletions

View file

@ -184,7 +184,7 @@ class Camera(object):
self.frame.move_to(center) self.frame.move_to(center)
def pixel_coords_to_space_coords(self, px, py, relative=False): def pixel_coords_to_space_coords(self, px, py, relative=False):
pw, ph = self.get_pixel_shape() pw, ph = self.fbo.size
fw, fh = self.get_frame_shape() fw, fh = self.get_frame_shape()
fc = self.get_frame_center() fc = self.get_frame_center()
if relative: if relative:
@ -192,11 +192,7 @@ class Camera(object):
else: else:
# Only scale wrt one axis # Only scale wrt one axis
scale = fh / ph scale = fh / ph
return np.array([ return fc + scale * np.array([(px - pw / 2), (py - ph / 2), 0])
scale * (px - pw / 2) - fc[0],
scale * (py - py / 2) - fc[0],
-fc[2] / 2,
])
# TODO, account for 3d # TODO, account for 3d
# Also, move this to CameraFrame? # Also, move this to CameraFrame?
@ -293,7 +289,7 @@ class Camera(object):
mapping = { mapping = {
'scale': fh / 2, # Scale based on frame size 'scale': fh / 2, # Scale based on frame size
'aspect_ratio': (pw / ph), # AR based on pixel shape 'aspect_ratio': (pw / ph), # AR based on pixel shape
'anti_alias_width': ANTI_ALIAS_WIDTH, 'anti_alias_width': ANTI_ALIAS_WIDTH_OVER_FRAME_HEIGHT * fh,
'frame_center': tuple(fc), 'frame_center': tuple(fc),
} }
for key, value in mapping.items(): for key, value in mapping.items():

View file

@ -5,8 +5,8 @@
void set_gl_Position(vec3 point){ void set_gl_Position(vec3 point){
// TODO, orient in 3d based on certain rotation matrices // TODO, orient in 3d based on certain rotation matrices
point -= frame_center;
point /= scale; point /= scale;
point.x /= aspect_ratio; point.x /= aspect_ratio;
point -= frame_center;
gl_Position = vec4(point, 1.0); gl_Position = vec4(point, 1.0);
} }

View file

@ -43,7 +43,7 @@ class Window(PygletWindow):
super().on_mouse_drag(x, y, dx, dy, buttons, modifiers) super().on_mouse_drag(x, y, dx, dy, buttons, modifiers)
point = self.pixel_coords_to_space_coords(x, y) point = self.pixel_coords_to_space_coords(x, y)
d_point = self.pixel_coords_to_space_coords(dx, dy, relative=True) d_point = self.pixel_coords_to_space_coords(dx, dy, relative=True)
self.scene.on_mouse_drag(point, d_point, buttons, modifiers) # Do a conversion? self.scene.on_mouse_drag(point, d_point, buttons, modifiers)
def on_mouse_press(self, x: int, y: int, button, mods): def on_mouse_press(self, x: int, y: int, button, mods):
super().on_mouse_press(x, y, button, mods) super().on_mouse_press(x, y, button, mods)