Class: FMOD::Geometry
- Includes:
- Enumerable
- Defined in:
- lib/fmod/geometry.rb
Overview
FMOD supports the supply of polygon mesh data, that can be processed in realtime to create the effect of occlusion in a real 3D world. In real world terms, the user can stop sounds travelling through walls, or even confine reverb inside a geometric volume so that it doesn’t leak out into other areas.
Defined Under Namespace
Instance Attribute Summary collapse
-
#active ⇒ Boolean
Value indicating if object will be processed in the geometry engine.
-
#polygon_count ⇒ Integer
(also: #size)
Retrieves the number of polygons stored within this Geometry object.
-
#position ⇒ Vector
The position of the object in world space, which is the same space FMOD sounds and listeners reside in.
-
#rotation ⇒ Rotation
The current orientation of the geometry object.
-
#scale ⇒ Vector
The relative scale vector of the geometry object.
Attributes inherited from Handle
Instance Method Summary collapse
-
#[](index) ⇒ Polygon
Retrieves the Polygon at the specified index.
-
#add_polygon(vertices, direct = 0.0, reverb = 0.0, double_sided = false) ⇒ Object
Adds a polygon to an geometry object.
-
#each ⇒ Object
Enumerates the polygons contained within the Geometry.
-
#max_polygons ⇒ Integer
Retrieves the maximum number of polygons allocatable for this object.
-
#max_vertices ⇒ Integer
Retrieves the maximum number of vertices allocatable for this object.
- #polygons ⇒ Array<Polygon>
-
#rotate(forward, upward) ⇒ Object
Sets the orientation of the geometry object.
-
#save(filename = nil) ⇒ Object
Serializes the Geometry object into a binary block.
Methods inherited from Handle
#initialize, #int_ptr, #release, #to_s
Constructor Details
This class inherits a constructor from FMOD::Handle
Instance Attribute Details
#active ⇒ Boolean
Value indicating if object will be processed in the geometry engine.
19 |
# File 'lib/fmod/geometry.rb', line 19 bool_reader(:active, :Geometry_GetActive) |
#polygon_count ⇒ Integer Also known as: size
Retrieves the number of polygons stored within this FMOD::Geometry object.
27 |
# File 'lib/fmod/geometry.rb', line 27 integer_reader(:polygon_count, :Geometry_GetNumPolygons) |
#position ⇒ Vector
The position of the object in world space, which is the same space FMOD sounds and listeners reside in.
38 39 40 41 |
# File 'lib/fmod/geometry.rb', line 38 def position FMOD.invoke(:Geometry_GetPosition, self, vector = Vector.zero) vector end |
#rotation ⇒ Rotation
The current orientation of the geometry object.
74 75 76 77 78 |
# File 'lib/fmod/geometry.rb', line 74 def rotation forward, up = Vector.zero, Vector.zero FMOD.invoke(:Geometry_GetRotation, self, forward, up) Rotation.new(forward, up) end |
#scale ⇒ Vector
The relative scale vector of the geometry object. An object can be scaled/warped in all 3 dimensions separately using the vector without having to modify polygon data.
-
Default: Core::Vector.one
57 58 59 60 |
# File 'lib/fmod/geometry.rb', line 57 def scale FMOD.invoke(:Geometry_GetScale, self, vector = Vector.zero) vector end |
Instance Method Details
#[](index) ⇒ Polygon
Retrieves the Polygon at the specified index.
128 129 130 131 |
# File 'lib/fmod/geometry.rb', line 128 def [](index) return nil unless index.between?(0, polygon_count) Polygon.send(:new, self, index) end |
#add_polygon(vertices, direct = 0.0, reverb = 0.0, double_sided = false) ⇒ Object
A minimum of 3 vertices is required to create a Polygon.
Adds a polygon to an geometry object.
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/fmod/geometry.rb', line 156 def add_polygon(vertices, direct = 0.0, reverb = 0.0, double_sided = false) size = vertices.size unless size >= 3 = "3 or more vertices required for polygon: #{size} specified" raise ArgumentError, end vectors = vertices.map(&:to_str).join direct = direct.clamp(0.0, 1.0) reverb = reverb.clamp(0.0, 1.0) FMOD.invoke(:Geometry_AddPolygon, self, direct, reverb, double_sided.to_i, size, vectors, index = "\0" * SIZEOF_INT) Polygon.send(:new, self, index.unpack1('l')) end |
#each {|polygon| ... } ⇒ self #each ⇒ Enumerator
Enumerates the polygons contained within the FMOD::Geometry.
205 206 207 208 209 |
# File 'lib/fmod/geometry.rb', line 205 def each return to_enum(:each) unless block_given? (0...polygon_count).each { |i| yield self[i] } self end |
#max_polygons ⇒ Integer
Retrieves the maximum number of polygons allocatable for this object.
This is not the number of polygons currently present.
107 108 109 110 111 |
# File 'lib/fmod/geometry.rb', line 107 def max_polygons max = "\0" * SIZEOF_INT FMOD.invoke(:Geometry_GetMaxPolygons, self, max, nil) max.unpack1('l') end |
#max_vertices ⇒ Integer
Retrieves the maximum number of vertices allocatable for this object.
This is not the number of vertices currently present.
118 119 120 121 122 |
# File 'lib/fmod/geometry.rb', line 118 def max_vertices max = "\0" * SIZEOF_INT FMOD.invoke(:Geometry_GetMaxPolygons, self, nil, max) max.unpack1('l') end |
#polygons ⇒ Array<Polygon>
Retrieves an array of Polygon objects within this FMOD::Geometry.
214 215 216 |
# File 'lib/fmod/geometry.rb', line 214 def polygons (0...polygon_count).map { |i| self[i] } end |
#rotate(forward, upward) ⇒ Object
Sets the orientation of the geometry object.
95 96 97 98 99 |
# File 'lib/fmod/geometry.rb', line 95 def rotate(forward, upward) FMOD.type?(forward, Vector) unless forward.nil? FMOD.type?(upward, Vector) unless upward.nil? FMOD.invoke(:Geometry_SetRotation, self, forward, upward) end |
#save(filename) ⇒ Boolean #save ⇒ String
Serializes the FMOD::Geometry object into a binary block.
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/fmod/geometry.rb', line 182 def save(filename = nil) FMOD.invoke(:Geometry_Save, self, nil, size = "\0" * SIZEOF_INT) data = "\0" * size.unpack1('l') FMOD.invoke(:Geometry_Save, self, data, size) unless filename.nil? File.open(filename, 'wb') { |file| file.write(data) } rescue return false return true end data end |