Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
cosmonaut | 3db1fee4d0 | |
cosmonaut | f1120a2572 | |
cosmonaut | 1a14f2595a |
|
@ -6,7 +6,7 @@ namespace MoonTools.Curve
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A 3-dimensional Bezier curve defined by 4 points.
|
/// A 3-dimensional Bezier curve defined by 4 points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct CubicBezierCurve3D : IEquatable<CubicBezierCurve3D>
|
public struct CubicBezierCurve3D : IEquatable<CubicBezierCurve3D>, ICurve3D
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The start point.
|
/// The start point.
|
||||||
|
|
|
@ -13,13 +13,15 @@
|
||||||
<AssemblyName>MoonTools.Curve</AssemblyName>
|
<AssemblyName>MoonTools.Curve</AssemblyName>
|
||||||
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
|
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
|
||||||
<PackageProjectUrl>https://gitea.moonside.games/MoonsideGames/MoonTools.Curve</PackageProjectUrl>
|
<PackageProjectUrl>https://gitea.moonside.games/MoonsideGames/MoonTools.Curve</PackageProjectUrl>
|
||||||
|
<Platforms>x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
|
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0"/>
|
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
|
||||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0"/>
|
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
|
||||||
|
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace MoonTools.Curve
|
||||||
|
{
|
||||||
|
public interface ICurve3D
|
||||||
|
{
|
||||||
|
Vector3 Point(float t, float startTime, float endTime);
|
||||||
|
Vector3 Velocity(float t, float startTime, float endTime);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ namespace MoonTools.Curve
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A 3-dimensional Bezier curve defined by 3 points.
|
/// A 3-dimensional Bezier curve defined by 3 points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct QuadraticBezierCurve3D : IEquatable<QuadraticBezierCurve3D>
|
public struct QuadraticBezierCurve3D : IEquatable<QuadraticBezierCurve3D>, ICurve3D
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The start point.
|
/// The start point.
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace MoonTools.Curve
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A concatenation of 3D curves with time values.
|
||||||
|
/// </summary>
|
||||||
|
public struct SplineCurve3D
|
||||||
|
{
|
||||||
|
private ICurve3D[] Curves { get; }
|
||||||
|
private float[] Times { get; }
|
||||||
|
public float TotalTime { get; }
|
||||||
|
public bool Loop { get; }
|
||||||
|
|
||||||
|
public SplineCurve3D(ICurve3D[] curves, float[] times, bool loop = false)
|
||||||
|
{
|
||||||
|
TotalTime = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < times.Length; i++)
|
||||||
|
{
|
||||||
|
TotalTime += times[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Curves = curves;
|
||||||
|
Times = times;
|
||||||
|
Loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 Point(float t)
|
||||||
|
{
|
||||||
|
if (!Loop && t >= TotalTime)
|
||||||
|
{
|
||||||
|
var lastIndex = Curves.Length - 1;
|
||||||
|
return Curves[lastIndex].Point(Times[lastIndex], 0, Times[lastIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
t %= TotalTime;
|
||||||
|
|
||||||
|
var index = 0;
|
||||||
|
var startTime = 0f;
|
||||||
|
var incrementalTime = 0f;
|
||||||
|
|
||||||
|
for (int i = 0; i < Times.Length; i++)
|
||||||
|
{
|
||||||
|
incrementalTime += Times[i];
|
||||||
|
|
||||||
|
if (t < incrementalTime)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
startTime = incrementalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Curves[index].Point(t - startTime, 0, Times[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue