SoundSource3D.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (c) 2008-2017 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 Atomic
  25. {
  26. class Audio;
  27. /// %Sound source component with three-dimensional position.
  28. class ATOMIC_API SoundSource3D : public SoundSource
  29. {
  30. ATOMIC_OBJECT(SoundSource3D, SoundSource);
  31. public:
  32. /// Construct.
  33. SoundSource3D(Context* context);
  34. /// Register object factory.
  35. static void RegisterObject(Context* context);
  36. /// Visualize the component as debug geometry.
  37. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  38. /// Update sound source.
  39. virtual void Update(float timeStep);
  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. void SetNearDistance(float distance);
  46. /// Set far distance. Outside this range sound will be completely attenuated.
  47. void SetFarDistance(float distance);
  48. /// Set inner angle in degrees. Inside this angle sound will not be attenuated.By default 360, meaning direction never has an effect.
  49. void SetInnerAngle(float angle);
  50. /// Set outer angle in degrees. Outside this angle sound will be completely attenuated. By default 360, meaning direction never has an effect.
  51. void SetOuterAngle(float angle);
  52. /// Set rolloff power factor, defines attenuation function shape.
  53. void SetRolloffFactor(float factor);
  54. /// Calculate attenuation and panning based on current position and listener position.
  55. void CalculateAttenuation();
  56. /// Return near distance.
  57. float GetNearDistance() const { return nearDistance_; }
  58. /// Return far distance.
  59. float GetFarDistance() const { return farDistance_; }
  60. /// Return inner angle in degrees.
  61. float GetInnerAngle() const { return innerAngle_; }
  62. /// Return outer angle in degrees.
  63. float GetOuterAngle() const { return outerAngle_; }
  64. /// Return rolloff power factor.
  65. float RollAngleoffFactor() const { return rolloffFactor_; }
  66. protected:
  67. /// Near distance.
  68. float nearDistance_;
  69. /// Far distance.
  70. float farDistance_;
  71. /// Inner angle for directional attenuation.
  72. float innerAngle_;
  73. /// Outer angle for directional attenuation.
  74. float outerAngle_;
  75. /// Rolloff power factor.
  76. float rolloffFactor_;
  77. };
  78. }