Class: GlimR::Geometry
- Inherits:
-
SceneObject
- Object
- SceneObject
- GlimR::Geometry
- Defined in:
- lib/glimr/renderer/geometry.rb
Overview
A Geometry object abstracts vertex arrays. It may contain a normal array, texcoord array, color array and vertex array.
The type of a Geometry is the corresponding GL VertexPointer type.
A Geometry is required to actually draw something to the screen.
Instance Attribute Summary collapse
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#normals ⇒ Object
Returns the value of attribute normals.
-
#texcoords ⇒ Object
Returns the value of attribute texcoords.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vertice_count ⇒ Object
Returns the value of attribute vertice_count.
-
#vertices ⇒ Object
Returns the value of attribute vertices.
Attributes inherited from SceneObject
#children, #mtime, #parent, #viewport
Attributes included from EventListener
#event_listeners, #listener_count
Instance Method Summary collapse
-
#absolute_geometry ⇒ Object
The collapsed geometry of a Geometry is the Geometry itself.
-
#apply ⇒ Object
Applies the different arrays and draws if vertices set.
- #collapse(list = []) ⇒ Object
-
#coords(d) ⇒ Object
Returns the coordinates that have coord index % 3 == d.
- #default_config ⇒ Object
-
#draw ⇒ Object
Draws the vertex arrays.
-
#drawables ⇒ Object
A geometry is a drawable.
- #inspect ⇒ Object
-
#max_x ⇒ Object
Returns the largest x coordinate in the vertices.
-
#max_y ⇒ Object
Returns the largest y coordinate in the vertices.
-
#max_z ⇒ Object
Returns the largest z coordinate in the vertices.
-
#merge!(other) ⇒ Object
Merges self with the other.
-
#min_x ⇒ Object
Returns the smallest x coordinate in the vertices.
-
#min_y ⇒ Object
Returns the smallest y coordinate in the vertices.
-
#min_z ⇒ Object
Returns the smallest z coordinate in the vertices.
-
#parse_array(v) ⇒ Object
Parses the given vertex array to a valid OpenGL vertex array.
-
#pop_state ⇒ Object
Disables vertex arrays.
-
#push_state ⇒ Object
Enables vertex arrays.
-
#replace!(other) ⇒ Object
Replaces ivars with the other’s.
-
#x_coords ⇒ Object
Returns an array of the x coordinates in the vertices.
-
#y_coords ⇒ Object
Returns an array of the y coordinates in the vertices.
-
#z_coords ⇒ Object
Returns an array of the z coordinates in the vertices.
Methods inherited from SceneObject
#<<, #absolute_material, #absolute_shader, #absolute_texture, #absolute_transform, #absolute_transform_for_drawing, #add_drawables, #attach, #clone, #detach, #detach_self, #initialize, #remove_drawables, #render, #replace_node, #root, #touch!, #visible
Methods included from Configurable
Methods included from EventListener
#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #initialize, #method_missing, #multicast_event, #process_event, #remove_event_listener
Constructor Details
This class inherits a constructor from GlimR::SceneObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GlimR::EventListener
Instance Attribute Details
#colors ⇒ Object
Returns the value of attribute colors.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def colors @colors end |
#normals ⇒ Object
Returns the value of attribute normals.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def normals @normals end |
#texcoords ⇒ Object
Returns the value of attribute texcoords.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def texcoords @texcoords end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def type @type end |
#vertice_count ⇒ Object
Returns the value of attribute vertice_count.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def vertice_count @vertice_count end |
#vertices ⇒ Object
Returns the value of attribute vertices.
16 17 18 |
# File 'lib/glimr/renderer/geometry.rb', line 16 def vertices @vertices end |
Instance Method Details
#absolute_geometry ⇒ Object
The collapsed geometry of a Geometry is the Geometry itself.
113 114 115 |
# File 'lib/glimr/renderer/geometry.rb', line 113 def absolute_geometry self end |
#apply ⇒ Object
Applies the different arrays and draws if vertices set.
163 164 165 166 167 168 169 |
# File 'lib/glimr/renderer/geometry.rb', line 163 def apply NormalPointer FLOAT, 0, normals if normals TexCoordPointer 2, FLOAT, 0, texcoords if texcoords ColorPointer 4, FLOAT, 0, colors if colors VertexPointer 3, FLOAT, 0, vertices if vertices draw if vertices end |
#collapse(list = []) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/glimr/renderer/geometry.rb', line 105 def collapse(list=[]) if vertices # drawable geometry list << self end super end |
#coords(d) ⇒ Object
Returns the coordinates that have coord index % 3 == d.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/glimr/renderer/geometry.rb', line 70 def coords(d) if vertices v = vertices.unpack("f*") i = -1 v.find_all{|c| i += 1 i%3 == d } else [0] end end |
#default_config ⇒ Object
18 19 20 21 22 |
# File 'lib/glimr/renderer/geometry.rb', line 18 def default_config super.merge( :type => GL::QUADS ) end |
#draw ⇒ Object
Draws the vertex arrays.
84 85 86 |
# File 'lib/glimr/renderer/geometry.rb', line 84 def draw DrawArrays type, 0, vertice_count end |
#drawables ⇒ Object
A geometry is a drawable.
101 102 103 |
# File 'lib/glimr/renderer/geometry.rb', line 101 def drawables @drawables + [self] end |
#inspect ⇒ Object
187 188 189 |
# File 'lib/glimr/renderer/geometry.rb', line 187 def inspect "#<#{self.class.name}:#{hash}:TYPE#@type:#@vertice_count vertices>" end |
#max_x ⇒ Object
Returns the largest x coordinate in the vertices.
30 31 32 |
# File 'lib/glimr/renderer/geometry.rb', line 30 def max_x x_coords.max end |
#max_y ⇒ Object
Returns the largest y coordinate in the vertices.
40 41 42 |
# File 'lib/glimr/renderer/geometry.rb', line 40 def max_y y_coords.max end |
#max_z ⇒ Object
Returns the largest z coordinate in the vertices.
50 51 52 |
# File 'lib/glimr/renderer/geometry.rb', line 50 def max_z z_coords.max end |
#merge!(other) ⇒ Object
Merges self with the other.
118 119 120 121 122 123 124 125 126 |
# File 'lib/glimr/renderer/geometry.rb', line 118 def merge!(other) @type = other.type if other.type @normals = other.normals if other.normals @texcoords = other.texcoords if other.texcoords @colors = other.colors if other.colors @vertices = other.vertices if other.vertices @vertice_count = other.vertice_count if other.vertice_count self end |
#min_x ⇒ Object
Returns the smallest x coordinate in the vertices.
25 26 27 |
# File 'lib/glimr/renderer/geometry.rb', line 25 def min_x x_coords.min end |
#min_y ⇒ Object
Returns the smallest y coordinate in the vertices.
35 36 37 |
# File 'lib/glimr/renderer/geometry.rb', line 35 def min_y y_coords.min end |
#min_z ⇒ Object
Returns the smallest z coordinate in the vertices.
45 46 47 |
# File 'lib/glimr/renderer/geometry.rb', line 45 def min_z z_coords.min end |
#parse_array(v) ⇒ Object
Parses the given vertex array to a valid OpenGL vertex array
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/glimr/renderer/geometry.rb', line 89 def parse_array(v) case v when Array v.flatten.pack("f*") when String,nil,false v else raise ArgumentError, "Provide either an Array of coords or a String of packed floats" end end |
#pop_state ⇒ Object
Disables vertex arrays.
180 181 182 183 184 185 |
# File 'lib/glimr/renderer/geometry.rb', line 180 def pop_state DisableClientState NORMAL_ARRAY if normals DisableClientState TEXTURE_COORD_ARRAY if texcoords DisableClientState COLOR_ARRAY if colors DisableClientState VERTEX_ARRAY if vertices end |
#push_state ⇒ Object
Enables vertex arrays.
172 173 174 175 176 177 |
# File 'lib/glimr/renderer/geometry.rb', line 172 def push_state EnableClientState NORMAL_ARRAY if normals EnableClientState TEXTURE_COORD_ARRAY if texcoords EnableClientState COLOR_ARRAY if colors EnableClientState VERTEX_ARRAY if vertices end |
#replace!(other) ⇒ Object
Replaces ivars with the other’s.
129 130 131 132 133 134 135 136 137 |
# File 'lib/glimr/renderer/geometry.rb', line 129 def replace!(other) @type = other.type @normals = other.normals @texcoords = other.texcoords @colors = other.colors @vertices = other.vertices @vertice_count = other.vertice_count self end |
#x_coords ⇒ Object
Returns an array of the x coordinates in the vertices.
55 56 57 |
# File 'lib/glimr/renderer/geometry.rb', line 55 def x_coords coords 0 end |
#y_coords ⇒ Object
Returns an array of the y coordinates in the vertices.
60 61 62 |
# File 'lib/glimr/renderer/geometry.rb', line 60 def y_coords coords 1 end |
#z_coords ⇒ Object
Returns an array of the z coordinates in the vertices.
65 66 67 |
# File 'lib/glimr/renderer/geometry.rb', line 65 def z_coords coords 2 end |