mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-16 10:19:18 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Contains a haptic pattern, which consists of frequency and amplitude values that can change over time.
|
|
/// </summary>
|
|
public partial record class HapticPattern( float Length, Curve FrequencyCurve, Curve AmplitudeCurve )
|
|
{
|
|
public float LengthScale = 1f;
|
|
public float FrequencyScale = 1f;
|
|
public float AmplitudeScale = 1f;
|
|
|
|
public int Position { get; private set; } = 0;
|
|
|
|
internal void Reset()
|
|
{
|
|
Position = 0;
|
|
|
|
LengthScale = 1f;
|
|
FrequencyScale = 1f;
|
|
AmplitudeScale = 1f;
|
|
}
|
|
|
|
internal void Update( out float amplitude, out float frequency )
|
|
{
|
|
frequency = 0f;
|
|
amplitude = 0f;
|
|
|
|
try
|
|
{
|
|
var length = Length * LengthScale * 1000f;
|
|
var time = Position / length;
|
|
|
|
if ( Position > length )
|
|
return;
|
|
|
|
GetValue( time, out frequency, out amplitude );
|
|
}
|
|
finally
|
|
{
|
|
Position += (int)(Time.Delta * 1000f);
|
|
}
|
|
}
|
|
|
|
public void GetValue( float t, out float frequency, out float amplitude )
|
|
{
|
|
frequency = FrequencyCurve.Evaluate( t ) * FrequencyScale;
|
|
amplitude = AmplitudeCurve.Evaluate( t ) * AmplitudeScale;
|
|
}
|
|
}
|