Class: RBGL::Engine::IndexBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/engine/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indices = []) ⇒ IndexBuffer

Returns a new instance of IndexBuffer.



204
205
206
# File 'lib/rbgl/engine/buffer.rb', line 204

def initialize(indices = [])
  @indices = indices.map(&:to_i)
end

Instance Attribute Details

#indicesObject (readonly)

Returns the value of attribute indices.



202
203
204
# File 'lib/rbgl/engine/buffer.rb', line 202

def indices
  @indices
end

Instance Method Details

#add(*idx) ⇒ Object



208
209
210
211
# File 'lib/rbgl/engine/buffer.rb', line 208

def add(*idx)
  @indices.concat(idx.flatten.map(&:to_i))
  self
end

#each_triangleObject



222
223
224
225
226
# File 'lib/rbgl/engine/buffer.rb', line 222

def each_triangle
  return enum_for(:each_triangle) unless block_given?

  (0...triangle_count).each { |i| yield get_triangle(i) }
end

#get_triangle(index) ⇒ Object



217
218
219
220
# File 'lib/rbgl/engine/buffer.rb', line 217

def get_triangle(index)
  start = index * 3
  @indices[start, 3]
end

#triangle_countObject



213
214
215
# File 'lib/rbgl/engine/buffer.rb', line 213

def triangle_count
  @indices.size / 3
end