class RubyGL::Vec3
Public Class Methods
new(array = nil)
click to toggle source
# File lib/rubygl/math.rb, line 18 def initialize(array = nil) @data = Array.new(3, 0) if array then for i in 0...@data.size @data[i] = array[i] end end end
Public Instance Methods
+(other_vector)
click to toggle source
# File lib/rubygl/math.rb, line 28 def +(other_vector) new_vector = Vec3.new() for i in 0...@data.size new_vector[i] = @data[i] + other_vector[i] end new_vector end
-(other_vector)
click to toggle source
# File lib/rubygl/math.rb, line 38 def -(other_vector) new_vector = Vec3.new() for i in 0...@data.size new_vector[i] = @data[i] - other_vector[i] end new_vector end
[](index)
click to toggle source
# File lib/rubygl/math.rb, line 87 def [](index) @data[index] end
[]=(index, value)
click to toggle source
# File lib/rubygl/math.rb, line 91 def []=(index, value) @data[index] = value end
cross(other_vector)
click to toggle source
# File lib/rubygl/math.rb, line 48 def cross(other_vector) new_vector = Vec3.new() new_vector[0] = (@data[1] * other_vector[2]) - (@data[2] * other_vector[1]) new_vector[1] = (@data[0] * other_vector[2]) - (@data[2] * other_vector[0]) new_vector[2] = (@data[0] * other_vector[1]) - (@data[1] * other_vector[0]) new_vector end
len()
click to toggle source
# File lib/rubygl/math.rb, line 77 def len() sum = 0 for i in 0...@data.size sum += @data[i] * @data[i] end Math::sqrt(sum) end
norm()
click to toggle source
# File lib/rubygl/math.rb, line 66 def norm() new_vector = Vec2.new() for i in 0...@data.size new_vector[i] = @data[i] end new_vector.norm! new_vector end
norm!()
click to toggle source
# File lib/rubygl/math.rb, line 58 def norm!() curr_len = self.len().abs() for i in 0...@data.size @data[i] /= curr_len end end
to_a()
click to toggle source
# File lib/rubygl/math.rb, line 99 def to_a() self.to_ary end
to_ary()
click to toggle source
# File lib/rubygl/math.rb, line 95 def to_ary() Array.new(@data) end