diff options
Diffstat (limited to 'lib/ruby2d/camera')
| -rw-r--r-- | lib/ruby2d/camera/circle.rb | 31 | ||||
| -rw-r--r-- | lib/ruby2d/camera/triangle.rb | 67 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/circle_wrapper.rb | 47 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/image_wrapper.rb | 73 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/line_wrapper.rb | 91 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/quad_wrapper.rb | 108 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/rectangle_wrapper.rb | 138 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/sprite_wrapper.rb | 86 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/square_wrapper.rb | 146 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/text_wrapper.rb | 84 | ||||
| -rw-r--r-- | lib/ruby2d/camera/wrappers/triangle_wrapper.rb | 90 |
11 files changed, 39 insertions, 922 deletions
diff --git a/lib/ruby2d/camera/circle.rb b/lib/ruby2d/camera/circle.rb new file mode 100644 index 0000000..a7416a2 --- /dev/null +++ b/lib/ruby2d/camera/circle.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Ruby2D + module Camera + # Wraps existing variables as well as adding new methods + # so that it can be handled by the Camera Module + class Circle < Ruby2D::Circle + # Recalculates real coordiantes + # Use after changing variables + def _draw + angle = Camera.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: tempy, + radius: temp_radius, + sectors: @sectors, + color: [self.color.r, self.color.g, self.color.b, self.color.a]) + + end + + def initialize(otps= {}) + super(opts) + Ruby2D::Camera << self + self.remove + end + end + end +end diff --git a/lib/ruby2d/camera/triangle.rb b/lib/ruby2d/camera/triangle.rb index cac74b8..9d3fbbf 100644 --- a/lib/ruby2d/camera/triangle.rb +++ b/lib/ruby2d/camera/triangle.rb @@ -2,9 +2,7 @@ module Ruby2D module Camera - # Wraps existing variables as well as adding new methods - # so that it can be handled by the Ruby2D::Camera Module - class Triangle << Ruby2D::Triangle + class Triangle < Ruby2D::Triangle # Recalculates real coordiantes # Use after changing variables def _draw @@ -17,15 +15,18 @@ module Ruby2D temp_y2 = (((x + @x2 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y2 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height temp_x3 = (((x + @x3 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y3 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width temp_y3 = (((x + @x3 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y3 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height - self.draw(x1: temp_x1, y1: temp_y1, - x2: temp_x2, y2: temp_y2, - x3: temp_x3, y3: temp_y3) + Ruby2D::Triangle.draw(x1: temp_x1, y1: temp_y1, + x2: temp_x2, y2: temp_y2, + x3: temp_x3, y3: temp_y3, + color: [[self.c1.r, self.c1.g, self.c1.b, self.c1.a], + [self.c2.r, self.c2.g, self.c2.b, self.c2.a], + [self.c3.r, self.c3.g, self.c3.b, self.c3.a]]) end def initialize(opts= {}) - #add to camera? super(opts) Ruby2D::Camera << self + self.remove end #Methods for moving the shape @@ -44,58 +45,6 @@ module Ruby2D def y=(y) @y = y end -=begin - # Wrappers for the coordinates so that - # they are handled by the Ruby2D::Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end -=end end end end diff --git a/lib/ruby2d/camera/wrappers/circle_wrapper.rb b/lib/ruby2d/camera/wrappers/circle_wrapper.rb deleted file mode 100644 index a7db05a..0000000 --- a/lib/ruby2d/camera/wrappers/circle_wrapper.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module - module CircleWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @radius = radius * Camera.zoom - @x = (((x - Camera.x + radius) * Math.cos(angle)) - ((y - Camera.y + radius) * Math.sin(angle))) * Camera.zoom + half_width - @y = (((x - Camera.x + radius) * Math.sin(angle)) + ((y - Camera.y + radius) * Math.cos(angle))) * Camera.zoom + half_height - end - - # Methods for moving the shape as well as - # wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x - @virtual_x ||= @x - end - - def x=(x) - @virtual_x = x - end - - def y - @virtual_y ||= @y - end - - def y=(y) - @virtual_y = y - end - - def radius - @virtual_radius ||= @radius - end - - def radius=(radius) - @virtual_radius = radius - end - end -end - diff --git a/lib/ruby2d/camera/wrappers/image_wrapper.rb b/lib/ruby2d/camera/wrappers/image_wrapper.rb deleted file mode 100644 index 9e4b163..0000000 --- a/lib/ruby2d/camera/wrappers/image_wrapper.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true - -module Camera - # Wraps existing variables as well as adding new methods - # so that it can be handled by the Camera Module - module ImageWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - offset_x = x + (width / 2) - offset_y = y + (height / 2) - @x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \ - * Camera.zoom + half_width - (width * Camera.zoom / 2) - @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height - (height * Camera.zoom / 2) - @rotate = rotate + Camera.angle - @width = width * Camera.zoom - @height = height * Camera.zoom - end - - #Methods for moving the shape - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x - @virtual_x ||= @x - end - - def x=(x) - @virtual_x = x - end - - def y - @virtual_y ||= @y - end - - def y=(y) - @virtual_y = y - end - - def x - @virtual_x ||= @x - end - - def rotate - @virtual_rotate ||= @rotate - end - - def rotate=(rotate) - @virtual_rotate = rotate - end - - def width - @virtual_width ||= @width - end - - def width=(width) - @virtual_width = width - end - - def height - @virtual_height ||= @height - end - - def height=(height) - @virtual_height = height - end - end -end diff --git a/lib/ruby2d/camera/wrappers/line_wrapper.rb b/lib/ruby2d/camera/wrappers/line_wrapper.rb deleted file mode 100644 index 7d4d944..0000000 --- a/lib/ruby2d/camera/wrappers/line_wrapper.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module - module LineWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @width = width * Camera.zoom - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def width - @virtual_width ||= @width - end - - def width=(width) - @virtual_width = width - end - - def length - points_distance(x1, y1, x2, y2) - end - - def contains?(x, y) - points_distance(x1, y1, x, y) <= length && - points_distance(x2, y2, x, y) <= length && - (((y2 - y1) * x - (x2 - x1) * y + x2 * y1 - y2 * x1).abs / length) <= 0.5 * width - end - end -end - diff --git a/lib/ruby2d/camera/wrappers/quad_wrapper.rb b/lib/ruby2d/camera/wrappers/quad_wrapper.rb deleted file mode 100644 index 477dbfd..0000000 --- a/lib/ruby2d/camera/wrappers/quad_wrapper.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module - module QuadWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x4 = (((x + x4 - Camera.x) * Math.cos(angle)) - ((y + y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y4 = (((x + x4 - Camera.x) * Math.sin(angle)) + ((y + y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end - - def x4 - @virtual_x4 ||= @x4 - end - - def x4=(x4) - @virtual_x4 = x4 - end - - def y4 - @virtual_y4 ||= @y4 - end - - def y4=(y4) - @virtual_y4 = y4 - end - end -end - diff --git a/lib/ruby2d/camera/wrappers/rectangle_wrapper.rb b/lib/ruby2d/camera/wrappers/rectangle_wrapper.rb deleted file mode 100644 index 93e888a..0000000 --- a/lib/ruby2d/camera/wrappers/rectangle_wrapper.rb +++ /dev/null @@ -1,138 +0,0 @@ -# frozen_string_literal: true - -module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module - module RectangleWrapped - # Rectangles are part of the exception where - # their x and y variables need to be reset - # when wrapped - def self.extended(obj) - obj.instance_exec do - @x = 0 - @y = 0 - end - end - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x4 = (((x + x4 - Camera.x) * Math.cos(angle)) - ((y + y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y4 = (((x + x4 - Camera.x) * Math.sin(angle)) + ((y + y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end - - def x4 - @virtual_x4 ||= @x4 - end - - def x4=(x4) - @virtual_x4 = x4 - end - - def y4 - @virtual_y4 ||= @y4 - end - - def y4=(y4) - @virtual_y4 = y4 - end - - - def width - @width ||= 200 - end - - def width=(width) - self.x2 = width - self.x3 = width - @width = width - end - - def height - @height ||= 100 - end - - def height=(height) - self.y3 = height - self.y4 = height - @height = height - end - end -end - diff --git a/lib/ruby2d/camera/wrappers/sprite_wrapper.rb b/lib/ruby2d/camera/wrappers/sprite_wrapper.rb deleted file mode 100644 index d38c0bc..0000000 --- a/lib/ruby2d/camera/wrappers/sprite_wrapper.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -module Camera - # Wraps existing variables as well as adding new methods - # so that it can be handled by the Camera Module - module SpriteWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - offset_x = x + (width / 2) - offset_y = y + (height / 2) - @x = @flip_x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \ - * Camera.zoom + half_width - (width * Camera.zoom / 2) - @y = @flip_y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height - (height * Camera.zoom / 2) - @rotate = rotate + Camera.angle - @width = @flip_width = width * Camera.zoom - @height = @flip_height = height * Camera.zoom - case @flip - when :both - @flip_x = @x + @height - @flip_width = -@width - @flip_y = @y + @width - @flip_height = -@height - when :horizontal - @flip_y = @y + @width - @flip_height = -@height - when :vertical - @flip_x = @x + @height - @flip_width = -@width - end - end - - #Methods for moving the shape - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x - @virtual_x ||= @x - end - - def x=(x) - @virtual_x = x - end - - def y - @virtual_y ||= @y - end - - def y=(y) - @virtual_y = y - end - - def x - @virtual_x ||= @x - end - - def rotate - @virtual_rotate ||= @rotate - end - - def rotate=(rotate) - @virtual_rotate = rotate - end - - def width - @virtual_width ||= @width - end - - def width=(width) - @virtual_width = width - end - - def height - @virtual_height ||= @height - end - - def height=(height) - @virtual_height = height - end - end -end diff --git a/lib/ruby2d/camera/wrappers/square_wrapper.rb b/lib/ruby2d/camera/wrappers/square_wrapper.rb deleted file mode 100644 index 2215a30..0000000 --- a/lib/ruby2d/camera/wrappers/square_wrapper.rb +++ /dev/null @@ -1,146 +0,0 @@ -# frozen_string_literal: true - -module Camera - # Wraps existing variables as well as adding new methods - # so that it can be handled by the Camera Module - module SquareWrapped - # Squares are part of the exception where - # their x and y variables need to be reset - # when wrapped - def self.extended(obj) - obj.instance_exec do - @x = 0 - @y = 0 - end - end - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x4 = (((x + x4 - Camera.x) * Math.cos(angle)) - ((y + y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y4 = (((x + x4 - Camera.x) * Math.sin(angle)) + ((y + y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end - - def x4 - @virtual_x4 ||= @x4 - end - - def x4=(x4) - @virtual_x4 = x4 - end - - def y4 - @virtual_y4 ||= @y4 - end - - def y4=(y4) - @virtual_y4 = y4 - end - - - def width - @width ||= 200 - end - - def width=(width) - self.x2 = width - self.x3 = width - @width = width - end - - def height - @height ||= 100 - end - - def height=(height) - self.y3 = height - self.y4 = height - @height = height - end - - def size - @size ||= 100 - end - - def size=(size) - @size = self.width = self.height = size - end - end -end - diff --git a/lib/ruby2d/camera/wrappers/text_wrapper.rb b/lib/ruby2d/camera/wrappers/text_wrapper.rb deleted file mode 100644 index ad96881..0000000 --- a/lib/ruby2d/camera/wrappers/text_wrapper.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -module Camera - # Wraps existing variables as well as adding new methods - # so that it can be handled by the Camera Module - # TODO: note that text could not be resized at the current iteration - # of Ruby2D so the math needs to be changed compensate for this. - # When Ruby2D gets updated to allow text resizing the math will need - # to be corrected again(see image_wrapper.rb for reference, that has - # math that allows for resizing) - module TextWrapped - @center = false - - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - if center - offset_y = y + (Camera.zoom / 2) - offset_x = x + (Camera.zoom / 2) - else - offset_x = x + (width / Camera.zoom / 2) - offset_y = y + (height / Camera.zoom / 2) - end - @x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \ - * Camera.zoom + half_width - (width / 2) - @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height - (height / 2) - @rotate = rotate + Camera.angle - @size = size * Camera.zoom - end - - #Methods for moving the shape - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x - @virtual_x ||= @x - end - - def x=(x) - @virtual_x = x - end - - def y - @virtual_y ||= @y - end - - def y=(y) - @virtual_y = y - end - - def x - @virtual_x ||= @x - end - - def rotate - @virtual_rotate ||= @rotate - end - - def rotate=(rotate) - @virtual_rotate = rotate - end - - def size - @virtual_size ||= @size - end - - def size=(size) - @virtual_size = size - end - - def center - @center - end - - def center=(center) - @center = center - end - end -end diff --git a/lib/ruby2d/camera/wrappers/triangle_wrapper.rb b/lib/ruby2d/camera/wrappers/triangle_wrapper.rb deleted file mode 100644 index 0aba2c0..0000000 --- a/lib/ruby2d/camera/wrappers/triangle_wrapper.rb +++ /dev/null @@ -1,90 +0,0 @@ -# frozen_string_literal: true - -module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module - module TriangleWrapped - # Recalculates real coordiantes - # Use after changing variables - def redraw - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end - end -end - |
