diff options
| author | Sébastien Crozet <developer@crozet.re> | 2023-12-10 22:08:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 22:08:07 +0100 |
| commit | 9ac3503b879f95fcdf5414470ba5aedf195b9a97 (patch) | |
| tree | 5551e86f366f53bfaa24a266f082ff332d74e52b /examples2d | |
| parent | c33b4eeb5c113b8f8509cd866c4ab48e5d6c5eaa (diff) | |
| parent | 2fba50c297987dac6971452d877c1609cee43a98 (diff) | |
| download | rapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.tar.gz rapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.tar.bz2 rapier-9ac3503b879f95fcdf5414470ba5aedf195b9a97.zip | |
Merge pull request #422 from pellico/Fix_Revolute-joint-motor-target-position-is-broken-at-and-beyond-90-degree-angles
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 | 79 |
2 files changed, 81 insertions, 0 deletions
diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs index d102b46..032e4d6 100644 --- a/examples2d/all_examples2.rs +++ b/examples2d/all_examples2.rs @@ -17,6 +17,7 @@ mod damping2; mod debug_box_ball2; mod drum2; mod heightfield2; +mod joint_motor_position2; mod joints2; mod locked_rotations2; mod one_way_platforms2; @@ -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..c8374ff --- /dev/null +++ b/examples2d/joint_motor_position2.rs @@ -0,0 +1,79 @@ +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(); + + /* + * Fixed ground to attach one end of the joints. + */ + let rigid_body = RigidBodyBuilder::fixed(); + let ground_handle = bodies.insert(rigid_body); + + /* + * A rectangle on a motor with target position. + */ + 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]) + .can_sleep(false); + 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_anchor1(point![x_pos, 1.5]) + .local_anchor2(point![0.0, -0.5]) + .motor_position( + -std::f32::consts::PI + std::f32::consts::PI / 4.0 * num as f32, + 1000.0, + 150.0, + ); + impulse_joints.insert(ground_handle, handle, joint, true); + } + + /* + * A rectangle on a motor with limits. + */ + for num in 0..8 { + let x_pos = -6.0 + 1.5 * num as f32; + let rigid_body = RigidBodyBuilder::dynamic() + .translation(vector![x_pos, 4.5]) + .rotation(std::f32::consts::PI) + .can_sleep(false); + 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_anchor1(point![x_pos, 5.0]) + .local_anchor2(point![0.0, -0.5]) + .motor_velocity(1.5, 30.0) + .motor_max_force(100.0) + .limits([ + -std::f32::consts::PI, + -std::f32::consts::PI + std::f32::consts::PI / 4.0 * num as f32, + ]); + impulse_joints.insert(ground_handle, 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); +} |
