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.



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

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_angleObject (readonly)

Returns the value of attribute inner_angle.



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

def inner_angle
  @inner_angle
end

#outer_angleObject (readonly)

Returns the value of attribute outer_angle.



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

def outer_angle
  @outer_angle
end

#outer_gainObject (readonly)

Returns the value of attribute outer_gain.



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

def outer_gain
  @outer_gain
end

Instance Method Details

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



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

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

#hashObject



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

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

#to_sObject Also known as: inspect



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

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