Class: Snow::Mat3

Inherits:
Object show all
Defined in:
lib/gosling/patches.rb

Instance Method Summary collapse

Instance Method Details

#identity?Boolean

Returns true if this Mat3 is an identity matrix.

Returns:

  • (Boolean)


38
39
40
# File 'lib/gosling/patches.rb', line 38

def identity?
  [1, 2, 3, 5, 6, 7].all? { |i| self[i] == 0 } && [0, 4, 8].all? { |i| self[i] == 1 }
end

#multiply(rhs, out = nil) ⇒ Object Also known as: *

Monkey-patch fix for Mat3 * Vec3



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gosling/patches.rb', line 8

def multiply(rhs, out = nil)
  case rhs
  when ::Snow::Mat3
    multiply_mat3(rhs, out)
  when ::Snow::Vec3
    values = (0..2).map { |i| get_row3(i) ** rhs }
    out ||= Snow::Vec3.new
    out.set(values)
  when Numeric
    scale(rhs, rhs, rhs, out)
  else
    raise TypeError, "Invalid type for RHS"
  end
end

#multiply!(rhs) ⇒ Object

Monkey-patch fix for #multiply! type-switching



27
28
29
30
31
32
33
# File 'lib/gosling/patches.rb', line 27

def multiply!(rhs)
  multiply rhs, case rhs
                when ::Snow::Mat3, Numeric then self
                when ::Snow::Vec3 then rhs
                else raise TypeError, "Invalid type for RHS"
                end
end