diff --git a/MLEM/Misc/SoundEffectInfo.cs b/MLEM/Misc/SoundEffectInfo.cs index 4ec3632..1dc99a7 100644 --- a/MLEM/Misc/SoundEffectInfo.cs +++ b/MLEM/Misc/SoundEffectInfo.cs @@ -1,9 +1,10 @@ +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; namespace MLEM.Misc { /// /// A sound effect info is a wrapper around that additionally stores , and information. - /// Additionally, a can be created using . + /// Additionally, a can be created using and a 3D sound can be played using . /// public class SoundEffectInfo { @@ -24,6 +25,8 @@ namespace MLEM.Misc { /// public float Pan; + private AudioEmitter emitter; + /// /// Creates a new sound effect info with the given values. /// @@ -46,6 +49,30 @@ namespace MLEM.Misc { return this.Sound.Play(this.Volume, this.Pitch, this.Pan); } + /// + /// Plays this info's once, with 3d positioning applied, to the given . + /// The required is automatically created and cached for future use. + /// + /// Data about the listener + /// The position to play the sound at + /// The emitter's doppler scale, defaults to 1 + /// The emitter's forward vector, defaults to + /// The emitter's up vector, defaults to + /// The emitter's velocity, defaults to + public void Play3D(AudioListener listener, Vector3 pos, float? dopplerScale = null, Vector3? forward = null, Vector3? up = null, Vector3? velocity = null) { + if (this.emitter == null) + this.emitter = new AudioEmitter(); + this.emitter.Position = pos; + this.emitter.DopplerScale = dopplerScale ?? 1; + this.emitter.Forward = forward ?? Vector3.Forward; + this.emitter.Up = up ?? Vector3.Up; + this.emitter.Velocity = velocity ?? Vector3.Zero; + + var inst = this.CreateInstance(); + inst.Apply3D(listener, this.emitter); + inst.Play(); + } + /// /// Creates a new with this sound effect info's data. ///