Class: RubyGL::Vec4

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygl/math.rb

Instance Method Summary collapse

Constructor Details

#initializeVec4

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

#lenObject



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

#normObject



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_aObject



170
171
172
# File 'lib/rubygl/math.rb', line 170

def to_a()
    self.to_ary
end

#to_aryObject



166
167
168
# File 'lib/rubygl/math.rb', line 166

def to_ary()
    Array.new(@data)
end