diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-11-03 15:46:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-03 15:46:16 +0100 |
| commit | a66f1175788c2626f0fbb510bbf1986cfd283b72 (patch) | |
| tree | 60b0e03ee6345dcb4a4114ccb344486078116f84 /examples2d/damping2.rs | |
| parent | f70a840f79943aa6da49db2590e13dcd3f3a89ed (diff) | |
| parent | db337c5df6de124e0fdff7eaa7aeebc28bfb27e6 (diff) | |
| download | rapier-a66f1175788c2626f0fbb510bbf1986cfd283b72.tar.gz rapier-a66f1175788c2626f0fbb510bbf1986cfd283b72.tar.bz2 rapier-a66f1175788c2626f0fbb510bbf1986cfd283b72.zip | |
Merge pull request #55 from dimforge/damping
Add damping support + demos.
Diffstat (limited to 'examples2d/damping2.rs')
| -rw-r--r-- | examples2d/damping2.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples2d/damping2.rs b/examples2d/damping2.rs new file mode 100644 index 0000000..43ca2b6 --- /dev/null +++ b/examples2d/damping2.rs @@ -0,0 +1,45 @@ +use na::{Point2, Vector2}; +use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed2d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let joints = JointSet::new(); + + /* + * Create the balls + */ + let num = 10; + let rad = 0.2; + + let subdiv = 1.0 / (num as f32); + + for i in 0usize..num { + let (x, y) = (i as f32 * subdiv * std::f32::consts::PI * 2.0).sin_cos(); + + // Build the rigid body. + let rb = RigidBodyBuilder::new_dynamic() + .translation(x, y) + .linvel(x * 10.0, y * 10.0) + .angvel(100.0) + .linear_damping((i + 1) as f32 * subdiv * 10.0) + .angular_damping((num - i) as f32 * subdiv * 10.0) + .build(); + let rb_handle = bodies.insert(rb); + + // Build the collider. + let co = ColliderBuilder::cuboid(rad, rad).build(); + colliders.insert(co, rb_handle, &mut bodies); + } + + /* + * Set up the testbed. + */ + testbed.set_world_with_gravity(bodies, colliders, joints, Vector2::zeros()); + testbed.look_at(Point2::new(3.0, 2.0), 50.0); +} |
