Class: FMOD::Geometry::Polygon Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fmod/geometry.rb

Overview

This class is abstract.

Wrapper class for a polygon within a FMOD::Geometry object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geometry, index) ⇒ Polygon

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Polygon objects should not be created by the user, only through FMOD::Geometry#add_polygon, as they are an abstract wrapper only, not backed by an actual object.

Creates a new instance of a Polygon object.

Parameters:

  • geometry (Geometry)

    The parent geometry object.

  • index (Integer)

    The index of the polygon within the geometry.



257
258
259
# File 'lib/fmod/geometry.rb', line 257

def initialize(geometry, index)
  @geometry, @index = geometry, index
end

Instance Attribute Details

#direct_occlusionFloat

The occlusion value from 0.0 to 1.0 which affects volume or audible frequencies.

  • Minimum: 0.0 The polygon does not occlude volume or audible frequencies (sound will be fully audible)

  • Maximum: 1.0 The polygon fully occludes (sound will be silent)

Returns:

  • (Float)


271
272
273
274
275
276
# File 'lib/fmod/geometry.rb', line 271

def direct_occlusion
  occlusion = "\0" * Fiddle::SIZEOF_FLOAT
  FMOD.invoke(:Geometry_GetPolygonAttributes, @geometry, @index,
              occlusion, nil, nil)
  occlusion.unpack1('f')
end

#double_sidedBoolean

The description of polygon if it is double sided or single sided.

  • true: The polygon is double sided

  • false: The polygon is single sided, and the winding of the polygon (which determines the polygon’s normal) determines which side of the polygon will cause occlusion.

Returns:

  • (Boolean)


315
316
317
318
319
320
# File 'lib/fmod/geometry.rb', line 315

def double_sided
  double = "\0" * Fiddle::SIZEOF_INT
  FMOD.invoke(:Geometry_GetPolygonAttributes, @geometry, @index,
              nil, nil, double)
  double.unpack1('l') != 0
end

#geometryGeometry (readonly)

The parent geometry object.

Returns:



242
243
244
# File 'lib/fmod/geometry.rb', line 242

def geometry
  @geometry
end

#indexInteger (readonly)

The index of the FMOD::Geometry::Polygon within its parent FMOD::Geometry object.

Returns:

  • (Integer)


247
248
249
# File 'lib/fmod/geometry.rb', line 247

def index
  @index
end

#reverb_occlusionFloat

The occlusion value from 0.0 to 1.0 which affects the reverb mix.

  • Minimum: 0.0 The polygon does not occlude reverb (reverb reflections still travel through this polygon)

  • Maximum: 1.0 The polygon fully occludes reverb (reverb reflections will be silent through this polygon)

Returns:

  • (Float)


293
294
295
296
297
298
# File 'lib/fmod/geometry.rb', line 293

def reverb_occlusion
  occlusion = "\0" * Fiddle::SIZEOF_FLOAT
  FMOD.invoke(:Geometry_GetPolygonAttributes, @geometry, @index,
              nil, occlusion, nil)
  occlusion.unpack1('f')
end

Instance Method Details

#[](index) ⇒ Vector

Retrieves the vertex of the polygon at the specified index.

Parameters:

  • index (Integer)

    The index of the vertex to retrieve.

Returns:



342
343
344
345
346
347
# File 'lib/fmod/geometry.rb', line 342

def [](index)
  return nil unless index.between?(0, vertex_count - 1)
  vertex = Vector.zero
  FMOD.invoke(:Geometry_GetPolygonVertex, @geometry, @index, index, vertex)
  vertex
end

#[]=(index, vertex) ⇒ Vector

Sets the vertex of the polygon at the specified index.

Parameters:

  • index (Integer)

    The index of the vertex to set.

  • vertex (Vector)

    The vertex to set.

Returns:



354
355
356
357
358
359
360
361
# File 'lib/fmod/geometry.rb', line 354

def []=(index, vertex)
  unless index.between?(0, vertex_count - 1)
    message = "Index #{index} outside of bounds: 0...#{vertex.count}"
    raise IndexError, message
  end
  FMOD.type?(vertex, Vector)
  FMOD.invoke(:Geometry_SetPolygonVertex, @geometry, @index, index, vertex)
end

#each {|vertex| ... } ⇒ self #eachEnumerator

Overloads:

  • #each {|vertex| ... } ⇒ self

    When called with a block, yields each vertex in turn before returning self.

    Yields:

    • (vertex)

      Yields a vertex to the block.

    Yield Parameters:

    • vertex (Vector)

      The enumerated vertex.

    Returns:

    • (self)
  • #eachEnumerator

    Returns an Enumerator for the polygon.

    Returns:

    • (Enumerator)


373
374
375
376
377
# File 'lib/fmod/geometry.rb', line 373

def each
  return to_enum(:each) unless block_given?
  (0...vertex_count).each { |i| yield self[i] }
  self
end

#vertex_countInteger Also known as: size

Retrieves the number of vertices within the polygon.

Returns:

  • (Integer)


330
331
332
333
334
# File 'lib/fmod/geometry.rb', line 330

def vertex_count
  count = "\0" * Fiddle::SIZEOF_INT
  FMOD.invoke(:Geometry_GetPolygonNumVertices, @geometry, @index, count)
  count.unpack1('l')
end

#verticesArray<Vector>

Retrieves an array of the vertices within the polygon.

Returns:



382
383
384
# File 'lib/fmod/geometry.rb', line 382

def vertices
  (0...vertex_count).map { |i| self[i] }
end