gosling 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gosling/actor.rb +234 -54
- data/lib/gosling/circle.rb +27 -5
- data/lib/gosling/collision.rb +55 -20
- data/lib/gosling/image_library.rb +7 -0
- data/lib/gosling/patches.rb +42 -0
- data/lib/gosling/polygon.rb +39 -11
- data/lib/gosling/rect.rb +13 -4
- data/lib/gosling/sprite.rb +14 -0
- data/lib/gosling/transform.rb +264 -163
- data/lib/gosling/utils.rb +20 -0
- data/lib/gosling/version.rb +5 -1
- data/spec/actor_spec.rb +47 -44
- data/spec/circle_spec.rb +2 -3
- data/spec/collision_spec.rb +207 -206
- data/spec/polygon_spec.rb +36 -36
- data/spec/rect_spec.rb +12 -12
- data/spec/transform_spec.rb +138 -149
- metadata +18 -2
data/spec/polygon_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Gosling::Polygon do
|
|
7
7
|
describe '#get_vertices' do
|
8
8
|
it 'returns a list of three or more vertices' do
|
9
9
|
expect(@polygon.get_vertices).to be_instance_of(Array)
|
10
|
-
expect(@polygon.get_vertices[0]).to be_instance_of(
|
10
|
+
expect(@polygon.get_vertices[0]).to be_instance_of(Snow::Vec3)
|
11
11
|
expect(@polygon.get_vertices.length).to be >= 3
|
12
12
|
end
|
13
13
|
end
|
@@ -15,10 +15,10 @@ describe Gosling::Polygon do
|
|
15
15
|
describe '#set_vertices' do
|
16
16
|
it 'assigns new vertices' do
|
17
17
|
vertices = [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
Snow::Vec3[ 1, 0, 1],
|
19
|
+
Snow::Vec3[ 0, 1, 1],
|
20
|
+
Snow::Vec3[-1, 0, 1],
|
21
|
+
Snow::Vec3[ 0, -1, 1],
|
22
22
|
]
|
23
23
|
|
24
24
|
polygon = Gosling::Polygon.new(@window)
|
@@ -45,8 +45,8 @@ describe Gosling::Polygon do
|
|
45
45
|
|
46
46
|
it 'raises an error if the parameter array is too short' do
|
47
47
|
vertices = [
|
48
|
-
|
49
|
-
|
48
|
+
Snow::Vec3[ 1, 0, 1],
|
49
|
+
Snow::Vec3[ 0, 1, 1]
|
50
50
|
]
|
51
51
|
|
52
52
|
polygon = Gosling::Polygon.new(@window)
|
@@ -55,10 +55,10 @@ describe Gosling::Polygon do
|
|
55
55
|
|
56
56
|
it 'raises an error if any vertices in the parameter array are not length 3' do
|
57
57
|
vertices = [
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
Snow::Vec3[ 1, 0, 1],
|
59
|
+
Snow::Vec3[ 0, 1, 0],
|
60
|
+
Snow::Vec2[-1, 0],
|
61
|
+
Snow::Vec3[ 0, -1, 3],
|
62
62
|
]
|
63
63
|
|
64
64
|
polygon = Gosling::Polygon.new(@window)
|
@@ -70,17 +70,17 @@ describe Gosling::Polygon do
|
|
70
70
|
before(:all) do
|
71
71
|
@global_polygon = Gosling::Polygon.new(@window)
|
72
72
|
@global_polygon.set_vertices([
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
Snow::Vec3[1, 1, 0],
|
74
|
+
Snow::Vec3[0, -1, 0],
|
75
|
+
Snow::Vec3[-1, -1, 0],
|
76
|
+
Snow::Vec3[-1, 2, 0]
|
77
77
|
])
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'returns a list of three or more vertices' do
|
81
81
|
result = @global_polygon.get_global_vertices
|
82
82
|
expect(result).to be_instance_of(Array)
|
83
|
-
expect(result[0]).to be_instance_of(
|
83
|
+
expect(result[0]).to be_instance_of(Snow::Vec3)
|
84
84
|
expect(result.length).to be >= 3
|
85
85
|
end
|
86
86
|
|
@@ -95,10 +95,10 @@ describe Gosling::Polygon do
|
|
95
95
|
|
96
96
|
vertices = @global_polygon.get_global_vertices
|
97
97
|
expect(vertices).to be == [
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
Snow::Vec3[-9, -1, 0],
|
99
|
+
Snow::Vec3[-10, -3, 0],
|
100
|
+
Snow::Vec3[-11, -3, 0],
|
101
|
+
Snow::Vec3[-11, 0, 0]
|
102
102
|
]
|
103
103
|
end
|
104
104
|
|
@@ -113,10 +113,10 @@ describe Gosling::Polygon do
|
|
113
113
|
|
114
114
|
vertices = @global_polygon.get_global_vertices
|
115
115
|
expect(vertices).to be == [
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
Snow::Vec3[3, 2, 0],
|
117
|
+
Snow::Vec3[0, -2, 0],
|
118
|
+
Snow::Vec3[-3, -2, 0],
|
119
|
+
Snow::Vec3[-3, 4, 0]
|
120
120
|
]
|
121
121
|
end
|
122
122
|
|
@@ -131,10 +131,10 @@ describe Gosling::Polygon do
|
|
131
131
|
|
132
132
|
vertices = @global_polygon.get_global_vertices
|
133
133
|
expect(vertices).to be == [
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
134
|
+
Snow::Vec3[1, -1, 0],
|
135
|
+
Snow::Vec3[-1, 0, 0],
|
136
|
+
Snow::Vec3[-1, 1, 0],
|
137
|
+
Snow::Vec3[2, 1, 0]
|
138
138
|
]
|
139
139
|
end
|
140
140
|
|
@@ -149,10 +149,10 @@ describe Gosling::Polygon do
|
|
149
149
|
|
150
150
|
vertices = @global_polygon.get_global_vertices
|
151
151
|
expect(vertices).to be == [
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
Snow::Vec3[-49, 11, 0],
|
153
|
+
Snow::Vec3[-50, 9, 0],
|
154
|
+
Snow::Vec3[-51, 9, 0],
|
155
|
+
Snow::Vec3[-51, 12, 0]
|
156
156
|
]
|
157
157
|
end
|
158
158
|
|
@@ -198,10 +198,10 @@ describe Gosling::Polygon do
|
|
198
198
|
it 'respects all ancestors' do
|
199
199
|
vertices = @global_polygon.get_global_vertices
|
200
200
|
expect(vertices).to be == [
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
201
|
+
Snow::Vec3[(1 + 10) * 3 - 10, (1 - 50) * -2 - 2, 0],
|
202
|
+
Snow::Vec3[(-1 + 10) * 3 - 10, (0 - 50) * -2 - 2, 0],
|
203
|
+
Snow::Vec3[(-1 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0],
|
204
|
+
Snow::Vec3[(2 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0]
|
205
205
|
]
|
206
206
|
end
|
207
207
|
|
data/spec/rect_spec.rb
CHANGED
@@ -30,10 +30,10 @@ describe Gosling::Rect do
|
|
30
30
|
|
31
31
|
it 'updates our vertices' do
|
32
32
|
expected_vertices = [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
Snow::Vec3[ 0, 0, 0],
|
34
|
+
Snow::Vec3[11, 0, 0],
|
35
|
+
Snow::Vec3[11, 1, 0],
|
36
|
+
Snow::Vec3[ 0, 1, 0]
|
37
37
|
]
|
38
38
|
|
39
39
|
rect = Gosling::Rect.new(@window)
|
@@ -63,10 +63,10 @@ describe Gosling::Rect do
|
|
63
63
|
|
64
64
|
it 'updates our vertices' do
|
65
65
|
expected_vertices = [
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
Snow::Vec3[0, 0, 0],
|
67
|
+
Snow::Vec3[1, 0, 0],
|
68
|
+
Snow::Vec3[1, 40, 0],
|
69
|
+
Snow::Vec3[0, 40, 0]
|
70
70
|
]
|
71
71
|
|
72
72
|
rect = Gosling::Rect.new(@window)
|
@@ -77,10 +77,10 @@ describe Gosling::Rect do
|
|
77
77
|
|
78
78
|
it 'does not allow set_vertices to be called directly' do
|
79
79
|
vertices = [
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
Snow::Vec3[0, 0, 0],
|
81
|
+
Snow::Vec3[1, 10, 0],
|
82
|
+
Snow::Vec3[2, 20, 0],
|
83
|
+
Snow::Vec3[3, 40, 0]
|
84
84
|
]
|
85
85
|
expect { @rect.set_vertices(vertices) }.to raise_error(NoMethodError)
|
86
86
|
end
|
data/spec/transform_spec.rb
CHANGED
@@ -4,50 +4,49 @@ describe Gosling::Transform do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'has a center' do
|
7
|
-
expect(@read_only_tf.center).to be_instance_of(
|
7
|
+
expect(@read_only_tf.center).to be_instance_of(Snow::Vec3)
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'has a scale' do
|
11
|
-
expect(@read_only_tf.scale).to be_instance_of(
|
11
|
+
expect(@read_only_tf.scale).to be_instance_of(Snow::Vec2)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has a rotation' do
|
15
|
-
expect(@read_only_tf.rotation).to
|
15
|
+
expect(@read_only_tf.rotation).to be_kind_of(Numeric)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has a translation' do
|
19
|
-
expect(@read_only_tf.translation).to be_instance_of(
|
19
|
+
expect(@read_only_tf.translation).to be_instance_of(Snow::Vec3)
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '#
|
22
|
+
describe '#center=' do
|
23
23
|
it 'accepts a size 3 vector' do
|
24
24
|
tf = Gosling::Transform.new
|
25
|
-
expect { tf.
|
26
|
-
expect { tf.
|
27
|
-
expect { tf.
|
28
|
-
expect { tf.set_center(:foo) }.to raise_error(ArgumentError)
|
25
|
+
expect { tf.center = Snow::Vec3[0, 0, 0] }.not_to raise_error
|
26
|
+
expect { tf.center = [0, 0, 0] }.not_to raise_error
|
27
|
+
expect { tf.center = :foo }.to raise_error(ArgumentError)
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'sets the center transform' do
|
32
|
-
v =
|
31
|
+
v = Snow::Vec3[10.to_r, 20.to_r, 1.to_r]
|
33
32
|
tf = Gosling::Transform.new
|
34
|
-
tf.
|
33
|
+
tf.center = v
|
35
34
|
expect(tf.center).to be == v
|
36
35
|
end
|
37
36
|
|
38
|
-
it 'does not alter the z value, which should always be
|
37
|
+
it 'does not alter the z value, which should always be 1' do
|
39
38
|
tf = Gosling::Transform.new
|
40
39
|
[
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
Snow::Vec3[1, 1, 1],
|
41
|
+
Snow::Vec3[1, 1, 13],
|
42
|
+
Snow::Vec3[1, 1, 7],
|
43
|
+
Snow::Vec3[1, 1, 29373],
|
44
|
+
Snow::Vec3[1, 1, -1],
|
45
|
+
Snow::Vec3[1, 1, 0],
|
46
|
+
Snow::Vec3[1, 1, -328.7],
|
48
47
|
].each do |v|
|
49
|
-
tf.
|
50
|
-
expect(tf.center[2]).to be ==
|
48
|
+
tf.center = v
|
49
|
+
expect(tf.center[2]).to be == 1
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -55,16 +54,14 @@ describe Gosling::Transform do
|
|
55
54
|
describe '#set_scale' do
|
56
55
|
it 'accepts a size 2 vector' do
|
57
56
|
tf = Gosling::Transform.new
|
58
|
-
expect { tf.
|
59
|
-
expect { tf.
|
60
|
-
expect { tf.set_scale(Vector[1]) }.to raise_error(ArgumentError)
|
61
|
-
expect { tf.set_scale(:foo) }.to raise_error(ArgumentError)
|
57
|
+
expect { tf.scale = Snow::Vec2[1, 1] }.not_to raise_error
|
58
|
+
expect { tf.scale = :foo }.to raise_error(ArgumentError)
|
62
59
|
end
|
63
60
|
|
64
61
|
it 'sets the scale transform' do
|
65
|
-
v =
|
62
|
+
v = Snow::Vec2[2.to_r, 0.5.to_r]
|
66
63
|
tf = Gosling::Transform.new
|
67
|
-
tf.
|
64
|
+
tf.scale = v
|
68
65
|
expect(tf.scale).to be == v
|
69
66
|
end
|
70
67
|
end
|
@@ -73,7 +70,7 @@ describe Gosling::Transform do
|
|
73
70
|
it 'sets the rotation transform' do
|
74
71
|
r = Math::PI / 2
|
75
72
|
tf = Gosling::Transform.new
|
76
|
-
tf.
|
73
|
+
tf.rotation = r
|
77
74
|
expect(tf.rotation).to be == r
|
78
75
|
end
|
79
76
|
end
|
@@ -81,146 +78,141 @@ describe Gosling::Transform do
|
|
81
78
|
describe '#set_translation' do
|
82
79
|
it 'accepts a size 3 vector' do
|
83
80
|
tf = Gosling::Transform.new
|
84
|
-
expect { tf.
|
85
|
-
expect { tf.
|
86
|
-
expect { tf.set_translation(Vector[0,0]) }.to raise_error(ArgumentError)
|
87
|
-
expect { tf.set_translation(:foo) }.to raise_error(ArgumentError)
|
81
|
+
expect { tf.translation = Snow::Vec3[0, 0, 0] }.not_to raise_error
|
82
|
+
expect { tf.translation = :foo }.to raise_error(ArgumentError)
|
88
83
|
end
|
89
84
|
|
90
85
|
it 'sets the translation transform' do
|
91
|
-
v =
|
86
|
+
v = Snow::Vec3[1024.to_r, 768.to_r, 1.to_r]
|
92
87
|
tf = Gosling::Transform.new
|
93
|
-
tf.
|
88
|
+
tf.translation = v
|
94
89
|
expect(tf.translation).to be == v
|
95
90
|
end
|
96
91
|
|
97
|
-
it 'does not alter the z value, which should always be
|
92
|
+
it 'does not alter the z value, which should always be 1' do
|
98
93
|
tf = Gosling::Transform.new
|
99
94
|
[
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
95
|
+
Snow::Vec3[1, 1, 1],
|
96
|
+
Snow::Vec3[1, 1, 13],
|
97
|
+
Snow::Vec3[1, 1, 7],
|
98
|
+
Snow::Vec3[1, 1, 29373],
|
99
|
+
Snow::Vec3[1, 1, -1],
|
100
|
+
Snow::Vec3[1, 1, 0],
|
101
|
+
Snow::Vec3[1, 1, -328.7],
|
107
102
|
].each do |v|
|
108
|
-
tf.
|
109
|
-
expect(tf.translation[2]).to be ==
|
103
|
+
tf.translation = v
|
104
|
+
expect(tf.translation[2]).to be == 1
|
110
105
|
end
|
111
106
|
end
|
112
107
|
end
|
113
108
|
|
114
109
|
describe '#to_matrix' do
|
115
110
|
it 'returns a matrix' do
|
116
|
-
expect(@read_only_tf.to_matrix).to be_instance_of(
|
111
|
+
expect(@read_only_tf.to_matrix).to be_instance_of(Snow::Mat3)
|
117
112
|
end
|
118
113
|
end
|
119
114
|
|
120
115
|
it 'centers correctly' do
|
121
116
|
tf = Gosling::Transform.new
|
122
|
-
tf.
|
123
|
-
expected_matrix =
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
117
|
+
tf.center = Snow::Vec3[10.to_r, 20.to_r, 0.to_r]
|
118
|
+
expected_matrix = Snow::Mat3[
|
119
|
+
1, 0, -10,
|
120
|
+
0, 1, -20,
|
121
|
+
0, 0, 1
|
122
|
+
]
|
128
123
|
expect(tf.to_matrix).to be == expected_matrix
|
129
124
|
end
|
130
125
|
|
131
126
|
it 'scales correctly' do
|
132
127
|
tf = Gosling::Transform.new
|
133
|
-
tf.
|
134
|
-
expected_matrix =
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
128
|
+
tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
|
129
|
+
expected_matrix = Snow::Mat3[
|
130
|
+
2, 0, 0,
|
131
|
+
0, 0.5, 0,
|
132
|
+
0, 0, 1
|
133
|
+
]
|
139
134
|
expect(tf.to_matrix).to be == expected_matrix
|
140
135
|
end
|
141
136
|
|
142
137
|
it 'rotates correctly' do
|
143
138
|
tf = Gosling::Transform.new
|
144
|
-
tf.
|
145
|
-
expected_matrix =
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
139
|
+
tf.rotation = Math::PI / 2
|
140
|
+
expected_matrix = Snow::Mat3[
|
141
|
+
0, 1, 0,
|
142
|
+
-1, 0, 0,
|
143
|
+
0, 0, 1
|
144
|
+
]
|
150
145
|
expect(tf.to_matrix).to be == expected_matrix
|
151
146
|
end
|
152
147
|
|
153
148
|
it 'translates correctly' do
|
154
149
|
tf = Gosling::Transform.new
|
155
|
-
tf.
|
156
|
-
expected_matrix =
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
150
|
+
tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
|
151
|
+
expected_matrix = Snow::Mat3[
|
152
|
+
1, 0, 1024,
|
153
|
+
0, 1, 768,
|
154
|
+
0, 0, 1
|
155
|
+
]
|
161
156
|
expect(tf.to_matrix).to be == expected_matrix
|
162
157
|
end
|
163
158
|
|
164
159
|
it 'applies all transforms in the correct order' do
|
165
160
|
tf = Gosling::Transform.new
|
166
|
-
tf.
|
167
|
-
tf.
|
168
|
-
tf.
|
169
|
-
tf.
|
170
|
-
|
171
|
-
expected_matrix =
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
161
|
+
tf.center = Snow::Vec3[10.to_r, 20.to_r, 0.to_r]
|
162
|
+
tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
|
163
|
+
tf.rotation = Math::PI / 2
|
164
|
+
tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
|
165
|
+
|
166
|
+
expected_matrix = Snow::Mat3[
|
167
|
+
0.0, 0.5, 1014.0,
|
168
|
+
-2.0, 0.0, 788.0,
|
169
|
+
0.0, 0.0, 1.0
|
170
|
+
]
|
176
171
|
expect(tf.to_matrix).to be == expected_matrix
|
177
172
|
|
178
|
-
v =
|
179
|
-
v_transformed =
|
173
|
+
v = Snow::Vec3[0.to_r, -50.to_r, 1.to_r]
|
174
|
+
v_transformed = Snow::Vec3[989.to_r, 788.to_r, 1.to_r]
|
180
175
|
expect(tf.to_matrix * v).to be == v_transformed
|
181
176
|
|
182
|
-
v =
|
183
|
-
v_transformed =
|
177
|
+
v = Snow::Vec3[100.to_r, -50.to_r, 1.to_r]
|
178
|
+
v_transformed = Snow::Vec3[989.to_r, 588.to_r, 1.to_r]
|
184
179
|
expect(tf.to_matrix * v).to be == v_transformed
|
185
180
|
|
186
|
-
v =
|
187
|
-
v_transformed =
|
181
|
+
v = Snow::Vec3[100.to_r, 50.to_r, 1.to_r]
|
182
|
+
v_transformed = Snow::Vec3[1039.to_r, 588.to_r, 1.to_r]
|
188
183
|
expect(tf.to_matrix * v).to be == v_transformed
|
189
184
|
|
190
|
-
v =
|
191
|
-
v_transformed =
|
185
|
+
v = Snow::Vec3[0.to_r, 50.to_r, 1.to_r]
|
186
|
+
v_transformed = Snow::Vec3[1039.to_r, 788.to_r, 1.to_r]
|
192
187
|
expect(tf.to_matrix * v).to be == v_transformed
|
193
188
|
end
|
194
189
|
|
195
190
|
describe '#transform_point' do
|
196
191
|
it 'expects a length 3 vector' do
|
197
|
-
expect { @read_only_tf.transform_point(
|
198
|
-
expect { @read_only_tf.transform_point(Vector[1, 0, 1, 1]) }.to raise_error(ArgumentError)
|
199
|
-
expect { @read_only_tf.transform_point(Vector[1, 0]) }.to raise_error(ArgumentError)
|
192
|
+
expect { @read_only_tf.transform_point(Snow::Vec3[1, 0, 1]) }.not_to raise_error
|
200
193
|
expect { @read_only_tf.transform_point(:foo) }.to raise_error(ArgumentError)
|
201
194
|
expect { @read_only_tf.transform_point(nil) }.to raise_error(ArgumentError)
|
202
195
|
end
|
203
196
|
|
204
197
|
it 'returns a length 3 vector' do
|
205
|
-
result = @read_only_tf.transform_point(
|
206
|
-
expect(result).to be_instance_of(
|
207
|
-
expect(result.size).to be == 3
|
198
|
+
result = @read_only_tf.transform_point(Snow::Vec3[1, 0, 1])
|
199
|
+
expect(result).to be_instance_of(Snow::Vec3)
|
208
200
|
end
|
209
201
|
|
210
202
|
it 'always returns a z value of 0' do
|
211
203
|
[
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
204
|
+
Snow::Vec3[1, 1, 1],
|
205
|
+
Snow::Vec3[-1, -1, -1],
|
206
|
+
Snow::Vec3[-22, -22, 0],
|
207
|
+
Snow::Vec3[-11, 13, 34],
|
208
|
+
Snow::Vec3[37, -4, -15],
|
209
|
+
Snow::Vec3[34, 39, -16],
|
210
|
+
Snow::Vec3[-48, 23, -32],
|
211
|
+
Snow::Vec3[24, -39, 42],
|
212
|
+
Snow::Vec3[49, 44, -15],
|
213
|
+
Snow::Vec3[27, 23, 42],
|
214
|
+
Snow::Vec3[33, -25, -20],
|
215
|
+
Snow::Vec3[-46, -18, 48],
|
224
216
|
].each do |v|
|
225
217
|
expect(@read_only_tf.transform_point(v)[2]).to be == 0
|
226
218
|
end
|
@@ -228,10 +220,10 @@ describe Gosling::Transform do
|
|
228
220
|
|
229
221
|
it 'transforms the point correctly' do
|
230
222
|
tf = Gosling::Transform.new
|
231
|
-
tf.
|
232
|
-
tf.
|
233
|
-
tf.
|
234
|
-
tf.
|
223
|
+
tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
|
224
|
+
tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
|
225
|
+
tf.rotation = Math::PI / 2
|
226
|
+
tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
|
235
227
|
|
236
228
|
[
|
237
229
|
[0, 0],
|
@@ -241,40 +233,37 @@ describe Gosling::Transform do
|
|
241
233
|
[5, 20]
|
242
234
|
].each do |pt|
|
243
235
|
x, y = pt
|
244
|
-
expect(tf.transform_point(
|
236
|
+
expect(tf.transform_point(Snow::Vec3[x, y, 0])).to be == Snow::Vec3[(y - 20) * 0.5 + 1024, (x - 5) * -2 + 768, 0]
|
245
237
|
end
|
246
238
|
end
|
247
239
|
end
|
248
240
|
|
249
241
|
describe '#untransform_point' do
|
250
242
|
it 'expects a length 3 vector' do
|
251
|
-
expect { @read_only_tf.untransform_point(
|
252
|
-
expect { @read_only_tf.untransform_point(Vector[1, 0, 1, 1]) }.to raise_error(ArgumentError)
|
253
|
-
expect { @read_only_tf.untransform_point(Vector[1, 0]) }.to raise_error(ArgumentError)
|
243
|
+
expect { @read_only_tf.untransform_point(Snow::Vec3[1, 0, 1]) }.not_to raise_error
|
254
244
|
expect { @read_only_tf.untransform_point(:foo) }.to raise_error(ArgumentError)
|
255
245
|
expect { @read_only_tf.untransform_point(nil) }.to raise_error(ArgumentError)
|
256
246
|
end
|
257
247
|
|
258
248
|
it 'returns a length 3 vector' do
|
259
|
-
result = @read_only_tf.untransform_point(
|
260
|
-
expect(result).to be_instance_of(
|
261
|
-
expect(result.size).to be == 3
|
249
|
+
result = @read_only_tf.untransform_point(Snow::Vec3[1, 0, 1])
|
250
|
+
expect(result).to be_instance_of(Snow::Vec3)
|
262
251
|
end
|
263
252
|
|
264
253
|
it 'always returns a z value of 0' do
|
265
254
|
[
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
255
|
+
Snow::Vec3[1, 1, 1],
|
256
|
+
Snow::Vec3[-1, -1, -1],
|
257
|
+
Snow::Vec3[-22, -22, 0],
|
258
|
+
Snow::Vec3[-11, 13, 34],
|
259
|
+
Snow::Vec3[37, -4, -15],
|
260
|
+
Snow::Vec3[34, 39, -16],
|
261
|
+
Snow::Vec3[-48, 23, -32],
|
262
|
+
Snow::Vec3[24, -39, 42],
|
263
|
+
Snow::Vec3[49, 44, -15],
|
264
|
+
Snow::Vec3[27, 23, 42],
|
265
|
+
Snow::Vec3[33, -25, -20],
|
266
|
+
Snow::Vec3[-46, -18, 48],
|
278
267
|
].each do |v|
|
279
268
|
expect(@read_only_tf.untransform_point(v)[2]).to be == 0
|
280
269
|
end
|
@@ -282,10 +271,10 @@ describe Gosling::Transform do
|
|
282
271
|
|
283
272
|
it 'untransforms the point correctly' do
|
284
273
|
tf = Gosling::Transform.new
|
285
|
-
tf.
|
286
|
-
tf.
|
287
|
-
tf.
|
288
|
-
tf.
|
274
|
+
tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
|
275
|
+
tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
|
276
|
+
tf.rotation = Math::PI / 2
|
277
|
+
tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
|
289
278
|
|
290
279
|
[
|
291
280
|
[1014, 778],
|
@@ -295,30 +284,30 @@ describe Gosling::Transform do
|
|
295
284
|
[768, 1024]
|
296
285
|
].each do |pt|
|
297
286
|
x, y = pt
|
298
|
-
expect(tf.untransform_point(
|
287
|
+
expect(tf.untransform_point(Snow::Vec3[x, y, 0])).to be == Snow::Vec3[(y - 768) * -0.5 + 5, (x - 1024) * 2 + 20, 0]
|
299
288
|
end
|
300
289
|
end
|
301
290
|
|
302
291
|
it 'undoes the results of transform_point' do
|
303
292
|
tf = Gosling::Transform.new
|
304
|
-
tf.
|
305
|
-
tf.
|
306
|
-
tf.
|
307
|
-
tf.
|
293
|
+
tf.center = Snow::Vec3[5.to_r, 20.to_r, 0.to_r]
|
294
|
+
tf.scale = Snow::Vec2[2.to_r, 0.5.to_r]
|
295
|
+
tf.rotation = Math::PI / 2
|
296
|
+
tf.translation = Snow::Vec3[1024.to_r, 768.to_r, 0.to_r]
|
308
297
|
|
309
298
|
[
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
299
|
+
Snow::Vec3[1, 1, 0],
|
300
|
+
Snow::Vec3[-1, -1, 0],
|
301
|
+
Snow::Vec3[-22, -22, 0],
|
302
|
+
Snow::Vec3[-11, 13, 0],
|
303
|
+
Snow::Vec3[37, -4, 0],
|
304
|
+
Snow::Vec3[34, 39, 0],
|
305
|
+
Snow::Vec3[-48, 23, 0],
|
306
|
+
Snow::Vec3[24, -39, 0],
|
307
|
+
Snow::Vec3[49, 44, 0],
|
308
|
+
Snow::Vec3[27, 23, 0],
|
309
|
+
Snow::Vec3[33, -25, 0],
|
310
|
+
Snow::Vec3[-46, -18, 0],
|
322
311
|
].each do |v|
|
323
312
|
expect(tf.untransform_point(tf.transform_point(v))).to be == v
|
324
313
|
expect(tf.transform_point(tf.untransform_point(v))).to be == v
|