Class: RBGL::Engine::IndexBuffer
- Inherits:
-
Object
- Object
- RBGL::Engine::IndexBuffer
- Defined in:
- lib/rbgl/engine/buffer.rb
Instance Attribute Summary collapse
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
Instance Method Summary collapse
- #add(*idx) ⇒ Object
- #each_triangle ⇒ Object
- #get_triangle(index) ⇒ Object
-
#initialize(indices = []) ⇒ IndexBuffer
constructor
A new instance of IndexBuffer.
- #triangle_count ⇒ Object
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
#indices ⇒ Object (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_triangle ⇒ Object
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_count ⇒ Object
213 214 215 |
# File 'lib/rbgl/engine/buffer.rb', line 213 def triangle_count @indices.size / 3 end |