aboutsummaryrefslogtreecommitdiff
path: root/examples3d
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-11-03 15:34:01 +0100
committerCrozet Sébastien <developer@crozet.re>2020-11-03 15:34:01 +0100
commitdb337c5df6de124e0fdff7eaa7aeebc28bfb27e6 (patch)
tree60b0e03ee6345dcb4a4114ccb344486078116f84 /examples3d
parent71611d3e30ce2fddee20832db3c3e0c8b6ba0d07 (diff)
downloadrapier-db337c5df6de124e0fdff7eaa7aeebc28bfb27e6.tar.gz
rapier-db337c5df6de124e0fdff7eaa7aeebc28bfb27e6.tar.bz2
rapier-db337c5df6de124e0fdff7eaa7aeebc28bfb27e6.zip
Add damping support + demos.
Diffstat (limited to 'examples3d')
-rw-r--r--examples3d/all_examples3.rs2
-rw-r--r--examples3d/damping3.rs45
2 files changed, 47 insertions, 0 deletions
diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs
index 2196605..9c1dffc 100644
--- a/examples3d/all_examples3.rs
+++ b/examples3d/all_examples3.rs
@@ -13,6 +13,7 @@ use std::cmp::Ordering;
mod add_remove3;
mod collision_groups3;
mod compound3;
+mod damping3;
mod debug_boxes3;
mod debug_cylinder3;
mod debug_triangle3;
@@ -69,6 +70,7 @@ pub fn main() {
("Primitives", primitives3::init_world),
("Collision groups", collision_groups3::init_world),
("Compound", compound3::init_world),
+ ("Damping", damping3::init_world),
("Domino", domino3::init_world),
("Heightfield", heightfield3::init_world),
("Joints", joints3::init_world),
diff --git a/examples3d/damping3.rs b/examples3d/damping3.rs
new file mode 100644
index 0000000..e055d8e
--- /dev/null
+++ b/examples3d/damping3.rs
@@ -0,0 +1,45 @@
+use na::{Point3, Vector3};
+use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
+use rapier3d::geometry::{ColliderBuilder, ColliderSet};
+use rapier_testbed3d::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, 0.0)
+ .linvel(x * 10.0, y * 10.0, 0.0)
+ .angvel(Vector3::z() * 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, rad).build();
+ colliders.insert(co, rb_handle, &mut bodies);
+ }
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world_with_gravity(bodies, colliders, joints, Vector3::zeros());
+ testbed.look_at(Point3::new(2.0, 2.5, 20.0), Point3::new(2.0, 2.5, 0.0));
+}