namespace Otter { /// /// Component that controls a sine wave. Can be useful for special effects and such. /// public class SineWave : Component { #region Public Fields /// /// The rate at which the sine wave moves. /// public float Rate; /// /// The amplitude of the sine wave. When not zero Min and Max are ignored. /// public float Amplitude; /// /// The offset of the value processed. /// public float Offset; /// /// The minimum value of the wave. /// public float Min; /// /// The maximum value of the wave. /// public float Max; #endregion #region Public Properties /// /// The current value of the wave. /// public float Value { get { if (Amplitude == 0) { return Util.SinScaleClamp((Timer + Offset) * Rate, Min, Max); } else { return Util.Sin((Timer + Offset) * Rate) * Amplitude; } } } #endregion #region Constructors /// /// Create a new SineWave. /// /// The rate of the wave. /// The amplitude of the wave. /// The offset of the value processed. public SineWave(float rate = 1, float amp = 1, float offset = 0) { Rate = rate; Amplitude = amp; Offset = offset; } /// /// Create a new SineWave. /// /// The rate of the wave. /// The minimum value of the wave. /// The maximum value of the wave. /// The offset of the value processed. public SineWave(float rate = 1, float min = -1, float max = 1, float offset = 0) { Rate = rate; Min = min; Max = max; Offset = offset; } #endregion #region Operators public static implicit operator float(SineWave s) { return s.Value; } public static implicit operator int(SineWave s) { return (int)s.Value; } #endregion } }