pgtools 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +25 -25
- data/bin/bxm_decoder +2 -2
- data/bin/bxm_encoder +2 -2
- data/bin/clh_convert +2 -2
- data/bin/clp_convert +2 -2
- data/bin/clw_convert +2 -2
- data/bin/dat_creator +2 -2
- data/bin/dat_extractor +2 -2
- data/bin/dat_ls +2 -2
- data/bin/eff_idd_creator +2 -2
- data/bin/eff_idd_extractor +2 -2
- data/bin/exp_convert_wiiu_pc +2 -2
- data/bin/exp_tool +2 -2
- data/bin/mot_convert_wiiu_pc +2 -2
- data/bin/mot_tool +2 -2
- data/bin/pkz_extractor +2 -2
- data/bin/scr_creator +2 -2
- data/bin/scr_extractor +2 -2
- data/bin/wmb_cleanup +2 -2
- data/bin/wmb_common_bones +2 -2
- data/bin/wmb_convert_pc_switch +2 -2
- data/bin/wmb_convert_wiiu_pc +2 -2
- data/bin/wmb_export_assimp +2 -2
- data/bin/wmb_get_bone_map +2 -2
- data/bin/wmb_import_assimp +2 -2
- data/bin/wmb_import_nier +2 -2
- data/bin/wmb_import_wiiu +2 -2
- data/bin/wtb_convert_wiiu_pc +2 -2
- data/bin/wtx_creator +2 -2
- data/bin/wtx_extractor +2 -2
- data/lib/bayonetta/alignment.rb +0 -0
- data/lib/bayonetta/bone.rb +0 -0
- data/lib/bayonetta/bxm.rb +180 -180
- data/lib/bayonetta/clh.rb +159 -159
- data/lib/bayonetta/clp.rb +212 -212
- data/lib/bayonetta/clw.rb +166 -166
- data/lib/bayonetta/dat.rb +261 -261
- data/lib/bayonetta/eff.rb +314 -314
- data/lib/bayonetta/endianness.rb +0 -0
- data/lib/bayonetta/exp.rb +768 -768
- data/lib/bayonetta/linalg.rb +416 -416
- data/lib/bayonetta/material_database.yaml +2581 -2581
- data/lib/bayonetta/mot.rb +763 -763
- data/lib/bayonetta/pkz.rb +63 -63
- data/lib/bayonetta/scr.rb +0 -0
- data/lib/bayonetta/tools/bxm_decoder.rb +23 -23
- data/lib/bayonetta/tools/bxm_encoder.rb +37 -37
- data/lib/bayonetta/tools/clh_convert.rb +60 -60
- data/lib/bayonetta/tools/clp_convert.rb +70 -70
- data/lib/bayonetta/tools/clw_convert.rb +60 -60
- data/lib/bayonetta/tools/dat_creator.rb +57 -57
- data/lib/bayonetta/tools/dat_extractor.rb +94 -94
- data/lib/bayonetta/tools/dat_ls.rb +106 -106
- data/lib/bayonetta/tools/eff_idd_creator.rb +66 -66
- data/lib/bayonetta/tools/eff_idd_extractor.rb +73 -73
- data/lib/bayonetta/tools/exp_convert_wiiu_pc.rb +33 -33
- data/lib/bayonetta/tools/exp_tool.rb +48 -48
- data/lib/bayonetta/tools/mot_convert_wiiu_pc.rb +33 -33
- data/lib/bayonetta/tools/mot_tool.rb +0 -0
- data/lib/bayonetta/tools/pkz_extractor.rb +75 -75
- data/lib/bayonetta/tools/scr_creator.rb +63 -63
- data/lib/bayonetta/tools/scr_extractor.rb +78 -78
- data/lib/bayonetta/tools/wmb_cleanup.rb +250 -250
- data/lib/bayonetta/tools/wmb_common_bones.rb +45 -45
- data/lib/bayonetta/tools/wmb_convert_pc_switch.rb +35 -35
- data/lib/bayonetta/tools/wmb_convert_wiiu_pc.rb +33 -33
- data/lib/bayonetta/tools/wmb_export_assimp.rb +479 -479
- data/lib/bayonetta/tools/wmb_get_bone_map.rb +50 -50
- data/lib/bayonetta/tools/wmb_import_assimp.rb +735 -735
- data/lib/bayonetta/tools/wmb_import_geometry_wiiu_pc.rb +472 -472
- data/lib/bayonetta/tools/wmb_import_nier.rb +309 -309
- data/lib/bayonetta/tools/wtb_convert_wiiu_pc.rb +95 -95
- data/lib/bayonetta/tools/wtb_import_textures.rb +103 -103
- data/lib/bayonetta/tools/wtx_creator.rb +69 -69
- data/lib/bayonetta/tools/wtx_extractor.rb +85 -85
- data/lib/bayonetta/vertex_types.yaml +0 -0
- data/lib/bayonetta/vertex_types2.yaml +0 -0
- data/lib/bayonetta/vertex_types_nier.yaml +145 -145
- data/lib/bayonetta/wmb.rb +2455 -2443
- data/lib/bayonetta/wmb3.rb +759 -759
- data/lib/bayonetta/wtb.rb +481 -481
- data/lib/bayonetta.rb +60 -60
- metadata +2 -2
data/lib/bayonetta/linalg.rb
CHANGED
@@ -1,416 +1,416 @@
|
|
1
|
-
module Bayonetta
|
2
|
-
|
3
|
-
module Linalg
|
4
|
-
|
5
|
-
class Matrix
|
6
|
-
attr_reader :data
|
7
|
-
def initialize
|
8
|
-
@data = [[1.0, 0.0, 0.0, 0.0],
|
9
|
-
[0.0, 1.0, 0.0, 0.0],
|
10
|
-
[0.0, 0.0, 1.0, 0.0],
|
11
|
-
[0.0, 0.0, 0.0, 1.0]]
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](i)
|
15
|
-
@data[i]
|
16
|
-
end
|
17
|
-
|
18
|
-
def transpose
|
19
|
-
m = Matrix::new
|
20
|
-
4.times { |i|
|
21
|
-
4.times { |j|
|
22
|
-
m.data[i][j] = data[j][i]
|
23
|
-
}
|
24
|
-
}
|
25
|
-
m
|
26
|
-
end
|
27
|
-
|
28
|
-
def inverse
|
29
|
-
m = Matrix::new
|
30
|
-
s0 = data[0][0] * data[1][1] - data[1][0] * data[0][1]
|
31
|
-
s1 = data[0][0] * data[1][2] - data[1][0] * data[0][2]
|
32
|
-
s2 = data[0][0] * data[1][3] - data[1][0] * data[0][3]
|
33
|
-
s3 = data[0][1] * data[1][2] - data[1][1] * data[0][2]
|
34
|
-
s4 = data[0][1] * data[1][3] - data[1][1] * data[0][3]
|
35
|
-
s5 = data[0][2] * data[1][3] - data[1][2] * data[0][3]
|
36
|
-
|
37
|
-
c5 = data[2][2] * data[3][3] - data[3][2] * data[2][3]
|
38
|
-
c4 = data[2][1] * data[3][3] - data[3][1] * data[2][3]
|
39
|
-
c3 = data[2][1] * data[3][2] - data[3][1] * data[2][2]
|
40
|
-
c2 = data[2][0] * data[3][3] - data[3][0] * data[2][3]
|
41
|
-
c1 = data[2][0] * data[3][2] - data[3][0] * data[2][2]
|
42
|
-
c0 = data[2][0] * data[3][1] - data[3][0] * data[2][1]
|
43
|
-
|
44
|
-
invdet = 1.0 / (s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0)
|
45
|
-
m.data[0][0] = ( data[1][1] * c5 - data[1][2] * c4 + data[1][3] * c3) * invdet
|
46
|
-
m.data[0][1] = (-data[0][1] * c5 + data[0][2] * c4 - data[0][3] * c3) * invdet
|
47
|
-
m.data[0][2] = ( data[3][1] * s5 - data[3][2] * s4 + data[3][3] * s3) * invdet
|
48
|
-
m.data[0][3] = (-data[2][1] * s5 + data[2][2] * s4 - data[2][3] * s3) * invdet
|
49
|
-
|
50
|
-
m.data[1][0] = (-data[1][0] * c5 + data[1][2] * c2 - data[1][3] * c1) * invdet
|
51
|
-
m.data[1][1] = ( data[0][0] * c5 - data[0][2] * c2 + data[0][3] * c1) * invdet
|
52
|
-
m.data[1][2] = (-data[3][0] * s5 + data[3][2] * s2 - data[3][3] * s1) * invdet
|
53
|
-
m.data[1][3] = ( data[2][0] * s5 - data[2][2] * s2 + data[2][3] * s1) * invdet
|
54
|
-
|
55
|
-
m.data[2][0] = ( data[1][0] * c4 - data[1][1] * c2 + data[1][3] * c0) * invdet
|
56
|
-
m.data[2][1] = (-data[0][0] * c4 + data[0][1] * c2 - data[0][3] * c0) * invdet
|
57
|
-
m.data[2][2] = ( data[3][0] * s4 - data[3][1] * s2 + data[3][3] * s0) * invdet
|
58
|
-
m.data[2][3] = (-data[2][0] * s4 + data[2][1] * s2 - data[2][3] * s0) * invdet
|
59
|
-
|
60
|
-
m.data[3][0] = (-data[1][0] * c3 + data[1][1] * c1 - data[1][2] * c0) * invdet
|
61
|
-
m.data[3][1] = ( data[0][0] * c3 - data[0][1] * c1 + data[0][2] * c0) * invdet
|
62
|
-
m.data[3][2] = (-data[3][0] * s3 + data[3][1] * s1 - data[3][2] * s0) * invdet
|
63
|
-
m.data[3][3] = ( data[2][0] * s3 - data[2][1] * s1 + data[2][2] * s0) * invdet
|
64
|
-
m
|
65
|
-
end
|
66
|
-
|
67
|
-
def +(other)
|
68
|
-
if other.kind_of?(Matrix)
|
69
|
-
m = Matrix::new
|
70
|
-
4.times { |i|
|
71
|
-
4.times { |j|
|
72
|
-
m.data[i][j] = data[i][j] + other.data[i][j]
|
73
|
-
}
|
74
|
-
}
|
75
|
-
return m
|
76
|
-
else
|
77
|
-
raise "Invalid argument for matrix add: #{other.inspect}!"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def *(other)
|
82
|
-
if other.kind_of?(Matrix)
|
83
|
-
m = Matrix::new
|
84
|
-
4.times { |i|
|
85
|
-
4.times { |j|
|
86
|
-
m.data[i][j] = 0.0
|
87
|
-
4.times { |k|
|
88
|
-
m.data[i][j] += data[i][k] * other.data[k][j]
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return m
|
93
|
-
elsif other.kind_of?(Vector) || (other.kind_of?(Array) && other.length == 4)
|
94
|
-
return Vector::new(
|
95
|
-
@data[0][0] * other[0] + @data[0][1] * other[1] + @data[0][2] * other[2] + @data[0][3] * other[3],
|
96
|
-
@data[1][0] * other[0] + @data[1][1] * other[1] + @data[1][2] * other[2] + @data[1][3] * other[3],
|
97
|
-
@data[2][0] * other[0] + @data[2][1] * other[1] + @data[2][2] * other[2] + @data[2][3] * other[3],
|
98
|
-
@data[3][0] * other[0] + @data[3][1] * other[1] + @data[3][2] * other[2] + @data[3][3] * other[3]
|
99
|
-
)
|
100
|
-
elsif other.kind_of?(Numeric)
|
101
|
-
m = Matrix::new
|
102
|
-
4.times { |i|
|
103
|
-
4.times { |j|
|
104
|
-
m.data[i][j] = data[i][j] * other
|
105
|
-
}
|
106
|
-
}
|
107
|
-
return m
|
108
|
-
else
|
109
|
-
raise "Invalid argument for matrix miltiply: #{other.inspect}!"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end #Matrix
|
113
|
-
|
114
|
-
class Vector
|
115
|
-
|
116
|
-
def initialize(x=0.0, y=0.0, z=0.0, w=1.0)
|
117
|
-
@data = [x, y, z, w]
|
118
|
-
end
|
119
|
-
|
120
|
-
def [](i)
|
121
|
-
return @data[i]
|
122
|
-
end
|
123
|
-
|
124
|
-
def []=(i,v)
|
125
|
-
return @data[i]=v
|
126
|
-
end
|
127
|
-
|
128
|
-
def dup
|
129
|
-
self.class::new(x,y,z,w)
|
130
|
-
end
|
131
|
-
|
132
|
-
def x
|
133
|
-
@data[0]
|
134
|
-
end
|
135
|
-
|
136
|
-
def x=(v)
|
137
|
-
@data[0] = v
|
138
|
-
end
|
139
|
-
|
140
|
-
def y
|
141
|
-
@data[1]
|
142
|
-
end
|
143
|
-
|
144
|
-
def y=(v)
|
145
|
-
@data[1] = v
|
146
|
-
end
|
147
|
-
|
148
|
-
def z
|
149
|
-
@data[2]
|
150
|
-
end
|
151
|
-
|
152
|
-
def z=(v)
|
153
|
-
@data[2]=v
|
154
|
-
end
|
155
|
-
|
156
|
-
def w
|
157
|
-
@data[3]
|
158
|
-
end
|
159
|
-
|
160
|
-
def w=(v)
|
161
|
-
@data[3] = v
|
162
|
-
end
|
163
|
-
|
164
|
-
def -(other)
|
165
|
-
Vector::new(x-other.x, y-other.y, z-other.z, w)
|
166
|
-
end
|
167
|
-
|
168
|
-
def +(other)
|
169
|
-
Vector::new(x+other.x, y+other.y, z+other.z, w)
|
170
|
-
end
|
171
|
-
|
172
|
-
def *(scalar)
|
173
|
-
Vector::new(x*scalar, y*scalar, z*scalar, w)
|
174
|
-
end
|
175
|
-
|
176
|
-
def dot(other)
|
177
|
-
x*other.x + y*other.y + z*other.z
|
178
|
-
end
|
179
|
-
|
180
|
-
def -@
|
181
|
-
self.class::new(-x, -y, -z, w)
|
182
|
-
end
|
183
|
-
|
184
|
-
def length
|
185
|
-
Math.sqrt(x*x + y*y + z*z)
|
186
|
-
end
|
187
|
-
|
188
|
-
def normalize!
|
189
|
-
l = length
|
190
|
-
if l != 0.0 && ! l.nan?
|
191
|
-
@data[0] /= l
|
192
|
-
@data[1] /= l
|
193
|
-
@data[2] /= l
|
194
|
-
else
|
195
|
-
@data[0] = 0.0
|
196
|
-
@data[1] = 0.0
|
197
|
-
@data[2] = 0.0
|
198
|
-
end
|
199
|
-
self
|
200
|
-
end
|
201
|
-
|
202
|
-
def normalize
|
203
|
-
self.dup.normalize!
|
204
|
-
end
|
205
|
-
|
206
|
-
end #Vector
|
207
|
-
|
208
|
-
def self.get_translation_vector(*args)
|
209
|
-
if args.length == 1
|
210
|
-
v = args.first.dup
|
211
|
-
elsif args.length == 3
|
212
|
-
v = Vector::new(*args)
|
213
|
-
else
|
214
|
-
raise "Invalid translation arguments: #{args.inspect}!"
|
215
|
-
end
|
216
|
-
v
|
217
|
-
end
|
218
|
-
|
219
|
-
def self.get_translation_matrix(*args)
|
220
|
-
m = get_unit_matrix
|
221
|
-
v = get_translation_vector(*args)
|
222
|
-
m.data[0][3] = v[0]
|
223
|
-
m.data[1][3] = v[1]
|
224
|
-
m.data[2][3] = v[2]
|
225
|
-
m
|
226
|
-
end
|
227
|
-
|
228
|
-
def self.get_inverse_translation_matrix(*args)
|
229
|
-
m = get_unit_matrix
|
230
|
-
v = get_translation_vector(*args)
|
231
|
-
m.data[0][3] = -v[0]
|
232
|
-
m.data[1][3] = -v[1]
|
233
|
-
m.data[2][3] = -v[2]
|
234
|
-
m
|
235
|
-
end
|
236
|
-
|
237
|
-
def self.get_scaling_vector(*args)
|
238
|
-
if args.length == 1
|
239
|
-
v = args.first.dup
|
240
|
-
elsif args.length == 3
|
241
|
-
v = Vector::new(*args)
|
242
|
-
else
|
243
|
-
raise "Invalid translation arguments: #{args.inspect}!"
|
244
|
-
end
|
245
|
-
v
|
246
|
-
end
|
247
|
-
|
248
|
-
def self.get_scaling_matrix(*args)
|
249
|
-
m = get_unit_matrix
|
250
|
-
v = get_scaling_vector(*args)
|
251
|
-
m.data[0][0] = v[0]
|
252
|
-
m.data[1][1] = v[1]
|
253
|
-
m.data[2][2] = v[2]
|
254
|
-
m
|
255
|
-
end
|
256
|
-
|
257
|
-
def self.get_inverse_scaling_matrix(*args)
|
258
|
-
m = get_unit_matrix
|
259
|
-
v = get_scaling_vector(*args)
|
260
|
-
m.data[0][0] = 1.0/v[0]
|
261
|
-
m.data[1][1] = 1.0/v[1]
|
262
|
-
m.data[2][2] = 1.0/v[2]
|
263
|
-
m
|
264
|
-
end
|
265
|
-
|
266
|
-
def self.get_rotation_vector(*args)
|
267
|
-
if args.length == 1
|
268
|
-
v = args.first.dup
|
269
|
-
elsif args.length == 3
|
270
|
-
v = Vector::new(*args)
|
271
|
-
else
|
272
|
-
raise "Invalid translation arguments: #{args.inspect}!"
|
273
|
-
end
|
274
|
-
v
|
275
|
-
end
|
276
|
-
|
277
|
-
def self.get_rotation_matrix(*args, center: nil, order: nil)
|
278
|
-
v = get_rotation_vector(*args)
|
279
|
-
if center
|
280
|
-
vt = get_translation_vector(*[center].flatten)
|
281
|
-
mt1 = get_translation_matrix(-vt)
|
282
|
-
mt2 = get_translation_matrix(vt)
|
283
|
-
else
|
284
|
-
mt1 = get_unit_matrix
|
285
|
-
mt2 = get_unit_matrix
|
286
|
-
end
|
287
|
-
m = mt2
|
288
|
-
if order
|
289
|
-
case order
|
290
|
-
when 0
|
291
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
292
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
293
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
294
|
-
when 1
|
295
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
296
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
297
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
298
|
-
when 2
|
299
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
300
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
301
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
302
|
-
when 3
|
303
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
304
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
305
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
306
|
-
when 4
|
307
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
308
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
309
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
310
|
-
else
|
311
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
312
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
313
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
314
|
-
end
|
315
|
-
else
|
316
|
-
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
317
|
-
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
318
|
-
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
319
|
-
end
|
320
|
-
m = m * mt1
|
321
|
-
m
|
322
|
-
end
|
323
|
-
|
324
|
-
def self.get_inverse_rotation_matrix(*args, center: nil, order: nil)
|
325
|
-
v = get_rotation_vector(*args)
|
326
|
-
if center
|
327
|
-
vt = get_translation_vector(*[center].flatten)
|
328
|
-
mt1 = get_translation_matrix(-vt)
|
329
|
-
mt2 = get_translation_matrix(vt)
|
330
|
-
else
|
331
|
-
mt1 = get_unit_matrix
|
332
|
-
mt2 = get_unit_matrix
|
333
|
-
end
|
334
|
-
m = mt2
|
335
|
-
if order
|
336
|
-
case order
|
337
|
-
when 0
|
338
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
339
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
340
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
341
|
-
when 1
|
342
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
343
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
344
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
345
|
-
when 2
|
346
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
347
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
348
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
349
|
-
when 3
|
350
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
351
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
352
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
353
|
-
when 4
|
354
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
355
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
356
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
357
|
-
else
|
358
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
359
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
360
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
361
|
-
end
|
362
|
-
else
|
363
|
-
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
364
|
-
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
365
|
-
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
366
|
-
end
|
367
|
-
m = m * mt1
|
368
|
-
m
|
369
|
-
end
|
370
|
-
|
371
|
-
def self.get_unit_matrix
|
372
|
-
Matrix::new
|
373
|
-
end
|
374
|
-
|
375
|
-
def self.get_zero_matrix
|
376
|
-
Matrix::new * 0.0
|
377
|
-
end
|
378
|
-
|
379
|
-
def self.get_transformation_matrix(translate, rotate, scale, parent_scale, order: nil)
|
380
|
-
get_translation_matrix(translate) *
|
381
|
-
get_inverse_scaling_matrix(parent_scale) *
|
382
|
-
get_rotation_matrix(rotate, order: order) *
|
383
|
-
get_scaling_matrix(scale)
|
384
|
-
end
|
385
|
-
|
386
|
-
def self.get_inverse_transformation_matrix(translate, rotate, scale, parent_scale, order: nil)
|
387
|
-
get_inverse_scaling_matrix(scale) *
|
388
|
-
get_inverse_rotation_matrix(rotate, order: order) *
|
389
|
-
get_scaling_matrix(parent_scale) *
|
390
|
-
get_inverse_translation_matrix(translate)
|
391
|
-
end
|
392
|
-
|
393
|
-
private
|
394
|
-
|
395
|
-
# https://en.wikipedia.org/wiki/Rotation_matrix#Axis_and_angle
|
396
|
-
def self.rotation_matrix(angle, vector)
|
397
|
-
v = vector.normalize
|
398
|
-
x = v[0]
|
399
|
-
y = v[1]
|
400
|
-
z = v[2]
|
401
|
-
c = Math::cos(angle)
|
402
|
-
d = 1 - c
|
403
|
-
s = Math::sin(angle)
|
404
|
-
|
405
|
-
m = Matrix::new
|
406
|
-
|
407
|
-
m.data.replace( [ [ x*x*d + c, x*y*d - z*s, x*z*d + y*s, 0.0],
|
408
|
-
[ y*x*d + z*s, y*y*d + c, y*z*d - x*s, 0.0],
|
409
|
-
[ z*x*d - y*s, z*y*d + x*s, z*z*d + c, 0.0],
|
410
|
-
[ 0.0, 0.0, 0.0, 1.0] ] )
|
411
|
-
m
|
412
|
-
end
|
413
|
-
|
414
|
-
end #Linalg
|
415
|
-
|
416
|
-
end #Bayonetta
|
1
|
+
module Bayonetta
|
2
|
+
|
3
|
+
module Linalg
|
4
|
+
|
5
|
+
class Matrix
|
6
|
+
attr_reader :data
|
7
|
+
def initialize
|
8
|
+
@data = [[1.0, 0.0, 0.0, 0.0],
|
9
|
+
[0.0, 1.0, 0.0, 0.0],
|
10
|
+
[0.0, 0.0, 1.0, 0.0],
|
11
|
+
[0.0, 0.0, 0.0, 1.0]]
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](i)
|
15
|
+
@data[i]
|
16
|
+
end
|
17
|
+
|
18
|
+
def transpose
|
19
|
+
m = Matrix::new
|
20
|
+
4.times { |i|
|
21
|
+
4.times { |j|
|
22
|
+
m.data[i][j] = data[j][i]
|
23
|
+
}
|
24
|
+
}
|
25
|
+
m
|
26
|
+
end
|
27
|
+
|
28
|
+
def inverse
|
29
|
+
m = Matrix::new
|
30
|
+
s0 = data[0][0] * data[1][1] - data[1][0] * data[0][1]
|
31
|
+
s1 = data[0][0] * data[1][2] - data[1][0] * data[0][2]
|
32
|
+
s2 = data[0][0] * data[1][3] - data[1][0] * data[0][3]
|
33
|
+
s3 = data[0][1] * data[1][2] - data[1][1] * data[0][2]
|
34
|
+
s4 = data[0][1] * data[1][3] - data[1][1] * data[0][3]
|
35
|
+
s5 = data[0][2] * data[1][3] - data[1][2] * data[0][3]
|
36
|
+
|
37
|
+
c5 = data[2][2] * data[3][3] - data[3][2] * data[2][3]
|
38
|
+
c4 = data[2][1] * data[3][3] - data[3][1] * data[2][3]
|
39
|
+
c3 = data[2][1] * data[3][2] - data[3][1] * data[2][2]
|
40
|
+
c2 = data[2][0] * data[3][3] - data[3][0] * data[2][3]
|
41
|
+
c1 = data[2][0] * data[3][2] - data[3][0] * data[2][2]
|
42
|
+
c0 = data[2][0] * data[3][1] - data[3][0] * data[2][1]
|
43
|
+
|
44
|
+
invdet = 1.0 / (s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0)
|
45
|
+
m.data[0][0] = ( data[1][1] * c5 - data[1][2] * c4 + data[1][3] * c3) * invdet
|
46
|
+
m.data[0][1] = (-data[0][1] * c5 + data[0][2] * c4 - data[0][3] * c3) * invdet
|
47
|
+
m.data[0][2] = ( data[3][1] * s5 - data[3][2] * s4 + data[3][3] * s3) * invdet
|
48
|
+
m.data[0][3] = (-data[2][1] * s5 + data[2][2] * s4 - data[2][3] * s3) * invdet
|
49
|
+
|
50
|
+
m.data[1][0] = (-data[1][0] * c5 + data[1][2] * c2 - data[1][3] * c1) * invdet
|
51
|
+
m.data[1][1] = ( data[0][0] * c5 - data[0][2] * c2 + data[0][3] * c1) * invdet
|
52
|
+
m.data[1][2] = (-data[3][0] * s5 + data[3][2] * s2 - data[3][3] * s1) * invdet
|
53
|
+
m.data[1][3] = ( data[2][0] * s5 - data[2][2] * s2 + data[2][3] * s1) * invdet
|
54
|
+
|
55
|
+
m.data[2][0] = ( data[1][0] * c4 - data[1][1] * c2 + data[1][3] * c0) * invdet
|
56
|
+
m.data[2][1] = (-data[0][0] * c4 + data[0][1] * c2 - data[0][3] * c0) * invdet
|
57
|
+
m.data[2][2] = ( data[3][0] * s4 - data[3][1] * s2 + data[3][3] * s0) * invdet
|
58
|
+
m.data[2][3] = (-data[2][0] * s4 + data[2][1] * s2 - data[2][3] * s0) * invdet
|
59
|
+
|
60
|
+
m.data[3][0] = (-data[1][0] * c3 + data[1][1] * c1 - data[1][2] * c0) * invdet
|
61
|
+
m.data[3][1] = ( data[0][0] * c3 - data[0][1] * c1 + data[0][2] * c0) * invdet
|
62
|
+
m.data[3][2] = (-data[3][0] * s3 + data[3][1] * s1 - data[3][2] * s0) * invdet
|
63
|
+
m.data[3][3] = ( data[2][0] * s3 - data[2][1] * s1 + data[2][2] * s0) * invdet
|
64
|
+
m
|
65
|
+
end
|
66
|
+
|
67
|
+
def +(other)
|
68
|
+
if other.kind_of?(Matrix)
|
69
|
+
m = Matrix::new
|
70
|
+
4.times { |i|
|
71
|
+
4.times { |j|
|
72
|
+
m.data[i][j] = data[i][j] + other.data[i][j]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return m
|
76
|
+
else
|
77
|
+
raise "Invalid argument for matrix add: #{other.inspect}!"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def *(other)
|
82
|
+
if other.kind_of?(Matrix)
|
83
|
+
m = Matrix::new
|
84
|
+
4.times { |i|
|
85
|
+
4.times { |j|
|
86
|
+
m.data[i][j] = 0.0
|
87
|
+
4.times { |k|
|
88
|
+
m.data[i][j] += data[i][k] * other.data[k][j]
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return m
|
93
|
+
elsif other.kind_of?(Vector) || (other.kind_of?(Array) && other.length == 4)
|
94
|
+
return Vector::new(
|
95
|
+
@data[0][0] * other[0] + @data[0][1] * other[1] + @data[0][2] * other[2] + @data[0][3] * other[3],
|
96
|
+
@data[1][0] * other[0] + @data[1][1] * other[1] + @data[1][2] * other[2] + @data[1][3] * other[3],
|
97
|
+
@data[2][0] * other[0] + @data[2][1] * other[1] + @data[2][2] * other[2] + @data[2][3] * other[3],
|
98
|
+
@data[3][0] * other[0] + @data[3][1] * other[1] + @data[3][2] * other[2] + @data[3][3] * other[3]
|
99
|
+
)
|
100
|
+
elsif other.kind_of?(Numeric)
|
101
|
+
m = Matrix::new
|
102
|
+
4.times { |i|
|
103
|
+
4.times { |j|
|
104
|
+
m.data[i][j] = data[i][j] * other
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return m
|
108
|
+
else
|
109
|
+
raise "Invalid argument for matrix miltiply: #{other.inspect}!"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end #Matrix
|
113
|
+
|
114
|
+
class Vector
|
115
|
+
|
116
|
+
def initialize(x=0.0, y=0.0, z=0.0, w=1.0)
|
117
|
+
@data = [x, y, z, w]
|
118
|
+
end
|
119
|
+
|
120
|
+
def [](i)
|
121
|
+
return @data[i]
|
122
|
+
end
|
123
|
+
|
124
|
+
def []=(i,v)
|
125
|
+
return @data[i]=v
|
126
|
+
end
|
127
|
+
|
128
|
+
def dup
|
129
|
+
self.class::new(x,y,z,w)
|
130
|
+
end
|
131
|
+
|
132
|
+
def x
|
133
|
+
@data[0]
|
134
|
+
end
|
135
|
+
|
136
|
+
def x=(v)
|
137
|
+
@data[0] = v
|
138
|
+
end
|
139
|
+
|
140
|
+
def y
|
141
|
+
@data[1]
|
142
|
+
end
|
143
|
+
|
144
|
+
def y=(v)
|
145
|
+
@data[1] = v
|
146
|
+
end
|
147
|
+
|
148
|
+
def z
|
149
|
+
@data[2]
|
150
|
+
end
|
151
|
+
|
152
|
+
def z=(v)
|
153
|
+
@data[2]=v
|
154
|
+
end
|
155
|
+
|
156
|
+
def w
|
157
|
+
@data[3]
|
158
|
+
end
|
159
|
+
|
160
|
+
def w=(v)
|
161
|
+
@data[3] = v
|
162
|
+
end
|
163
|
+
|
164
|
+
def -(other)
|
165
|
+
Vector::new(x-other.x, y-other.y, z-other.z, w)
|
166
|
+
end
|
167
|
+
|
168
|
+
def +(other)
|
169
|
+
Vector::new(x+other.x, y+other.y, z+other.z, w)
|
170
|
+
end
|
171
|
+
|
172
|
+
def *(scalar)
|
173
|
+
Vector::new(x*scalar, y*scalar, z*scalar, w)
|
174
|
+
end
|
175
|
+
|
176
|
+
def dot(other)
|
177
|
+
x*other.x + y*other.y + z*other.z
|
178
|
+
end
|
179
|
+
|
180
|
+
def -@
|
181
|
+
self.class::new(-x, -y, -z, w)
|
182
|
+
end
|
183
|
+
|
184
|
+
def length
|
185
|
+
Math.sqrt(x*x + y*y + z*z)
|
186
|
+
end
|
187
|
+
|
188
|
+
def normalize!
|
189
|
+
l = length
|
190
|
+
if l != 0.0 && ! l.nan?
|
191
|
+
@data[0] /= l
|
192
|
+
@data[1] /= l
|
193
|
+
@data[2] /= l
|
194
|
+
else
|
195
|
+
@data[0] = 0.0
|
196
|
+
@data[1] = 0.0
|
197
|
+
@data[2] = 0.0
|
198
|
+
end
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
202
|
+
def normalize
|
203
|
+
self.dup.normalize!
|
204
|
+
end
|
205
|
+
|
206
|
+
end #Vector
|
207
|
+
|
208
|
+
def self.get_translation_vector(*args)
|
209
|
+
if args.length == 1
|
210
|
+
v = args.first.dup
|
211
|
+
elsif args.length == 3
|
212
|
+
v = Vector::new(*args)
|
213
|
+
else
|
214
|
+
raise "Invalid translation arguments: #{args.inspect}!"
|
215
|
+
end
|
216
|
+
v
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.get_translation_matrix(*args)
|
220
|
+
m = get_unit_matrix
|
221
|
+
v = get_translation_vector(*args)
|
222
|
+
m.data[0][3] = v[0]
|
223
|
+
m.data[1][3] = v[1]
|
224
|
+
m.data[2][3] = v[2]
|
225
|
+
m
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.get_inverse_translation_matrix(*args)
|
229
|
+
m = get_unit_matrix
|
230
|
+
v = get_translation_vector(*args)
|
231
|
+
m.data[0][3] = -v[0]
|
232
|
+
m.data[1][3] = -v[1]
|
233
|
+
m.data[2][3] = -v[2]
|
234
|
+
m
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.get_scaling_vector(*args)
|
238
|
+
if args.length == 1
|
239
|
+
v = args.first.dup
|
240
|
+
elsif args.length == 3
|
241
|
+
v = Vector::new(*args)
|
242
|
+
else
|
243
|
+
raise "Invalid translation arguments: #{args.inspect}!"
|
244
|
+
end
|
245
|
+
v
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.get_scaling_matrix(*args)
|
249
|
+
m = get_unit_matrix
|
250
|
+
v = get_scaling_vector(*args)
|
251
|
+
m.data[0][0] = v[0]
|
252
|
+
m.data[1][1] = v[1]
|
253
|
+
m.data[2][2] = v[2]
|
254
|
+
m
|
255
|
+
end
|
256
|
+
|
257
|
+
def self.get_inverse_scaling_matrix(*args)
|
258
|
+
m = get_unit_matrix
|
259
|
+
v = get_scaling_vector(*args)
|
260
|
+
m.data[0][0] = 1.0/v[0]
|
261
|
+
m.data[1][1] = 1.0/v[1]
|
262
|
+
m.data[2][2] = 1.0/v[2]
|
263
|
+
m
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.get_rotation_vector(*args)
|
267
|
+
if args.length == 1
|
268
|
+
v = args.first.dup
|
269
|
+
elsif args.length == 3
|
270
|
+
v = Vector::new(*args)
|
271
|
+
else
|
272
|
+
raise "Invalid translation arguments: #{args.inspect}!"
|
273
|
+
end
|
274
|
+
v
|
275
|
+
end
|
276
|
+
|
277
|
+
def self.get_rotation_matrix(*args, center: nil, order: nil)
|
278
|
+
v = get_rotation_vector(*args)
|
279
|
+
if center
|
280
|
+
vt = get_translation_vector(*[center].flatten)
|
281
|
+
mt1 = get_translation_matrix(-vt)
|
282
|
+
mt2 = get_translation_matrix(vt)
|
283
|
+
else
|
284
|
+
mt1 = get_unit_matrix
|
285
|
+
mt2 = get_unit_matrix
|
286
|
+
end
|
287
|
+
m = mt2
|
288
|
+
if order
|
289
|
+
case order
|
290
|
+
when 0
|
291
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
292
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
293
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
294
|
+
when 1
|
295
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
296
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
297
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
298
|
+
when 2
|
299
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
300
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
301
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
302
|
+
when 3
|
303
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
304
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
305
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
306
|
+
when 4
|
307
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
308
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
309
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
310
|
+
else
|
311
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
312
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
313
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
314
|
+
end
|
315
|
+
else
|
316
|
+
m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0))
|
317
|
+
m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0))
|
318
|
+
m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0))
|
319
|
+
end
|
320
|
+
m = m * mt1
|
321
|
+
m
|
322
|
+
end
|
323
|
+
|
324
|
+
def self.get_inverse_rotation_matrix(*args, center: nil, order: nil)
|
325
|
+
v = get_rotation_vector(*args)
|
326
|
+
if center
|
327
|
+
vt = get_translation_vector(*[center].flatten)
|
328
|
+
mt1 = get_translation_matrix(-vt)
|
329
|
+
mt2 = get_translation_matrix(vt)
|
330
|
+
else
|
331
|
+
mt1 = get_unit_matrix
|
332
|
+
mt2 = get_unit_matrix
|
333
|
+
end
|
334
|
+
m = mt2
|
335
|
+
if order
|
336
|
+
case order
|
337
|
+
when 0
|
338
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
339
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
340
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
341
|
+
when 1
|
342
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
343
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
344
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
345
|
+
when 2
|
346
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
347
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
348
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
349
|
+
when 3
|
350
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
351
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
352
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
353
|
+
when 4
|
354
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
355
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
356
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
357
|
+
else
|
358
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
359
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
360
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
361
|
+
end
|
362
|
+
else
|
363
|
+
m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0))
|
364
|
+
m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0))
|
365
|
+
m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0))
|
366
|
+
end
|
367
|
+
m = m * mt1
|
368
|
+
m
|
369
|
+
end
|
370
|
+
|
371
|
+
def self.get_unit_matrix
|
372
|
+
Matrix::new
|
373
|
+
end
|
374
|
+
|
375
|
+
def self.get_zero_matrix
|
376
|
+
Matrix::new * 0.0
|
377
|
+
end
|
378
|
+
|
379
|
+
def self.get_transformation_matrix(translate, rotate, scale, parent_scale, order: nil)
|
380
|
+
get_translation_matrix(translate) *
|
381
|
+
get_inverse_scaling_matrix(parent_scale) *
|
382
|
+
get_rotation_matrix(rotate, order: order) *
|
383
|
+
get_scaling_matrix(scale)
|
384
|
+
end
|
385
|
+
|
386
|
+
def self.get_inverse_transformation_matrix(translate, rotate, scale, parent_scale, order: nil)
|
387
|
+
get_inverse_scaling_matrix(scale) *
|
388
|
+
get_inverse_rotation_matrix(rotate, order: order) *
|
389
|
+
get_scaling_matrix(parent_scale) *
|
390
|
+
get_inverse_translation_matrix(translate)
|
391
|
+
end
|
392
|
+
|
393
|
+
private
|
394
|
+
|
395
|
+
# https://en.wikipedia.org/wiki/Rotation_matrix#Axis_and_angle
|
396
|
+
def self.rotation_matrix(angle, vector)
|
397
|
+
v = vector.normalize
|
398
|
+
x = v[0]
|
399
|
+
y = v[1]
|
400
|
+
z = v[2]
|
401
|
+
c = Math::cos(angle)
|
402
|
+
d = 1 - c
|
403
|
+
s = Math::sin(angle)
|
404
|
+
|
405
|
+
m = Matrix::new
|
406
|
+
|
407
|
+
m.data.replace( [ [ x*x*d + c, x*y*d - z*s, x*z*d + y*s, 0.0],
|
408
|
+
[ y*x*d + z*s, y*y*d + c, y*z*d - x*s, 0.0],
|
409
|
+
[ z*x*d - y*s, z*y*d + x*s, z*z*d + c, 0.0],
|
410
|
+
[ 0.0, 0.0, 0.0, 1.0] ] )
|
411
|
+
m
|
412
|
+
end
|
413
|
+
|
414
|
+
end #Linalg
|
415
|
+
|
416
|
+
end #Bayonetta
|