chore: rework vertical stacks demo

This commit is contained in:
Sébastien Crozet
2024-04-14 18:59:08 +02:00
committed by Sébastien Crozet
parent 2f1ce1887f
commit de5e871cd1
3 changed files with 28 additions and 17 deletions

View File

@@ -58,7 +58,7 @@ pub fn main() {
("Convex polygons", convex_polygons2::init_world), ("Convex polygons", convex_polygons2::init_world),
("Heightfield", heightfield2::init_world), ("Heightfield", heightfield2::init_world),
("Pyramid", pyramid2::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 ball", joint_ball2::init_world),
("(Stress test) joint fixed", joint_fixed2::init_world), ("(Stress test) joint fixed", joint_fixed2::init_world),
( (

View File

@@ -10,10 +10,14 @@ pub fn init_world(testbed: &mut Testbed) {
let impulse_joints = ImpulseJointSet::new(); let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new(); let multibody_joints = MultibodyJointSet::new();
let num = 40;
let rad = 50.0 / 2.0; // 0.5;
/* /*
* Ground * Ground
*/ */
let ground_size = 100.0; let ground_size = num as f32 * rad * 10.0;
let ground_thickness = 1.0; let ground_thickness = 1.0;
let rigid_body = RigidBodyBuilder::fixed(); let rigid_body = RigidBodyBuilder::fixed();
@@ -24,24 +28,29 @@ pub fn init_world(testbed: &mut Testbed) {
/* /*
* Create the cubes * Create the cubes
*/ */
let num = 30;
let rad = 0.5;
let shift = rad * 2.0; let shiftx_centerx = [
let centery = shift / 2.0 + ground_thickness; (rad * 2.0, -(num as f32) * rad * 2.0 * 1.5),
(rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5),
];
for i in 0..num { for (shiftx, centerx) in shiftx_centerx {
for j in 0usize..1 + i * 2 { let shifty = rad * 2.0;
let fj = j as f32; let centery = shifty / 2.0 + ground_thickness;
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. for i in 0..num {
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]); for j in 0usize..1 + i * 2 {
let handle = bodies.insert(rigid_body); let fj = j as f32;
let collider = ColliderBuilder::cuboid(rad, rad); let fi = i as f32;
colliders.insert_with_parent(collider, handle, &mut bodies); 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);
}
} }
} }

View File

@@ -1,6 +1,8 @@
use crate::math::Real; use crate::math::Real;
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
// TODO: enabling the block solver in 3d introduces a lot of jitters in
// the 3D domino demo. So for now we dont enable it in 3D.
pub(crate) static BLOCK_SOLVER_ENABLED: bool = cfg!(feature = "dim2"); pub(crate) static BLOCK_SOLVER_ENABLED: bool = cfg!(feature = "dim2");
pub(crate) static DISABLE_FRICTION_LIMIT_REAPPLY: bool = false; pub(crate) static DISABLE_FRICTION_LIMIT_REAPPLY: bool = false;