Class: RubyGL::Vec4
- Inherits:
-
Object
- Object
- RubyGL::Vec4
- Defined in:
- lib/rubygl/math.rb
Instance Method Summary collapse
- #+(other_vector) ⇒ Object
- #-(other_vector) ⇒ Object
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
-
#initialize ⇒ Vec4
constructor
A new instance of Vec4.
- #len ⇒ Object
- #norm ⇒ Object
- #norm! ⇒ Object
- #to_a ⇒ Object
- #to_ary ⇒ Object
Constructor Details
#initialize ⇒ Vec4
Returns a new instance of Vec4.
105 106 107 |
# File 'lib/rubygl/math.rb', line 105 def initialize() @data = Array.new(4, 0) end |
Instance Method Details
#+(other_vector) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/rubygl/math.rb', line 109 def +(other_vector) new_vector = Vec4.new() for i in 0..@data.size new_vector[i] = @data[i] + other_vector[i] end new_vector end |
#-(other_vector) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/rubygl/math.rb', line 119 def -(other_vector) new_vector = Vec4.new() for i in 0..@data.size new_vector[i] = @data[i] - other_vector[i] end new_vector end |
#[](index) ⇒ Object
158 159 160 |
# File 'lib/rubygl/math.rb', line 158 def [](index) @data[index] end |
#[]=(index, value) ⇒ Object
162 163 164 |
# File 'lib/rubygl/math.rb', line 162 def []=(index, value) @data[index] = value end |
#len ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/rubygl/math.rb', line 148 def len() sum = 0 for i in 0...@data.size sum += @data[i] * @data[i] end Math::sqrt(sum) end |
#norm ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rubygl/math.rb', line 137 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! ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/rubygl/math.rb', line 129 def norm!() curr_len = self.len() for i in 0...@data.size @data /= curr_len end end |
#to_a ⇒ Object
170 171 172 |
# File 'lib/rubygl/math.rb', line 170 def to_a() self.to_ary end |
#to_ary ⇒ Object
166 167 168 |
# File 'lib/rubygl/math.rb', line 166 def to_ary() Array.new(@data) end |