diff options
Diffstat (limited to 'examples3d')
| -rw-r--r-- | examples3d/debug_big_colliders3.rs | 23 | ||||
| -rw-r--r-- | examples3d/debug_infinite_fall3.rs | 8 | ||||
| -rw-r--r-- | examples3d/fountain3.rs | 14 | ||||
| -rw-r--r-- | examples3d/primitives3.rs | 48 |
4 files changed, 37 insertions, 56 deletions
diff --git a/examples3d/debug_big_colliders3.rs b/examples3d/debug_big_colliders3.rs index c2b62e2..956f36a 100644 --- a/examples3d/debug_big_colliders3.rs +++ b/examples3d/debug_big_colliders3.rs @@ -1,6 +1,6 @@ -use na::Point3; +use na::{Point3, Vector3}; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::geometry::{ColliderBuilder, ColliderSet, HalfSpace, SharedShape}; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,30 +14,27 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = 100.0; - let ground_height = 0.1; - let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size) - .friction(1.5) - .build(); + let halfspace = SharedShape::new(HalfSpace::new(Vector3::y_axis())); + let collider = ColliderBuilder::new(halfspace).build(); colliders.insert(collider, handle, &mut bodies); let mut curr_y = 0.0; - let mut curr_width = 1_000.0; + let mut curr_width = 10_000.0; - for _ in 0..6 { - curr_y += curr_width; + for _ in 0..12 { + let curr_height = 0.1f32.min(curr_width); + curr_y += curr_height * 4.0; let rigid_body = RigidBodyBuilder::new_dynamic() .translation(0.0, curr_y, 0.0) .build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(curr_width, curr_width, curr_width).build(); + let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width).build(); colliders.insert(collider, handle, &mut bodies); - curr_width /= 10.0; + curr_width /= 5.0; } /* diff --git a/examples3d/debug_infinite_fall3.rs b/examples3d/debug_infinite_fall3.rs index 2a85e37..e70a386 100644 --- a/examples3d/debug_infinite_fall3.rs +++ b/examples3d/debug_infinite_fall3.rs @@ -1,3 +1,4 @@ +use na::Point3; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; use rapier3d::geometry::{ColliderBuilder, ColliderSet}; use rapier_testbed3d::Testbed; @@ -17,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 2.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(0.0, 4.0, 0.0) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); @@ -26,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) { let rad = 1.0; // Build the dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0 * rad, 0.0) + .translation(0.0, 7.0 * rad, 0.0) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); @@ -34,7 +35,7 @@ pub fn init_world(testbed: &mut Testbed) { colliders.insert(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 5.0 * rad, 0.0) + .translation(0.0, 2.0 * rad, 0.0) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); @@ -44,6 +45,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Set up the testbed. */ + testbed.look_at(Point3::new(100.0, -10.0, 100.0), Point3::origin()); testbed.set_world(bodies, colliders, joints); } diff --git a/examples3d/fountain3.rs b/examples3d/fountain3.rs index e39ff2a..6c80562 100644 --- a/examples3d/fountain3.rs +++ b/examples3d/fountain3.rs @@ -15,7 +15,7 @@ pub fn init_world(testbed: &mut Testbed) { * Ground */ let ground_size = 100.1; - let ground_height = 2.1; + let ground_height = 2.1; // 16.0; let rigid_body = RigidBodyBuilder::new_static() .translation(0.0, -ground_height, 0.0) @@ -64,10 +64,6 @@ pub fn init_world(testbed: &mut Testbed) { physics .bodies .remove(*handle, &mut physics.colliders, &mut physics.joints); - physics.broad_phase.maintain(&mut physics.colliders); - physics - .narrow_phase - .maintain(&mut physics.colliders, &mut physics.bodies); if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) { graphics.remove_body_nodes(window, *handle); @@ -80,10 +76,10 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed - .physics_state_mut() - .integration_parameters - .velocity_based_erp = 0.2; + // testbed + // .physics_state_mut() + // .integration_parameters + // .velocity_based_erp = 0.2; testbed.look_at(Point3::new(-30.0, 4.0, -30.0), Point3::new(0.0, 1.0, 0.0)); } diff --git a/examples3d/primitives3.rs b/examples3d/primitives3.rs index a9ae176..db15341 100644 --- a/examples3d/primitives3.rs +++ b/examples3d/primitives3.rs @@ -12,6 +12,19 @@ pub fn init_world(testbed: &mut Testbed) { let joints = JointSet::new(); /* + * Ground + */ + let ground_size = 100.1; + let ground_height = 2.1; + + let rigid_body = RigidBodyBuilder::new_static() + .translation(0.0, -ground_height, 0.0) + .build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); + colliders.insert(collider, handle, &mut bodies); + + /* * Create the cubes */ let num = 8; @@ -26,11 +39,11 @@ pub fn init_world(testbed: &mut Testbed) { let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5; - for j in 0usize..1 { - for i in 0..1 { - for k in 0usize..1 { + for j in 0usize..20 { + for i in 0..num { + for k in 0usize..num { let x = i as f32 * shiftx - centerx + offset; - let y = j as f32 * shifty + centery - rad; + let y = j as f32 * shifty + centery + 3.0; let z = k as f32 * shiftz - centerz + offset; // Build the rigid body. @@ -55,36 +68,9 @@ pub fn init_world(testbed: &mut Testbed) { } /* - * Ground - */ - testbed.add_callback( - move |mut window, mut graphics, physics, events, run_state| { - if run_state.timestep_id == 10 { - let ground_size = 100.1; - let ground_height = 2.1; - - let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) - .build(); - let handle = physics.bodies.insert(rigid_body); - let collider = - ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); - physics - .colliders - .insert(collider, handle, &mut physics.bodies); - - if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) { - graphics.add(window, handle, &physics.bodies, &physics.colliders); - } - } - }, - ); - - /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.physics_state_mut().gravity.fill(0.0); testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); } |
