ruby2d-camera 1.1.1 → 1.2.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 828ab4d3439c8309d22514a0eb9b239616fd6476b28d0a93df8d937f3260e015
4
- data.tar.gz: e2e06eb639a63168b9822626ab00a8f0f3e2f78b1e5810ae3a9848d72852bacc
3
+ metadata.gz: b7cb8d6e9a5fc5471d273472c36336080cc975a323c3e8e68ad367b6d9e9c9d9
4
+ data.tar.gz: 04d27cefad0aef63d46b159cb2656963055b362c8a7dd64e1a2d507074479638
5
5
  SHA512:
6
- metadata.gz: c763e012f4c7e0ecde81fa6634f5b264818c9006656fdd69caece56afd0e7f9729113183b5ee7cec8ec4ba4399a645aa0f579d6da883e23d1b25e2e8be56cbbd
7
- data.tar.gz: 6c1b41ef44fd6df7ec4c7c758a64a34b167a69773a01dc0862be439944a2dea6833003d9376a9912aad7d0d5d4cf458acf841943d0f759b5b81123e5e35fe8d0
6
+ metadata.gz: d3b143c892900526f9a667157f7c168b8dcc8b96cef8b76f8caa3b446c6c65c14f1daecd701357d3a1eca6ec8cd1d92cf27bf1a5112a63480bff1c061f5dcc6f
7
+ data.tar.gz: d898f544cdb0cda38c53819edda7d5d175979f573521cb64e5bb352e40516a9043303a2bbe8888535c8f72814c7dbf1fc2a27f8372b8a9fe783c47a677439f81
data/CHANGELOG.mdown CHANGED
@@ -6,6 +6,11 @@
6
6
  ![Deprecated](https://img.shields.io/badge/-Deprecated-orange)
7
7
  ![Removed](https://img.shields.io/badge/-Removed-red)
8
8
 
9
+ ## 1.2.0-beta.1 - 2021-10-04
10
+ ![Added](https://img.shields.io/badge/-Added-brightgreen)
11
+ - Added rotation functions for Triangles, Quads, and Circles
12
+ - Need to finish the rest of the shapes to be ready for release
13
+
9
14
  ## [1.1.1](https://github.com/realtradam/ruby2d-camera/releases/tag/1.1.1) - 2021-09-24
10
15
  ![Fixed](https://img.shields.io/badge/-Fixed-blue)
11
16
  - Fixed changing z-index after the shape has been added not applying at all
@@ -11,12 +11,17 @@ module Ruby2D
11
11
  return if @hide
12
12
 
13
13
  angle = Camera.angle * (Math::PI / 180)
14
+ self_angle = self.angle * (Math::PI / 180)
14
15
  half_width = Window.width * 0.5
15
16
  half_height = Window.height * 0.5
16
17
  temp_radius = @radius * Camera.zoom
17
- temp_x = (((@x - Ruby2D::Camera.x + radius) * Math.cos(angle)) - ((@y - Ruby2D::Camera.y + radius) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
18
- temp_y = (((@x - Ruby2D::Camera.x + radius) * Math.sin(angle)) + ((@y - Ruby2D::Camera.y + radius) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
19
- Ruby2D::Circle.draw(x: temp_x, y: temp_y,
18
+ # rotate the shape
19
+ temp1_x = (x_offset * Math.cos(self_angle)) - (y_offset * Math.sin(self_angle)) + x
20
+ temp1_y = (y_offset * Math.cos(self_angle)) + (x_offset * Math.sin(self_angle)) + y
21
+ # apply the camera modifications
22
+ 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
23
+ 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
24
+ Ruby2D::Circle.draw(x: temp2_x, y: temp2_y,
20
25
  radius: temp_radius,
21
26
  sectors: sectors,
22
27
  color: [color.r, color.g, color.b, color.a])
@@ -24,13 +29,32 @@ module Ruby2D
24
29
 
25
30
  def initialize(opts = {})
26
31
  super(opts)
32
+ unless opts[:x_offset].nil?
33
+ self.x_offset = opts[:x_offset]
34
+ end
35
+ unless opts[:y_offset].nil?
36
+ self.y_offset = opts[:y_offset]
37
+ end
27
38
  Ruby2D::Camera << self
28
39
  Window.remove(self)
29
40
  end
30
41
 
31
- def z=(z)
32
- super(z)
33
- Ruby2D::Camera._sort_by_z
42
+ def angle
43
+ @angle ||= 0
44
+ end
45
+
46
+ def angle=(angle)
47
+ @angle = (angle % 360)
48
+ end
49
+
50
+ attr_writer :x_offset, :y_offset
51
+
52
+ def x_offset
53
+ @x_offset ||= 0
54
+ end
55
+
56
+ def y_offset
57
+ @y_offset ||= 0
34
58
  end
35
59
 
36
60
  def remove
@@ -11,20 +11,31 @@ module Ruby2D
11
11
  return if @hide
12
12
 
13
13
  angle = Camera.angle * (Math::PI / 180)
14
+ self_angle = self.angle * (Math::PI / 180)
14
15
  half_width = Window.width * 0.5
15
16
  half_height = Window.height * 0.5
16
- temp_x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
17
- temp_y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
18
- temp_x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
19
- temp_y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
20
- temp_x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
21
- temp_y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
22
- temp_x4 = (((x + x4 - Camera.x) * Math.cos(angle)) - ((y + y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
23
- temp_y4 = (((x + x4 - Camera.x) * Math.sin(angle)) + ((y + y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
24
- Ruby2D::Quad.draw(x1: temp_x1, y1: temp_y1,
25
- x2: temp_x2, y2: temp_y2,
26
- x3: temp_x3, y3: temp_y3,
27
- x4: temp_x4, y4: temp_y4,
17
+ # rotate the shape
18
+ temp1_x1 = (x1 * Math.cos(self_angle)) - (y1 * Math.sin(self_angle))
19
+ temp1_y1 = (y1 * Math.cos(self_angle)) + (x1 * Math.sin(self_angle))
20
+ temp1_x2 = (x2 * Math.cos(self_angle)) - (y2 * Math.sin(self_angle))
21
+ temp1_y2 = (y2 * Math.cos(self_angle)) + (x2 * Math.sin(self_angle))
22
+ temp1_x3 = (x3 * Math.cos(self_angle)) - (y3 * Math.sin(self_angle))
23
+ temp1_y3 = (y3 * Math.cos(self_angle)) + (x3 * Math.sin(self_angle))
24
+ temp1_x4 = (x4 * Math.cos(self_angle)) - (y4 * Math.sin(self_angle))
25
+ temp1_y4 = (y4 * Math.cos(self_angle)) + (x4 * Math.sin(self_angle))
26
+ # apply the camera modifications
27
+ temp2_x1 = (((x + temp1_x1 - Camera.x) * Math.cos(angle)) - ((y + temp1_y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
28
+ temp2_y1 = (((x + temp1_x1 - Camera.x) * Math.sin(angle)) + ((y + temp1_y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
29
+ temp2_x2 = (((x + temp1_x2 - Camera.x) * Math.cos(angle)) - ((y + temp1_y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
30
+ temp2_y2 = (((x + temp1_x2 - Camera.x) * Math.sin(angle)) + ((y + temp1_y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
31
+ temp2_x3 = (((x + temp1_x3 - Camera.x) * Math.cos(angle)) - ((y + temp1_y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
32
+ temp2_y3 = (((x + temp1_x3 - Camera.x) * Math.sin(angle)) + ((y + temp1_y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
33
+ temp2_x4 = (((x + temp1_x4 - Camera.x) * Math.cos(angle)) - ((y + temp1_y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
34
+ temp2_y4 = (((x + temp1_x4 - Camera.x) * Math.sin(angle)) + ((y + temp1_y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
35
+ Ruby2D::Quad.draw(x1: temp2_x1, y1: temp2_y1,
36
+ x2: temp2_x2, y2: temp2_y2,
37
+ x3: temp2_x3, y3: temp2_y3,
38
+ x4: temp2_x4, y4: temp2_y4,
28
39
  color: [
29
40
  [c1.r, c1.g, c1.b, c1.a],
30
41
  [c2.r, c2.g, c2.b, c2.a],
@@ -48,6 +59,14 @@ module Ruby2D
48
59
  @hide = false
49
60
  end
50
61
 
62
+ def angle
63
+ @angle ||= 0
64
+ end
65
+
66
+ def angle=(angle)
67
+ @angle = (angle % 360)
68
+ end
69
+
51
70
  # Methods for moving the shape
52
71
  attr_writer :x, :y
53
72
 
@@ -9,17 +9,26 @@ module Ruby2D
9
9
  return if @hide
10
10
 
11
11
  angle = Ruby2D::Camera.angle * (Math::PI / 180)
12
+ self_angle = self.angle * (Math::PI / 180)
12
13
  half_width = Window.width * 0.5
13
14
  half_height = Window.height * 0.5
14
- temp_x1 = (((x + @x1 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y1 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
15
- temp_y1 = (((x + @x1 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y1 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
16
- temp_x2 = (((x + @x2 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y2 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
17
- temp_y2 = (((x + @x2 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y2 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
18
- temp_x3 = (((x + @x3 - Ruby2D::Camera.x) * Math.cos(angle)) - ((y + @y3 - Ruby2D::Camera.y) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width
19
- temp_y3 = (((x + @x3 - Ruby2D::Camera.x) * Math.sin(angle)) + ((y + @y3 - Ruby2D::Camera.y) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height
20
- Ruby2D::Triangle.draw(x1: temp_x1, y1: temp_y1,
21
- x2: temp_x2, y2: temp_y2,
22
- x3: temp_x3, y3: temp_y3,
15
+ # rotate the shape
16
+ temp1_x1 = (x1 * Math.cos(self_angle)) - (y1 * Math.sin(self_angle))
17
+ temp1_y1 = (y1 * Math.cos(self_angle)) + (x1 * Math.sin(self_angle))
18
+ temp1_x2 = (x2 * Math.cos(self_angle)) - (y2 * Math.sin(self_angle))
19
+ temp1_y2 = (y2 * Math.cos(self_angle)) + (x2 * Math.sin(self_angle))
20
+ temp1_x3 = (x3 * Math.cos(self_angle)) - (y3 * Math.sin(self_angle))
21
+ temp1_y3 = (y3 * Math.cos(self_angle)) + (x3 * Math.sin(self_angle))
22
+ # apply camera operations
23
+ temp2_x1 = (((x + temp1_x1 - Camera.x) * Math.cos(angle)) - ((y + temp1_y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
24
+ temp2_y1 = (((x + temp1_x1 - Camera.x) * Math.sin(angle)) + ((y + temp1_y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
25
+ temp2_x2 = (((x + temp1_x2 - Camera.x) * Math.cos(angle)) - ((y + temp1_y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
26
+ temp2_y2 = (((x + temp1_x2 - Camera.x) * Math.sin(angle)) + ((y + temp1_y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
27
+ temp2_x3 = (((x + temp1_x3 - Camera.x) * Math.cos(angle)) - ((y + temp1_y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width
28
+ temp2_y3 = (((x + temp1_x3 - Camera.x) * Math.sin(angle)) + ((y + temp1_y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height
29
+ Ruby2D::Triangle.draw(x1: temp2_x1, y1: temp2_y1,
30
+ x2: temp2_x2, y2: temp2_y2,
31
+ x3: temp2_x3, y3: temp2_y3,
23
32
  color: [
24
33
  [c1.r, c1.g, c1.b, c1.a],
25
34
  [c2.r, c2.g, c2.b, c2.a],
@@ -43,6 +52,14 @@ module Ruby2D
43
52
  @hide = false
44
53
  end
45
54
 
55
+ def angle
56
+ @angle ||= 0
57
+ end
58
+
59
+ def angle=(angle)
60
+ @angle = (angle % 360)
61
+ end
62
+
46
63
  # Methods for moving the shape
47
64
  attr_writer :x, :y
48
65
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby2d
4
4
  module Camera
5
- VERSION = '1.1.1'
5
+ VERSION = '1.2.0-beta.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2d-camera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tradam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d
@@ -71,9 +71,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  version: 2.4.0
72
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - ">"
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: 1.3.1
77
77
  requirements: []
78
78
  rubygems_version: 3.2.22
79
79
  signing_key: