Class: SFML::SoundCone

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/audio/sound_cone.rb

Overview

Directional-attenuation cone for a 3D sound source. Inside the inner_angle cone the sound plays at full volume; outside the outer_angle cone it's attenuated by outer_gain; between the two it's smoothly interpolated.

Angles are in degrees, measured from the source's direction axis. outer_gain is a scalar in [0, 1] (0 = silent outside).

sound.direction = [0, 0, -1]
sound.cone = SFML::SoundCone.new(
inner_angle: 30, outer_angle: 90, outer_gain: 0.2,
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inner_angle:, outer_angle:, outer_gain:) ⇒ SoundCone

Returns a new instance of SoundCone.



18
19
20
21
22
23
# File 'lib/sfml/audio/sound_cone.rb', line 18

def initialize(inner_angle:, outer_angle:, outer_gain:)
  @inner_angle = inner_angle.to_f
  @outer_angle = outer_angle.to_f
  @outer_gain  = outer_gain.to_f
  freeze
end

Instance Attribute Details

#inner_angle ⇒ Object (readonly)

The inner angle, outer angle, outer gain components.



16
17
18
# File 'lib/sfml/audio/sound_cone.rb', line 16

def inner_angle
  @inner_angle
end

#outer_angle ⇒ Object (readonly)

The inner angle, outer angle, outer gain components.



16
17
18
# File 'lib/sfml/audio/sound_cone.rb', line 16

def outer_angle
  @outer_angle
end

#outer_gain ⇒ Object (readonly)

The inner angle, outer angle, outer gain components.



16
17
18
# File 'lib/sfml/audio/sound_cone.rb', line 16

def outer_gain
  @outer_gain
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



25
26
27
28
29
30
# File 'lib/sfml/audio/sound_cone.rb', line 25

def ==(other)
  other.is_a?(SoundCone) &&
    inner_angle == other.inner_angle &&
    outer_angle == other.outer_angle &&
    outer_gain  == other.outer_gain
end

#hash ⇒ Object

Returns the hash.



33
# File 'lib/sfml/audio/sound_cone.rb', line 33

def hash = [inner_angle, outer_angle, outer_gain].hash

#to_s ⇒ Object Also known as: inspect

Returns the to s.



36
37
38
# File 'lib/sfml/audio/sound_cone.rb', line 36

def to_s
  "SoundCone(inner=#{inner_angle}°, outer=#{outer_angle}°, outer_gain=#{outer_gain})"
end