Cover Box3D world-step semantics
This commit is contained in:
parent
34366604be
commit
0ffad2a4f0
6 changed files with 226 additions and 9 deletions
|
|
@ -40,6 +40,18 @@ internal static partial class Box3DOracle
|
|||
float bodyY,
|
||||
float bodyRadius,
|
||||
int canEncroach);
|
||||
|
||||
[LibraryImport(LibraryName)]
|
||||
internal static partial void ymir_box3d_step_pair(
|
||||
in Box3DBodyInput bodyA,
|
||||
in Box3DBodyInput bodyB,
|
||||
float timeStep,
|
||||
int subStepCount,
|
||||
float restitutionThreshold,
|
||||
out Box3DPairStepResult result);
|
||||
|
||||
[LibraryImport(LibraryName)]
|
||||
internal static partial Box3DTorqueResult ymir_box3d_torque_lifetime(float torque, float timeStep, int subStepCount);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
@ -58,3 +70,35 @@ internal readonly record struct Box3DCastResult(
|
|||
{
|
||||
public bool IsHit => Hit != 0;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly record struct Box3DBodyInput(
|
||||
float PositionX,
|
||||
float PositionY,
|
||||
float VelocityX,
|
||||
float VelocityY,
|
||||
float Radius,
|
||||
float Mass,
|
||||
float Restitution,
|
||||
int IsStatic);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly record struct Box3DBodyOutput(
|
||||
float PositionX,
|
||||
float PositionY,
|
||||
float VelocityX,
|
||||
float VelocityY,
|
||||
float AngularVelocity);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly record struct Box3DPairStepResult(
|
||||
Box3DBodyOutput BodyA,
|
||||
Box3DBodyOutput BodyB,
|
||||
int BeginContactCount,
|
||||
int EndContactCount,
|
||||
int HitContactCount);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly record struct Box3DTorqueResult(
|
||||
float AngularVelocityAfterAppliedStep,
|
||||
float AngularVelocityAfterUnforcedStep);
|
||||
|
|
|
|||
|
|
@ -83,4 +83,41 @@ public sealed class Box3DParityTests
|
|||
|
||||
Assert.True(result.IsHit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PairStepEmitsBeginContactAndSeparatesOverlappingSpheres()
|
||||
{
|
||||
var bodyA = new Box3DBodyInput(-0.9f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0);
|
||||
var bodyB = new Box3DBodyInput(0.9f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0);
|
||||
|
||||
Box3DOracle.ymir_box3d_step_pair(in bodyA, in bodyB, 1.0f / 60.0f, 4, 0.0f, out var result);
|
||||
|
||||
Assert.Equal(1, result.BeginContactCount);
|
||||
Assert.True(result.BodyA.PositionX < -0.9f);
|
||||
Assert.True(result.BodyB.PositionX > 0.9f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PairStepUsesMaximumRestitution()
|
||||
{
|
||||
var bodyA = new Box3DBodyInput(-1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.1f, 0);
|
||||
var bodyB = new Box3DBodyInput(1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.8f, 0);
|
||||
|
||||
Box3DOracle.ymir_box3d_step_pair(in bodyA, in bodyB, 1.0f / 60.0f, 4, 0.0f, out var result);
|
||||
|
||||
Assert.True(result.BodyA.VelocityX < -0.7f);
|
||||
Assert.True(result.BodyB.VelocityX > 0.7f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TorqueIsClearedAfterEachWorldStep()
|
||||
{
|
||||
var result = Box3DOracle.ymir_box3d_torque_lifetime(0.4f, 0.1f, 4);
|
||||
|
||||
Assert.True(result.AngularVelocityAfterAppliedStep > 0.0f);
|
||||
Assert.Equal(
|
||||
result.AngularVelocityAfterAppliedStep,
|
||||
result.AngularVelocityAfterUnforcedStep,
|
||||
precision: 5);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
<IsPackable>false</IsPackable>
|
||||
<NativeSourceDir>$(MSBuildThisFileDirectory)..\..\native\Ymir.Box3D</NativeSourceDir>
|
||||
<NativeBuildDir>$(MSBuildThisFileDirectory)..\..\artifacts\box3d-native\$(Configuration)</NativeBuildDir>
|
||||
<CMakeExe Condition="'$(OS)' == 'Windows_NT'">C:\Program Files\CMake\bin\cmake.exe</CMakeExe>
|
||||
<CMakeExe Condition="'$(OS)' != 'Windows_NT'">cmake</CMakeExe>
|
||||
<CMakeExe Condition="'$(CMakeExe)' == '' and '$(OS)' == 'Windows_NT' and Exists('C:\Program Files\CMake\bin\cmake.exe')">C:\Program Files\CMake\bin\cmake.exe</CMakeExe>
|
||||
<CMakeExe Condition="'$(CMakeExe)' == ''">cmake</CMakeExe>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue