Module: Rgltf::Matrix4

Defined in:
lib/rgltf/properties/node.rb

Constant Summary collapse

IDENTITY =
[
  1.0, 0.0, 0.0, 0.0,
  0.0, 1.0, 0.0, 0.0,
  0.0, 0.0, 1.0, 0.0,
  0.0, 0.0, 0.0, 1.0
].freeze

Class Method Summary collapse

Class Method Details

.from_trs(translation, rotation, scale) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rgltf/properties/node.rb', line 22

def from_trs(translation, rotation, scale)
  x, y, z, w = rotation
  sx, sy, sz = scale
  xx = x * x
  yy = y * y
  zz = z * z
  xy = x * y
  xz = x * z
  yz = y * z
  xw = x * w
  yw = y * w
  zw = z * w
  [
    (1.0 - (2.0 * (yy + zz))) * sx, (2.0 * (xy + zw)) * sx, (2.0 * (xz - yw)) * sx, 0.0,
    (2.0 * (xy - zw)) * sy, (1.0 - (2.0 * (xx + zz))) * sy, (2.0 * (yz + xw)) * sy, 0.0,
    (2.0 * (xz + yw)) * sz, (2.0 * (yz - xw)) * sz, (1.0 - (2.0 * (xx + yy))) * sz, 0.0,
    translation[0], translation[1], translation[2], 1.0
  ].freeze
end

.multiply(left, right) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rgltf/properties/node.rb', line 14

def multiply(left, right)
  Array.new(16) do |index|
    row = index % 4
    column = index / 4
    4.times.sum { |inner| left[(inner * 4) + row] * right[(column * 4) + inner] }
  end.freeze
end