class Assimp::Matrix3x3

Public Class Methods

identity() click to toggle source
# File lib/assimp/matrix3x3.rb, line 12
def self.identity
  m = Matrix3x3::new
  Assimp::aiIdentityMatrix3(m)
  m
end
rotation(a, axis) click to toggle source
# File lib/assimp/matrix3x3.rb, line 18
def self.rotation(a, axis)
  # https://en.wikipedia.org/wiki/Rotation_matrix#Axis_and_angle
  c = Math::cos(a)
  s = Math::sin(a)
  t = 1 - c
  x = axis.x
  y = axis.y
  z = axis.z

  out = Matrix3x3
  out.a1 = t*x*x + c
  out.a2 = t*x*y - s*z
  out.a3 = t*x*z + s*y
  out.b1 = t*x*y + s*z
  out.b2 = t*y*y + c
  out.b3 = t*y*z - s*x
  out.c1 = t*x*z - s*y
  out.c2 = t*y*z + s*x
  out.c3 = t*z*z + c
  out
end

Public Instance Methods

*(other) click to toggle source
# File lib/assimp/matrix3x3.rb, line 63
def *(other)
  if other.kind_of?(Matrix3x3)
    m = self.dup
    Assimp::aiMultiplyMatrix3(m, other)
    m
  elsif other.kind_of?(Vector3D)
    v = other.dup
    Assimp::aiTransformVecByMatrix3(v, self)
    v
  else
    raise "Unsupported operand: #{other.inspect}!"
  end
end
determinant() click to toggle source
# File lib/assimp/matrix3x3.rb, line 77
def determinant
  a1*b2*c3 - a1*b3*c2 + a2*b3*c1 - a2*b1*c3 + a3*b1*c2 - a3*b2*c1
end
inverse() click to toggle source
# File lib/assimp/matrix3x3.rb, line 81
def inverse
  det = determinant
  raise "Not inversible!" if det == 0.0
  m = Matrix3x3::new
  invdet = 1.0/det
  m.a1 = invdet  * (b2 * c3 - b3 * c2)
  m.a2 = -invdet * (a2 * c3 - a3 * c2)
  m.a3 = invdet  * (a2 * b3 - a3 * b2)
  m.b1 = -invdet * (b1 * c3 - b3 * c1)
  m.b2 = invdet  * (a1 * c3 - a3 * c1)
  m.b3 = -invdet * (a1 * b3 - a3 * b1)
  m.c1 = invdet  * (b1 * c2 - b2 * c1)
  m.c2 = -invdet * (a1 * c2 - a2 * c1)
  m.c3 = invdet  * (a1 * b2 - a2 * b1)
  m
end
quaternion() click to toggle source
# File lib/assimp/matrix3x3.rb, line 48
def quaternion
  q = Quaternion::new
  Assimp::aiCreateQuaternionFromMatrix(q, self)
end
to_s() click to toggle source
# File lib/assimp/matrix3x3.rb, line 40
    def to_s
      <<EOF
< <#{a1}, #{a2}, #{a3}>,
  <#{b1}, #{b2}, #{b3}>,
  <#{c1}, #{c2}, #{c3}> >
EOF
    end
transpose() click to toggle source
# File lib/assimp/matrix3x3.rb, line 58
def transpose
  t = self.dup
  t.transpose!
end
transpose!() click to toggle source
# File lib/assimp/matrix3x3.rb, line 53
def transpose!
  Assimp::aiTransposeMatrix3(self)
  self
end