SoundSource3D.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Audio/SoundSource.h"
  5. namespace Urho3D
  6. {
  7. class Audio;
  8. /// %Sound source component with three-dimensional position.
  9. class URHO3D_API SoundSource3D : public SoundSource
  10. {
  11. URHO3D_OBJECT(SoundSource3D, SoundSource);
  12. public:
  13. /// Construct.
  14. explicit SoundSource3D(Context* context);
  15. /// Register object factory.
  16. /// @nobind
  17. static void RegisterObject(Context* context);
  18. /// Visualize the component as debug geometry.
  19. void DrawDebugGeometry(DebugRenderer* debug, bool depthTest) override;
  20. /// Update sound source.
  21. void Update(float timeStep) override;
  22. /// Set attenuation parameters.
  23. void SetDistanceAttenuation(float nearDistance, float farDistance, float rolloffFactor);
  24. /// Set angle attenuation parameters.
  25. void SetAngleAttenuation(float innerAngle, float outerAngle);
  26. /// Set near distance. Inside this range sound will not be attenuated.
  27. /// @property
  28. void SetNearDistance(float distance);
  29. /// Set far distance. Outside this range sound will be completely attenuated.
  30. /// @property
  31. void SetFarDistance(float distance);
  32. /// Set inner angle in degrees. Inside this angle sound will not be attenuated.By default 360, meaning direction never has an effect.
  33. /// @property
  34. void SetInnerAngle(float angle);
  35. /// Set outer angle in degrees. Outside this angle sound will be completely attenuated. By default 360, meaning direction never has an effect.
  36. /// @property
  37. void SetOuterAngle(float angle);
  38. /// Set rolloff power factor, defines attenuation function shape.
  39. /// @property
  40. void SetRolloffFactor(float factor);
  41. /// Calculate attenuation and panning based on current position and listener position.
  42. void CalculateAttenuation();
  43. /// Return near distance.
  44. /// @property
  45. float GetNearDistance() const { return nearDistance_; }
  46. /// Return far distance.
  47. /// @property
  48. float GetFarDistance() const { return farDistance_; }
  49. /// Return inner angle in degrees.
  50. /// @property
  51. float GetInnerAngle() const { return innerAngle_; }
  52. /// Return outer angle in degrees.
  53. /// @property
  54. float GetOuterAngle() const { return outerAngle_; }
  55. /// Return rolloff power factor.
  56. /// @property{get_rolloffFactor}
  57. float RollAngleoffFactor() const { return rolloffFactor_; }
  58. protected:
  59. /// Near distance.
  60. float nearDistance_;
  61. /// Far distance.
  62. float farDistance_;
  63. /// Inner angle for directional attenuation.
  64. float innerAngle_;
  65. /// Outer angle for directional attenuation.
  66. float outerAngle_;
  67. /// Rolloff power factor.
  68. float rolloffFactor_;
  69. };
  70. }