diff options
| author | pellico <pellico@users.noreply.github.com> | 2022-11-27 18:47:35 +0100 |
|---|---|---|
| committer | Sébastien Crozet <sebcrozet@dimforge.com> | 2023-12-10 12:43:13 +0100 |
| commit | 6432909110c4b96e59d4ee2ebdae1d79abe8d4b3 (patch) | |
| tree | 691b88f6c151407f185c124c311123eb40cccccf /examples2d | |
| parent | c33b4eeb5c113b8f8509cd866c4ab48e5d6c5eaa (diff) | |
| download | rapier-6432909110c4b96e59d4ee2ebdae1d79abe8d4b3.tar.gz rapier-6432909110c4b96e59d4ee2ebdae1d79abe8d4b3.tar.bz2 rapier-6432909110c4b96e59d4ee2ebdae1d79abe8d4b3.zip | |
Fix #378 Added one example join_motor_position
Diffstat (limited to 'examples2d')
| -rw-r--r-- | examples2d/all_examples2.rs | 2 | ||||
| -rw-r--r-- | examples2d/joint_motor_position2.rs | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs index d102b46..fff20c5 100644 --- a/examples2d/all_examples2.rs +++ b/examples2d/all_examples2.rs @@ -16,6 +16,7 @@ mod convex_polygons2; mod damping2; mod debug_box_ball2; mod drum2; +mod joint_motor_position2; mod heightfield2; mod joints2; mod locked_rotations2; @@ -79,6 +80,7 @@ pub fn main() { ("Rope Joints", rope_joints2::init_world), ("Sensor", sensor2::init_world), ("Trimesh", trimesh2::init_world), + ("Joint motor position", joint_motor_position2::init_world), ("(Debug) box ball", debug_box_ball2::init_world), ]; diff --git a/examples2d/joint_motor_position2.rs b/examples2d/joint_motor_position2.rs new file mode 100644 index 0000000..5a79874 --- /dev/null +++ b/examples2d/joint_motor_position2.rs @@ -0,0 +1,46 @@ +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 mut impulse_joints = ImpulseJointSet::new(); + let multibody_joints = MultibodyJointSet::new(); + + /* + * The ground + */ + let ground_size = 5.0; + let ground_height = 0.1; + + let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height]); + let ground_handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_height); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); + + /* + * A rectangle on a motor + */ + for num in 0..9 { + let x_pos = -6.0 + 1.5 * num as f32; + let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x_pos, 2.0]); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(0.1, 0.5); + colliders.insert_with_parent(collider, handle, &mut bodies); + + let joint = RevoluteJointBuilder::new() + .local_anchor2(point![x_pos, 1.5]) + .local_anchor1(point![0.0, -0.5]) + .motor_position(std::f32::consts::PI/4.0*num as f32, 100.0, 15.0); + impulse_joints.insert(handle,ground_handle, joint, true); + } + + /* + * Set up the testbed. + */ + testbed.set_world_with_params(bodies, colliders, impulse_joints, multibody_joints,vector![0.0,0.0],()); + testbed.look_at(point![0.0, 0.0], 40.0); +} |
