summaryrefslogtreecommitdiffhomepage
path: root/lib/ruby2d/camera/circle.rb
diff options
context:
space:
mode:
authortradam <git.tradam.fyi>2021-10-04 03:41:14 -0400
committertradam <git.tradam.fyi>2021-10-04 03:41:14 -0400
commitc795c2a1a2f61056f1e3f5302b167703798e3ac4 (patch)
tree9d6b4a6a98359fcaba83a753cde7bf9801d972fd /lib/ruby2d/camera/circle.rb
parentc326eb2b27921f584ac46c484dab9be2cddb90f7 (diff)
downloadruby2d-camera-dev.tar.gz
ruby2d-camera-dev.zip
Added rotations for circle, triangle, and quaddev1.2.0-beta.1
Diffstat (limited to 'lib/ruby2d/camera/circle.rb')
-rw-r--r--lib/ruby2d/camera/circle.rb36
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/ruby2d/camera/circle.rb b/lib/ruby2d/camera/circle.rb
index 2896055..98c5152 100644
--- a/lib/ruby2d/camera/circle.rb
+++ b/lib/ruby2d/camera/circle.rb
@@ -11,12 +11,17 @@ module Ruby2D
return if @hide
angle = Camera.angle * (Math::PI / 180)
+ self_angle = self.angle * (Math::PI / 180)
half_width = Window.width * 0.5
half_height = Window.height * 0.5
temp_radius = @radius * Camera.zoom
- temp_x = (((@x - Ruby2D::Camera.x + radius) * Math.cos(angle)) - ((@y - Ruby2D::Camera.y + radius) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
- temp_y = (((@x - Ruby2D::Camera.x + radius) * Math.sin(angle)) + ((@y - Ruby2D::Camera.y + radius) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
- Ruby2D::Circle.draw(x: temp_x, y: temp_y,
+ # rotate the shape
+ temp1_x = (x_offset * Math.cos(self_angle)) - (y_offset * Math.sin(self_angle)) + x
+ temp1_y = (y_offset * Math.cos(self_angle)) + (x_offset * Math.sin(self_angle)) + y
+ # apply the camera modifications
+ temp2_x = (((temp1_x - Ruby2D::Camera.x - radius) * Math.cos(angle)) - ((temp1_y - Ruby2D::Camera.y - radius) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
+ temp2_y = (((temp1_x - Ruby2D::Camera.x - radius) * Math.sin(angle)) + ((temp1_y - Ruby2D::Camera.y - radius) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
+ Ruby2D::Circle.draw(x: temp2_x, y: temp2_y,
radius: temp_radius,
sectors: sectors,
color: [color.r, color.g, color.b, color.a])
@@ -24,13 +29,32 @@ module Ruby2D
def initialize(opts = {})
super(opts)
+ unless opts[:x_offset].nil?
+ self.x_offset = opts[:x_offset]
+ end
+ unless opts[:y_offset].nil?
+ self.y_offset = opts[:y_offset]
+ end
Ruby2D::Camera << self
Window.remove(self)
end
- def z=(z)
- super(z)
- Ruby2D::Camera._sort_by_z
+ def angle
+ @angle ||= 0
+ end
+
+ def angle=(angle)
+ @angle = (angle % 360)
+ end
+
+ attr_writer :x_offset, :y_offset
+
+ def x_offset
+ @x_offset ||= 0
+ end
+
+ def y_offset
+ @y_offset ||= 0
end
def remove