qstbak/Auspex/Auspex/AxAngularGradient.cs
2026-08-17 20:25:32 +10:00

33 lines
889 B
C#

using System;
using System.Numerics;
using Auspex.Rendering.Direct3D;
namespace Auspex;
public readonly struct AxAngularGradient : IPctGradient
{
private readonly Vector3 _center;
private readonly float _minAngle;
private readonly float _invRange;
private readonly Vector4 _colorStart;
private readonly Vector4 _colorEnd;
public AxAngularGradient(Vector3 center, uint colorStart, uint colorEnd, float minAngle = 0f, float maxAngle = (float)Math.PI * 2f)
{
_center = center;
_minAngle = minAngle;
_invRange = 1f / (maxAngle - minAngle);
_colorStart = colorStart.ToVector4();
_colorEnd = colorEnd.ToVector4();
}
public uint ColorAt(Vector3 point)
{
float amount = Math.Clamp((MathF.Atan2(point.Z - _center.Z, point.X - _center.X) - (float)Math.PI / 2f - _minAngle) * _invRange % 1f, 0f, 1f);
return Vector4.Lerp(_colorStart, _colorEnd, amount).ToUint();
}
}