diff options
| author | realtradam <[email protected]> | 2021-04-24 13:57:31 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-04-24 13:57:31 -0400 |
| commit | 8968999c513b4ce3cac9f5907199235006bb6a11 (patch) | |
| tree | b132cf991ff09a7a1fe74a3899be253c704ec84d /lib/camera/wrappers/square_wrapper.rb | |
| parent | 645974e42ce72c95a3ba9f9de2278e71d89ffa6c (diff) | |
| download | ruby2d-camera-8968999c513b4ce3cac9f5907199235006bb6a11.tar.gz ruby2d-camera-8968999c513b4ce3cac9f5907199235006bb6a11.zip | |
.
Diffstat (limited to 'lib/camera/wrappers/square_wrapper.rb')
| -rw-r--r-- | lib/camera/wrappers/square_wrapper.rb | 128 |
1 files changed, 101 insertions, 27 deletions
diff --git a/lib/camera/wrappers/square_wrapper.rb b/lib/camera/wrappers/square_wrapper.rb index ce0831e..f828e0c 100644 --- a/lib/camera/wrappers/square_wrapper.rb +++ b/lib/camera/wrappers/square_wrapper.rb @@ -1,63 +1,137 @@ # 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 +# Wraps existing variables as well as adding new methods +# so that it can be handled by the Camera Module module SquareWrapped # Recalculates real coordiantes # Use after changing variables def update angle = Camera.angle * (Math::PI / 180) - half_size = Window.size * 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_size #- (size * Camera.zoom / 2) - @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height #- (size * Camera.zoom / 2) - @rotate = rotate + Camera.angle - @size = size * Camera.zoom + 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 - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming def x - @virtual_x ||= @x + @x ||= x1 end def x=(x) - @virtual_x = x + @x = x end def y - @virtual_y ||= @y + @y ||= y1 end def y=(y) - @virtual_y = y + @y = y end - def x - @virtual_x ||= @x + # 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 rotate - @virtual_rotate ||= @rotate + def x3 + @virtual_x3 ||= @x3 end - def rotate=(rotate) - @virtual_rotate = rotate + 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 - @virtual_size ||= @size + @size ||= 100 end def size=(size) - @virtual_size = size + @size = self.width = self.height = size end end end + |
