Module: Bayonetta::Linalg
- Defined in:
- lib/bayonetta/linalg.rb
Defined Under Namespace
Class Method Summary collapse
- .get_inverse_rotation_matrix(*args, center: nil, order: nil) ⇒ Object
- .get_inverse_scaling_matrix(*args) ⇒ Object
- .get_inverse_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) ⇒ Object
- .get_inverse_translation_matrix(*args) ⇒ Object
- .get_rotation_matrix(*args, center: nil, order: nil) ⇒ Object
- .get_rotation_vector(*args) ⇒ Object
- .get_scaling_matrix(*args) ⇒ Object
- .get_scaling_vector(*args) ⇒ Object
- .get_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) ⇒ Object
- .get_translation_matrix(*args) ⇒ Object
-
.get_translation_vector(*args) ⇒ Object
Vector.
- .get_unit_matrix ⇒ Object
- .get_zero_matrix ⇒ Object
Class Method Details
.get_inverse_rotation_matrix(*args, center: nil, order: nil) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/bayonetta/linalg.rb', line 324 def self.get_inverse_rotation_matrix(*args, center: nil, order: nil) v = get_rotation_vector(*args) if center vt = get_translation_vector(*[center].flatten) mt1 = get_translation_matrix(-vt) mt2 = get_translation_matrix(vt) else mt1 = get_unit_matrix mt2 = get_unit_matrix end m = mt2 if order case order when 0 m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) when 1 m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) when 2 m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) when 3 m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) when 4 m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) else m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) end else m = m * rotation_matrix( -v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( -v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( -v[2], Vector::new(0.0, 0.0, 1.0)) end m = m * mt1 m end |
.get_inverse_scaling_matrix(*args) ⇒ Object
257 258 259 260 261 262 263 264 |
# File 'lib/bayonetta/linalg.rb', line 257 def self.get_inverse_scaling_matrix(*args) m = get_unit_matrix v = get_scaling_vector(*args) m.data[0][0] = 1.0/v[0] m.data[1][1] = 1.0/v[1] m.data[2][2] = 1.0/v[2] m end |
.get_inverse_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) ⇒ Object
386 387 388 389 390 391 |
# File 'lib/bayonetta/linalg.rb', line 386 def self.get_inverse_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) get_inverse_scaling_matrix(scale) * get_inverse_rotation_matrix(rotate, order: order) * get_scaling_matrix(parent_scale) * get_inverse_translation_matrix(translate) end |
.get_inverse_translation_matrix(*args) ⇒ Object
228 229 230 231 232 233 234 235 |
# File 'lib/bayonetta/linalg.rb', line 228 def self.get_inverse_translation_matrix(*args) m = get_unit_matrix v = get_translation_vector(*args) m.data[0][3] = -v[0] m.data[1][3] = -v[1] m.data[2][3] = -v[2] m end |
.get_rotation_matrix(*args, center: nil, order: nil) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/bayonetta/linalg.rb', line 277 def self.get_rotation_matrix(*args, center: nil, order: nil) v = get_rotation_vector(*args) if center vt = get_translation_vector(*[center].flatten) mt1 = get_translation_matrix(-vt) mt2 = get_translation_matrix(vt) else mt1 = get_unit_matrix mt2 = get_unit_matrix end m = mt2 if order case order when 0 m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) when 1 m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) when 2 m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) when 3 m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) when 4 m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) else m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) end else m = m * rotation_matrix( v[2], Vector::new(0.0, 0.0, 1.0)) m = m * rotation_matrix( v[1], Vector::new(0.0, 1.0, 0.0)) m = m * rotation_matrix( v[0], Vector::new(1.0, 0.0, 0.0)) end m = m * mt1 m end |
.get_rotation_vector(*args) ⇒ Object
266 267 268 269 270 271 272 273 274 275 |
# File 'lib/bayonetta/linalg.rb', line 266 def self.get_rotation_vector(*args) if args.length == 1 v = args.first.dup elsif args.length == 3 v = Vector::new(*args) else raise "Invalid translation arguments: #{args.inspect}!" end v end |
.get_scaling_matrix(*args) ⇒ Object
248 249 250 251 252 253 254 255 |
# File 'lib/bayonetta/linalg.rb', line 248 def self.get_scaling_matrix(*args) m = get_unit_matrix v = get_scaling_vector(*args) m.data[0][0] = v[0] m.data[1][1] = v[1] m.data[2][2] = v[2] m end |
.get_scaling_vector(*args) ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/bayonetta/linalg.rb', line 237 def self.get_scaling_vector(*args) if args.length == 1 v = args.first.dup elsif args.length == 3 v = Vector::new(*args) else raise "Invalid translation arguments: #{args.inspect}!" end v end |
.get_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) ⇒ Object
379 380 381 382 383 384 |
# File 'lib/bayonetta/linalg.rb', line 379 def self.get_transformation_matrix(translate, rotate, scale, parent_scale, order: nil) get_translation_matrix(translate) * get_inverse_scaling_matrix(parent_scale) * get_rotation_matrix(rotate, order: order) * get_scaling_matrix(scale) end |
.get_translation_matrix(*args) ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'lib/bayonetta/linalg.rb', line 219 def self.get_translation_matrix(*args) m = get_unit_matrix v = get_translation_vector(*args) m.data[0][3] = v[0] m.data[1][3] = v[1] m.data[2][3] = v[2] m end |
.get_translation_vector(*args) ⇒ Object
Vector
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/bayonetta/linalg.rb', line 208 def self.get_translation_vector(*args) if args.length == 1 v = args.first.dup elsif args.length == 3 v = Vector::new(*args) else raise "Invalid translation arguments: #{args.inspect}!" end v end |