From b3c67e70aa97c6ad6176917427b5a192b407dbd6 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 23 Jan 2021 02:17:59 -0500 Subject: reworking to work with quads --- camera.rb | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- run.rb | 7 ++- 2 files changed, 188 insertions(+), 7 deletions(-) diff --git a/camera.rb b/camera.rb index 1ccea91..0044794 100644 --- a/camera.rb +++ b/camera.rb @@ -2,26 +2,197 @@ # Simulates a moving camera by manipulating objects it knows class Camera + # Is added to quads to manage how they show and modify + # it should convert or undo the camera modification + # such that it is as if the camera wasnt there and everything + # is relative to the origin + module QuadCameraTracker + def update(x, y) + @x1 -= x + @x2 -= x + @x3 -= x + @x4 -= x + @y1 -= y + @y2 -= y + @y3 -= y + @y4 -= y + end + + def x + @x ||= 0 + end + + def x=(x) + diff = @x - x + self.x1 += diff + self.x2 += diff + self.x3 += diff + self.x4 += diff + @x = x + end + + def y + @y ||= 0 + end + + def y=(y) + diff = @y - y + self.y1 += diff + self.y2 += diff + self.y3 += diff + self.y4 += diff + @y = y + end + + def size + @size ||= 1 + end + + def size=(size) + # should resize based on the top left point + # offset rotation to shape + end + + def x1 + (@x1 + x) / Camera.zoom_level + Camera.camera_position[0] + # undo rotation/translation/zoom + end + + def x1=(x1) + @x1 = ((x1 + x) - Camera.camera_position[0]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def y1 + (@y1 + y) / Camera.zoom_level + Camera.camera_position[1] + # undo rotation/translation/zoom + end + + def y1=(y1) + @y1 = ((y1 + y) - Camera.camera_position[1]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def x2 + (@x2 + x) / Camera.zoom_level + Camera.camera_position[0] + # undo rotation/translation/zoom + end + + def x2=(x2) + @x2 = ((x2 + x) - Camera.camera_position[0]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def y2 + (@y2 + y) / Camera.zoom_level + Camera.camera_position[1] + # undo rotation/translation/zoom + end + + def y2=(y2) + @y2 = ((y2 + y) - Camera.camera_position[1]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def x3 + (@x3 + x) / Camera.zoom_level + Camera.camera_position[0] + # undo rotation/translation/zoom + end + + def x3=(x3) + @x1 = ((x3 + x) - Camera.camera_position[0]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def y3 + (@y3 + y) / Camera.zoom_level + Camera.camera_position[1] + # undo rotation/translation/zoom + end + + def y3=(y3) + @y3 = ((y3 + y) - Camera.camera_position[1]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def x4 + (@x4 + x) / Camera.zoom_level + Camera.camera_position[0] + # undo rotation/translation/zoom + end + + def x4=(x4) + @x4 = ((x4 + x) - Camera.camera_position[0]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def y4 + (@y4 + y) / Camera.zoom_level + Camera.camera_position[1] + # undo rotation/translation/zoom + end + + def y4=(y4) + @y4 = ((y4 + y) - Camera.camera_position[1]) * Camera.zoom_level + # add rotation level + # apply rotation/translation/zoom then pass to super + end + + def rotation_degrees + @rotation_degrees ||= 0 + end + + def rotate_degrees_by(degrees) + # offset rotation to shape + end + + def rotate_degree_to(degrees) + # set rotation + end + end class <