aboutsummaryrefslogtreecommitdiff
path: root/benchmarks2d
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2024-04-14 18:59:08 +0200
committerSébastien Crozet <sebastien@crozet.re>2024-04-30 23:10:46 +0200
commitde5e871cd1a76d424c2fa49da776c14ddd6f533b (patch)
treecf0f10c30056e7bb29d2c4afd4157feacd7afa70 /benchmarks2d
parent2f1ce1887f8bc42dc4cf7bd45cf6992eb82e46d3 (diff)
downloadrapier-de5e871cd1a76d424c2fa49da776c14ddd6f533b.tar.gz
rapier-de5e871cd1a76d424c2fa49da776c14ddd6f533b.tar.bz2
rapier-de5e871cd1a76d424c2fa49da776c14ddd6f533b.zip
chore: rework vertical stacks demo
Diffstat (limited to 'benchmarks2d')
-rw-r--r--benchmarks2d/all_benchmarks2.rs2
-rw-r--r--benchmarks2d/vertical_stacks2.rs47
2 files changed, 29 insertions, 20 deletions
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);
+ }
}
}