-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from NoiseStudio/feature/311/simple-rigidbody…
…-and-sphere-collider Simple rigidbody and sphere collider
- Loading branch information
Showing
56 changed files
with
1,546 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using NoiseEngine.Jobs; | ||
using System; | ||
|
||
namespace NoiseEngine.Tests.Jobs; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using NoiseEngine.Jobs; | ||
|
||
namespace NoiseEngine.Tests.Jobs; | ||
|
||
internal record struct MockComponentG(float ValueA, bool ValueB, int ValueC) : IComponent { | ||
|
||
public static MockComponentG TestValueA => new MockComponentG(114.114f, true, 456373525); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using NoiseEngine.Mathematics; | ||
using System; | ||
using System.Numerics; | ||
|
||
namespace NoiseEngine.Tests.Mathematics; | ||
|
||
public class Matrix3x3Test { | ||
|
||
[Theory] | ||
[InlineData(new float[] { 2, 2, 1, -3, 0, 4, 1, -1, 5 }, 49)] | ||
[InlineData(new float[] { 4, 6, 5, 2, 1, 3, 7, 9, 8 }, 9)] | ||
public void Determinant(float[] init, float expected) { | ||
Matrix3x3<float> matrix = FromSpan<float>(init); | ||
Assert.Equal(expected, matrix.Determinant()); | ||
} | ||
|
||
[Theory] | ||
[InlineData( | ||
new float[] { 1, 2, -1, 2, 1, 2, -1, 2, 1 }, | ||
new float[] { 3f / 16f, 1f / 4f, -5f / 16f, 1f / 4f, 0f, 1f / 4f, -5f / 16f, 1f / 4f, 3 / 16f } | ||
)] | ||
[InlineData( | ||
new float[] { 4, 6, 5, 2, 1, 3, 7, 9, 8 }, | ||
new float[] { -19f / 9f, -1f / 3f, 13f / 9f, 5f / 9f, -1f / 3f, -2f / 9f, 11f / 9f, 2f / 3f, -8f / 9f } | ||
)] | ||
public void TryInvert(float[] init, float[]? expected) { | ||
Matrix3x3<float> matrix = FromSpan<float>(init); | ||
if (expected is null) { | ||
Assert.False(matrix.TryInvert(out _)); | ||
} else { | ||
Assert.True(matrix.TryInvert(out Matrix3x3<float> invertedMatrix)); | ||
Assert.Equal(FromSpan<float>(expected), invertedMatrix); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData( | ||
new float[] { 3, 7, 12, 5, 8, 15, 6, 9, 12 }, | ||
new float[] { 1, 4, 7 }, | ||
new float[] { 65, 102, 156 } | ||
)] | ||
public void MultipleByVector3(float[] init, float[] vector, float[] expected) { | ||
Matrix3x3<float> matrix = FromSpan<float>(init); | ||
Assert.Equal(Vector3FromSpan<float>(expected), matrix * Vector3FromSpan<float>(vector)); | ||
} | ||
|
||
private Matrix3x3<T> FromSpan<T>(ReadOnlySpan<T> data) where T : INumber<T> { | ||
return new Matrix3x3<T>( | ||
new Vector3<T>(data[0], data[1], data[2]), | ||
new Vector3<T>(data[3], data[4], data[5]), | ||
new Vector3<T>(data[6], data[7], data[8]) | ||
); | ||
} | ||
|
||
private Vector3<T> Vector3FromSpan<T>(ReadOnlySpan<T> data) where T : INumber<T> { | ||
return new Vector3<T>(data[0], data[1], data[2]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using NoiseEngine.Components; | ||
using NoiseEngine.DeveloperTools.Systems; | ||
using NoiseEngine.Mathematics; | ||
using NoiseEngine.Physics; | ||
using NoiseEngine.Tests.Environments; | ||
using NoiseEngine.Tests.Fixtures; | ||
using System.Threading; | ||
|
||
namespace NoiseEngine.Tests.Physics; | ||
|
||
public class PhysicsTest : ApplicationTestEnvironment { | ||
|
||
public PhysicsTest(ApplicationFixture fixture) : base(fixture) { | ||
} | ||
|
||
/*[FactRequire(TestRequirements.Graphics | TestRequirements.Gui)] | ||
public void SimpleScene() { | ||
ApplicationScene scene = new ApplicationScene(); | ||
Window window = Fixture.GetWindow("Physics!"); | ||
Camera camera = new Camera(scene) { | ||
RenderTarget = window, | ||
RenderLoop = new PerformanceRenderLoop() | ||
}; | ||
scene.AddFrameDependentSystem(new PhysicsTestActivatorSystem(scene, window)); | ||
scene.Spawn( | ||
new TransformComponent( | ||
new Vector3<float>(0, -105, 0), Quaternion<float>.Identity, new Vector3<float>(200, 200, 200) | ||
), | ||
new MeshRendererComponent(scene.Primitive.GetSphereMesh(), scene.Primitive.DefaultMaterial), | ||
new ColliderComponent(new SphereCollider()) | ||
); | ||
for (int x = 0; x < 1; x += 2) { | ||
for (int y = 0; y < 40; y += 2) { | ||
for (int z = 0; z < 1; z += 2) { | ||
scene.Spawn( | ||
new TransformComponent(new Vector3<float>(x, y * 3 + 4.5f, z)), | ||
new MeshRendererComponent(scene.Primitive.GetSphereMesh(), scene.Primitive.DefaultMaterial), | ||
new RigidBodyComponent(), | ||
new ColliderComponent(new SphereCollider()) | ||
); | ||
} | ||
} | ||
} | ||
DebugMovementSystem.InitializeTo(camera); | ||
while (!window.IsDisposed) | ||
Thread.Sleep(10); | ||
}*/ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using NoiseEngine.Components; | ||
using NoiseEngine.Inputs; | ||
using NoiseEngine.Jobs; | ||
using NoiseEngine.Mathematics; | ||
using NoiseEngine.Physics; | ||
using NoiseEngine.Physics.Collision; | ||
using NoiseEngine.Physics.FrameSmoothing; | ||
using NoiseEngine.Physics.Internal; | ||
using NoiseEngine.Physics.Simulation; | ||
using System; | ||
|
||
namespace NoiseEngine.Tests.Physics; | ||
|
||
internal partial class PhysicsTestActivatorSystem : EntitySystem { | ||
|
||
private readonly ApplicationScene scene; | ||
private readonly Window window; | ||
|
||
public PhysicsTestActivatorSystem(ApplicationScene scene, Window window) { | ||
this.scene = scene; | ||
this.window = window; | ||
} | ||
|
||
protected override void OnUpdate() { | ||
if (!window.Input.Pressed(Key.F1)) | ||
return; | ||
Enabled = false; | ||
|
||
scene.Primitive.CreateCube( | ||
new Vector3<float>(0, 0, 15), | ||
Quaternion.EulerDegrees(new Vector3<float>(0, 90, 0)), | ||
new Vector3<float>(10, 10, 10) | ||
); | ||
|
||
scene.AddFrameDependentSystem(new RigidBodyFrameSmoothingSystem()); | ||
double cycleTime = 20; | ||
CollisionSpace space = new CollisionSpace(); | ||
ContactPointsBuffer contactPoints = new ContactPointsBuffer(); | ||
|
||
SimulationSystem simulationSystem = new SimulationSystem(space); | ||
CollisionDetectionSystem collisionDetectionSystem = new CollisionDetectionSystem(space, contactPoints); | ||
CollisionResolveSystem collisionResolveSystem = new CollisionResolveSystem(contactPoints); | ||
ImmovableColliderRegisterSystem immovableColliderRegisterSystem = new ImmovableColliderRegisterSystem(space); | ||
|
||
simulationSystem.AddDependency(collisionResolveSystem); | ||
immovableColliderRegisterSystem.AddDependency(collisionDetectionSystem); | ||
|
||
collisionDetectionSystem.AddDependency(simulationSystem); | ||
collisionDetectionSystem.AddDependency(immovableColliderRegisterSystem); | ||
|
||
collisionResolveSystem.AddDependency(collisionDetectionSystem); | ||
|
||
scene.AddSystem(simulationSystem, cycleTime); | ||
scene.AddSystem(immovableColliderRegisterSystem, cycleTime); | ||
scene.AddSystem(collisionDetectionSystem, cycleTime); | ||
scene.AddSystem(collisionResolveSystem, cycleTime); | ||
|
||
RigidBodyInitializerSystem initalizer = new RigidBodyInitializerSystem(); | ||
scene.AddSystem(initalizer, cycleTime); | ||
} | ||
|
||
private void OnUpdateEntity() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.