SoundSource3D.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Audio/SoundSource.h"
  24. namespace Urho3D
  25. {
  26. class Audio;
  27. /// %Sound source component with three-dimensional position.
  28. class URHO3D_API SoundSource3D : public SoundSource
  29. {
  30. URHO3D_OBJECT(SoundSource3D, SoundSource);
  31. public:
  32. /// Construct.
  33. explicit SoundSource3D(Context* context);
  34. /// Register object factory.
  35. static void RegisterObject(Context* context);
  36. /// Visualize the component as debug geometry.
  37. void DrawDebugGeometry(DebugRenderer* debug, bool depthTest) override;
  38. /// Update sound source.
  39. void Update(float timeStep) override;
  40. /// Set attenuation parameters.
  41. void SetDistanceAttenuation(float nearDistance, float farDistance, float rolloffFactor);
  42. /// Set angle attenuation parameters.
  43. void SetAngleAttenuation(float innerAngle, float outerAngle);
  44. /// Set near distance. Inside this range sound will not be attenuated.
  45. /// @property
  46. void SetNearDistance(float distance);
  47. /// Set far distance. Outside this range sound will be completely attenuated.
  48. /// @property
  49. void SetFarDistance(float distance);
  50. /// Set inner angle in degrees. Inside this angle sound will not be attenuated.By default 360, meaning direction never has an effect.
  51. /// @property
  52. void SetInnerAngle(float angle);
  53. /// Set outer angle in degrees. Outside this angle sound will be completely attenuated. By default 360, meaning direction never has an effect.
  54. /// @property
  55. void SetOuterAngle(float angle);
  56. /// Set rolloff power factor, defines attenuation function shape.
  57. /// @property
  58. void SetRolloffFactor(float factor);
  59. /// Calculate attenuation and panning based on current position and listener position.
  60. void CalculateAttenuation();
  61. /// Return near distance.
  62. /// @property
  63. float GetNearDistance() const { return nearDistance_; }
  64. /// Return far distance.
  65. /// @property
  66. float GetFarDistance() const { return farDistance_; }
  67. /// Return inner angle in degrees.
  68. /// @property
  69. float GetInnerAngle() const { return innerAngle_; }
  70. /// Return outer angle in degrees.
  71. /// @property
  72. float GetOuterAngle() const { return outerAngle_; }
  73. /// Return rolloff power factor.
  74. /// @property{get_rolloffFactor}
  75. float RollAngleoffFactor() const { return rolloffFactor_; }
  76. protected:
  77. /// Near distance.
  78. float nearDistance_;
  79. /// Far distance.
  80. float farDistance_;
  81. /// Inner angle for directional attenuation.
  82. float innerAngle_;
  83. /// Outer angle for directional attenuation.
  84. float outerAngle_;
  85. /// Rolloff power factor.
  86. float rolloffFactor_;
  87. };
  88. }