update Transform2D and switch matrix4x4 to matrix3x2

generics
Evan Hemsley 2020-01-01 23:08:14 -08:00
parent d553c2e213
commit bf7a97af20
6 changed files with 56 additions and 54 deletions

View File

@ -49,14 +49,13 @@ namespace MoonTools.Core.Bonk
Max = max;
}
private static Matrix4x4 AbsoluteMatrix(Matrix4x4 matrix)
private static Matrix3x2 AbsoluteMatrix(Matrix3x2 matrix)
{
return new Matrix4x4
return new Matrix3x2
(
Math.Abs(matrix.M11), Math.Abs(matrix.M12), Math.Abs(matrix.M13), Math.Abs(matrix.M14),
Math.Abs(matrix.M21), Math.Abs(matrix.M22), Math.Abs(matrix.M23), Math.Abs(matrix.M24),
Math.Abs(matrix.M31), Math.Abs(matrix.M32), Math.Abs(matrix.M33), Math.Abs(matrix.M34),
Math.Abs(matrix.M41), Math.Abs(matrix.M42), Math.Abs(matrix.M43), Math.Abs(matrix.M44)
Math.Abs(matrix.M11), Math.Abs(matrix.M12),
Math.Abs(matrix.M21), Math.Abs(matrix.M22),
Math.Abs(matrix.M31), Math.Abs(matrix.M32)
);
}

View File

@ -20,8 +20,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MoonTools.Core.Structs" Version="2.1.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
<PackageReference Include="MoonTools.Core.Structs" Version="3.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
</ItemGroup>

View File

@ -59,13 +59,13 @@ namespace MoonTools.Core.Bonk
/// </summary>
public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, IShape2D shape, Transform2D transform2D)
{
AABB box = shape.TransformedAABB(transform2D);
var box = shape.TransformedAABB(transform2D);
var minHash = Hash(box.Min);
var maxHash = Hash(box.Max);
for (int i = minHash.Item1; i <= maxHash.Item1; i++)
for (var i = minHash.Item1; i <= maxHash.Item1; i++)
{
for (int j = minHash.Item2; j <= maxHash.Item2; j++)
for (var j = minHash.Item2; j <= maxHash.Item2; j++)
{
var key = MakeLong(i, j);
if (hashDictionary.ContainsKey(key))

View File

@ -1,47 +1,50 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Numerics;
using MoonTools.Core.Structs;
internal unsafe struct SimplexVertexBuffer
namespace MoonTools.Core.Bonk
{
private const int Size = 35;
public int Length { get; private set; }
public SimplexVertexBuffer(IEnumerable<Position2D> positions)
internal unsafe struct SimplexVertexBuffer
{
var i = 0;
foreach (var position in positions)
{
if (i == Size) { break; }
var vertex = position.ToVector2();
_simplexXBuffer[i] = vertex.X;
_simplexYBuffer[i] = vertex.Y;
i++;
}
Length = i;
}
private const int Size = 35;
public Vector2 this[int key]
{
get => new Vector2(_simplexXBuffer[key], _simplexYBuffer[key]);
private set
{
_simplexXBuffer[key] = value.X;
_simplexYBuffer[key] = value.Y;
}
}
public int Length { get; private set; }
public void Insert(int index, Vector2 value)
{
for (var i = Length; i > index; i--)
public SimplexVertexBuffer(IEnumerable<Position2D> positions)
{
this[i] = this[i - 1];
var i = 0;
foreach (var position in positions)
{
if (i == Size) { break; }
var vertex = position.ToVector2();
_simplexXBuffer[i] = vertex.X;
_simplexYBuffer[i] = vertex.Y;
i++;
}
Length = i;
}
this[index] = value;
Length++;
}
private fixed float _simplexXBuffer[Size];
private fixed float _simplexYBuffer[Size];
public Vector2 this[int key]
{
get => new Vector2(_simplexXBuffer[key], _simplexYBuffer[key]);
private set
{
_simplexXBuffer[key] = value.X;
_simplexYBuffer[key] = value.Y;
}
}
public void Insert(int index, Vector2 value)
{
for (var i = Length; i > index; i--)
{
this[i] = this[i - 1];
}
this[index] = value;
Length++;
}
private fixed float _simplexXBuffer[Size];
private fixed float _simplexYBuffer[Size];
}
}

View File

@ -79,8 +79,8 @@ namespace MoonTools.Core.Bonk
public Vector2 Support(Vector2 direction, Transform2D transform)
{
Matrix4x4 inverseTransform;
Matrix4x4.Invert(transform.TransformMatrix, out inverseTransform);
Matrix3x2 inverseTransform;
Matrix3x2.Invert(transform.TransformMatrix, out inverseTransform);
var inverseDirection = Vector2.TransformNormal(direction, inverseTransform);
return Vector2.Transform(Support(inverseDirection), transform.TransformMatrix);
}

View File

@ -4,12 +4,12 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
<PackageReference Include="FluentAssertions" Version="5.9.0"/>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bonk\Bonk.csproj"/>
<ProjectReference Include="..\Bonk\Bonk.csproj" />
</ItemGroup>
</Project>