From 3ad9c5ad3ba58b3cd4f19c07c6c89880908e0878 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 14 Apr 2024 15:56:47 +0200 Subject: feat: add a few more debug demos --- benchmarks2d/all_benchmarks2.rs | 2 ++ benchmarks2d/vertical_stacks2.rs | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 benchmarks2d/vertical_stacks2.rs (limited to 'benchmarks2d') diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs index fcc7b95..af71049 100644 --- a/benchmarks2d/all_benchmarks2.rs +++ b/benchmarks2d/all_benchmarks2.rs @@ -17,6 +17,7 @@ mod joint_ball2; mod joint_fixed2; mod joint_prismatic2; mod pyramid2; +mod vertical_stacks2; fn demo_name_from_command_line() -> Option { let mut args = std::env::args(); @@ -57,6 +58,7 @@ pub fn main() { ("Convex polygons", convex_polygons2::init_world), ("Heightfield", heightfield2::init_world), ("Pyramid", pyramid2::init_world), + ("Verticals tacks", vertical_stacks2::init_world), ("(Stress test) joint ball", joint_ball2::init_world), ("(Stress test) joint fixed", joint_fixed2::init_world), ( diff --git a/benchmarks2d/vertical_stacks2.rs b/benchmarks2d/vertical_stacks2.rs new file mode 100644 index 0000000..12de83a --- /dev/null +++ b/benchmarks2d/vertical_stacks2.rs @@ -0,0 +1,53 @@ +use rapier2d::prelude::*; +use rapier_testbed2d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let impulse_joints = ImpulseJointSet::new(); + let multibody_joints = MultibodyJointSet::new(); + + /* + * Ground + */ + let ground_size = 100.0; + let ground_thickness = 1.0; + + let rigid_body = RigidBodyBuilder::fixed(); + let ground_handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_thickness); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 30; + let rad = 0.5; + + let shift = rad * 2.0; + let centery = shift / 2.0 + ground_thickness; + + for i in 0..num { + for j in 0usize..1 + i * 2 { + let fj = j as f32; + let fi = i as f32; + let x = (fj - fi) * shift; // (shift + rad / 2.0); + let y = (num as f32 - fi - 1.0) * shift + centery; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(rad, rad); + colliders.insert_with_parent(collider, handle, &mut bodies); + } + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, impulse_joints, multibody_joints); + testbed.look_at(point![0.0, 2.5], 5.0); +} -- cgit From de5e871cd1a76d424c2fa49da776c14ddd6f533b Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 14 Apr 2024 18:59:08 +0200 Subject: chore: rework vertical stacks demo --- benchmarks2d/all_benchmarks2.rs | 2 +- benchmarks2d/vertical_stacks2.rs | 47 ++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 20 deletions(-) (limited to 'benchmarks2d') diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs index af71049..64ec802 100644 --- a/benchmarks2d/all_benchmarks2.rs +++ b/benchmarks2d/all_benchmarks2.rs @@ -58,7 +58,7 @@ pub fn main() { ("Convex polygons", convex_polygons2::init_world), ("Heightfield", heightfield2::init_world), ("Pyramid", pyramid2::init_world), - ("Verticals tacks", vertical_stacks2::init_world), + ("Verticals stacks", vertical_stacks2::init_world), ("(Stress test) joint ball", joint_ball2::init_world), ("(Stress test) joint fixed", joint_fixed2::init_world), ( diff --git a/benchmarks2d/vertical_stacks2.rs b/benchmarks2d/vertical_stacks2.rs index 12de83a..a415693 100644 --- a/benchmarks2d/vertical_stacks2.rs +++ b/benchmarks2d/vertical_stacks2.rs @@ -10,10 +10,14 @@ pub fn init_world(testbed: &mut Testbed) { let impulse_joints = ImpulseJointSet::new(); let multibody_joints = MultibodyJointSet::new(); + + let num = 40; + let rad = 50.0 / 2.0; // 0.5; + /* * Ground */ - let ground_size = 100.0; + let ground_size = num as f32 * rad * 10.0; let ground_thickness = 1.0; let rigid_body = RigidBodyBuilder::fixed(); @@ -24,24 +28,29 @@ pub fn init_world(testbed: &mut Testbed) { /* * Create the cubes */ - let num = 30; - let rad = 0.5; - - let shift = rad * 2.0; - let centery = shift / 2.0 + ground_thickness; - - for i in 0..num { - for j in 0usize..1 + i * 2 { - let fj = j as f32; - let fi = i as f32; - let x = (fj - fi) * shift; // (shift + rad / 2.0); - let y = (num as f32 - fi - 1.0) * shift + centery; - - // Build the rigid body. - let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]); - let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(rad, rad); - colliders.insert_with_parent(collider, handle, &mut bodies); + + let shiftx_centerx = [ + (rad * 2.0, -(num as f32) * rad * 2.0 * 1.5), + (rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5), + ]; + + for (shiftx, centerx) in shiftx_centerx { + let shifty = rad * 2.0; + let centery = shifty / 2.0 + ground_thickness; + + for i in 0..num { + for j in 0usize..1 + i * 2 { + let fj = j as f32; + let fi = i as f32; + let x = (fj - fi) * shiftx + centerx; + let y = (num as f32 - fi - 1.0) * shifty + centery; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(rad, rad); + colliders.insert_with_parent(collider, handle, &mut bodies); + } } } -- cgit From f58b4f7c195ab7acf0778ea65c46ebf37ac8188c Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 21 Apr 2024 18:55:11 +0200 Subject: feat: add warmstarting to contact constraints resolution --- benchmarks2d/vertical_stacks2.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'benchmarks2d') diff --git a/benchmarks2d/vertical_stacks2.rs b/benchmarks2d/vertical_stacks2.rs index a415693..aaf7933 100644 --- a/benchmarks2d/vertical_stacks2.rs +++ b/benchmarks2d/vertical_stacks2.rs @@ -11,14 +11,14 @@ pub fn init_world(testbed: &mut Testbed) { let multibody_joints = MultibodyJointSet::new(); - let num = 40; + let rad = 0.5; // 50.0 / 2.0; // 0.5; let rad = 50.0 / 2.0; // 0.5; /* * Ground */ let ground_size = num as f32 * rad * 10.0; - let ground_thickness = 1.0; + let ground_thickness = 25.0; let rigid_body = RigidBodyBuilder::fixed(); let ground_handle = bodies.insert(rigid_body); @@ -30,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) { */ let shiftx_centerx = [ - (rad * 2.0, -(num as f32) * rad * 2.0 * 1.5), + (rad * 2.0 + 0.0002, -(num as f32) * rad * 2.0 * 1.5), (rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5), ]; -- cgit From 0a9153e273dc0bdd4ba6443bd7f4dcfc671faac3 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 28 Apr 2024 18:23:30 +0200 Subject: chore: clippy fixes --- benchmarks2d/vertical_stacks2.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'benchmarks2d') diff --git a/benchmarks2d/vertical_stacks2.rs b/benchmarks2d/vertical_stacks2.rs index aaf7933..15552ba 100644 --- a/benchmarks2d/vertical_stacks2.rs +++ b/benchmarks2d/vertical_stacks2.rs @@ -10,15 +10,14 @@ pub fn init_world(testbed: &mut Testbed) { let impulse_joints = ImpulseJointSet::new(); let multibody_joints = MultibodyJointSet::new(); - - let rad = 0.5; // 50.0 / 2.0; // 0.5; - let rad = 50.0 / 2.0; // 0.5; + let num = 80; + let rad = 0.5; /* * Ground */ let ground_size = num as f32 * rad * 10.0; - let ground_thickness = 25.0; + let ground_thickness = 1.0; let rigid_body = RigidBodyBuilder::fixed(); let ground_handle = bodies.insert(rigid_body); @@ -31,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) { let shiftx_centerx = [ (rad * 2.0 + 0.0002, -(num as f32) * rad * 2.0 * 1.5), - (rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5), + (rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5), ]; for (shiftx, centerx) in shiftx_centerx { -- cgit From 1b05b2ebfac63034d3dd14a7a5b9b87c59377529 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Fri, 19 Apr 2024 12:42:16 +0700 Subject: Fix typo in clippy fix. This was supposed to be a `'('`, not a `')'`. Fixes #596. --- benchmarks2d/all_benchmarks2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'benchmarks2d') diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs index 64ec802..3f98fb4 100644 --- a/benchmarks2d/all_benchmarks2.rs +++ b/benchmarks2d/all_benchmarks2.rs @@ -68,7 +68,7 @@ pub fn main() { ]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with(')')) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, -- cgit