summaryrefslogtreecommitdiffhomepage
path: root/quad_camera_tracker.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-01-25 00:09:51 -0500
committerrealtradam <[email protected]>2021-01-25 00:09:51 -0500
commitc1476cb451e93a54df8521ad5572732539f345dd (patch)
tree2379fb6d3c1d5bd6f2cd667421f8f2604f6c520c /quad_camera_tracker.rb
parentb3c67e70aa97c6ad6176917427b5a192b407dbd6 (diff)
downloadruby2d-camera-old-c1476cb451e93a54df8521ad5572732539f345dd.tar.gz
ruby2d-camera-old-c1476cb451e93a54df8521ad5572732539f345dd.zip
finished implementing quads
Diffstat (limited to 'quad_camera_tracker.rb')
-rw-r--r--quad_camera_tracker.rb173
1 files changed, 173 insertions, 0 deletions
diff --git a/quad_camera_tracker.rb b/quad_camera_tracker.rb
new file mode 100644
index 0000000..d0bcd21
--- /dev/null
+++ b/quad_camera_tracker.rb
@@ -0,0 +1,173 @@
+# frozen_string_literal: true
+
+module QuadCameraTracker
+ def update(zoom: 1, x: 0, y: 0)
+ if x != 0 or y != 0
+ @x1 -= x
+ @x2 -= x
+ @x3 -= x
+ @x4 -= x
+ @y1 -= y
+ @y2 -= y
+ @y3 -= y
+ @y4 -= y
+ end
+ if zoom != 1
+ @x1 *= zoom
+ @x2 *= zoom
+ @x3 *= zoom
+ @x4 *= zoom
+ @y1 *= zoom
+ @y2 *= zoom
+ @y3 *= zoom
+ @y4 *= zoom
+ end
+ end
+
+ def true_center
+ [[@x1, @x2, @x3, @x4].min, [@y1, @y2, @y3, @y4].min]
+ end
+
+ def width
+ [@x1, @x2, @x3, @x4].max - [@x1, @x2, @x3, @x4].min
+ end
+
+ def height
+ [@y1, @y2, @y3, @y4].max - [@y1, @y2, @y3, @y4].min
+ end
+
+ def x
+ @x ||= 0
+ end
+
+ def x=(x)
+ diff = x - self.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 - self.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 / Camera.zoom_level + Camera.camera_position[0] - x
+ # 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 / Camera.zoom_level + Camera.camera_position[1] - y
+ # 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) / Camera.zoom_level + Camera.camera_position[0] - x
+ # 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) / Camera.zoom_level + Camera.camera_position[1] - y
+ # 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) / Camera.zoom_level + Camera.camera_position[0] - x
+ # undo rotation/translation/zoom
+ end
+
+ def x3=(x3)
+ @x3 = ((x3 + x) - Camera.camera_position[0]) * Camera.zoom_level
+ # add rotation level
+ # apply rotation/translation/zoom then pass to super
+ end
+
+ def y3
+ (@y3) / Camera.zoom_level + Camera.camera_position[1] - y
+ # 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 / Camera.zoom_level + Camera.camera_position[0] - x
+ # 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 / Camera.zoom_level + Camera.camera_position[1] - y
+ # 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