summaryrefslogtreecommitdiffhomepage
path: root/quad_camera_tracker.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-01-29 00:31:00 -0500
committerrealtradam <[email protected]>2021-01-29 00:31:00 -0500
commitbee6e8aa782895acefc6b40b2559f4d618a9466d (patch)
tree8d842ce28317bc23bd3bd56a0df07bd27a2e54ff /quad_camera_tracker.rb
parent7c87aec3da8f502bc5401264fc68dcefde25caf0 (diff)
downloadruby2d-camera-old-bee6e8aa782895acefc6b40b2559f4d618a9466d.tar.gz
ruby2d-camera-old-bee6e8aa782895acefc6b40b2559f4d618a9466d.zip
small progress
Diffstat (limited to 'quad_camera_tracker.rb')
-rw-r--r--quad_camera_tracker.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/quad_camera_tracker.rb b/quad_camera_tracker.rb
index de3e786..81c7561 100644
--- a/quad_camera_tracker.rb
+++ b/quad_camera_tracker.rb
@@ -23,9 +23,9 @@ module QuadCameraTracker
@y4 *= options[:zoom]
end
if options[:rotate]
- x_pivot = Camera.camera_position_x - x
- y_pivot = Camera.camera_position_y - y
- calc_angle = (Math::PI * angle) / 180
+ x_pivot = -x
+ y_pivot = -y
+ calc_angle = (Math::PI * options[:rotate]) / 180
x_shifted1 = x1 - x_pivot
y_shifted1 = y1 - y_pivot
x_shifted2 = x2 - x_pivot
@@ -49,8 +49,12 @@ module QuadCameraTracker
end
end
- def true_center
- [[@x1, @x2, @x3, @x4].min, [@y1, @y2, @y3, @y4].min]
+ # Uses a 'fast' method of getting the center
+ # perfectly accurate for squares and rectangles
+ # may be inaccurate for other quadrilaterals
+ def lazy_center
+ [([@x1, @x2, @x3, @x4].min + [@x1, @x2, @x3, @x4].max) / 2,
+ ([@y1, @y2, @y3, @y4].min + [@y1, @y2, @y3, @y4].max) / 2]
end
def width
@@ -96,6 +100,10 @@ module QuadCameraTracker
# offset rotation to shape
end
+ def x1_debug
+ @x1
+ end
+
def x1
@x1 / Camera.zoom_level + Camera.camera_position[0] - x
# undo rotation/translation/zoom