|
| 1 | +using BepuUtilities; |
| 2 | +using DemoRenderer; |
| 3 | +using BepuPhysics; |
| 4 | +using BepuPhysics.Collidables; |
| 5 | +using System; |
| 6 | +using System.Numerics; |
| 7 | +using BepuUtilities.Collections; |
| 8 | +using DemoContentLoader; |
| 9 | +using BepuPhysics.Constraints; |
| 10 | +using DemoUtilities; |
| 11 | + |
| 12 | +namespace Demos.SpecializedTests; |
| 13 | + |
| 14 | +public class StaggeredDropTestDemo : Demo |
| 15 | +{ |
| 16 | + public override void Initialize(ContentArchive content, Camera camera) |
| 17 | + { |
| 18 | + camera.Position = new Vector3(-30, 10, -30); |
| 19 | + //camera.Yaw = MathHelper.Pi ; |
| 20 | + camera.Yaw = MathHelper.Pi * 3f / 4; |
| 21 | + //camera.Pitch = MathHelper.PiOver2 * 0.999f; |
| 22 | + Simulation = Simulation.Create(BufferPool, new DemoNarrowPhaseCallbacks(new SpringSettings(30, 1)), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new SolveDescription(4, 1)); |
| 23 | + |
| 24 | + var box = new Box(1f, 3f, 2f); |
| 25 | + |
| 26 | + var boxInertia = box.ComputeInertia(1); |
| 27 | + var boxIndex = Simulation.Shapes.Add(box); |
| 28 | + const int width = 256; |
| 29 | + const int height = 1; |
| 30 | + const int length = 256; |
| 31 | + var shapeCount = 0; |
| 32 | + var random = new Random(5); |
| 33 | + for (int i = 0; i < width; ++i) |
| 34 | + { |
| 35 | + for (int j = 0; j < height; ++j) |
| 36 | + { |
| 37 | + for (int k = 0; k < length; ++k) |
| 38 | + { |
| 39 | + var location = new Vector3(6, 3, 6) * new Vector3(i, j, k) + new Vector3(-width * 3, 5.5f + random.NextSingle() * 5, -length * 3); |
| 40 | + var bodyDescription = BodyDescription.CreateDynamic(location, boxInertia, boxIndex, -0.01f); |
| 41 | + var index = shapeCount++; |
| 42 | + Simulation.Bodies.Add(bodyDescription); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(new Box(5000, 1, 5000)))); |
| 48 | + //var mesh = DemoMeshHelper.CreateDeformedPlane(128, 128, (x, y) => new Vector3(x - 64, 2f * (float)(Math.Sin(x * 0.5f) * Math.Sin(y * 0.5f)), y - 64), new Vector3(4, 1, 4), BufferPool); |
| 49 | + //Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(mesh))); |
| 50 | + } |
| 51 | + |
| 52 | + double time = 0; |
| 53 | + long frameCount = 0; |
| 54 | + public override void Update(Window window, Camera camera, Input input, float dt) |
| 55 | + { |
| 56 | + base.Update(window, camera, input, dt); |
| 57 | + const long minimumFrameToMeasure = 512; |
| 58 | + frameCount++; |
| 59 | + if (frameCount >= minimumFrameToMeasure) |
| 60 | + { |
| 61 | + var frameTime = Simulation.Profiler[Simulation.BroadPhaseOverlapFinder]; |
| 62 | + time += frameTime; |
| 63 | + Console.WriteLine($"coldet time (ms): {1e3 * frameTime}, average (ms): {1e3 * time / (frameCount - minimumFrameToMeasure)}"); |
| 64 | + } |
| 65 | + |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
0 commit comments