aboutsummaryrefslogtreecommitdiff
path: root/benchmarks3d/balls3.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2020-09-06 12:16:09 +0200
committerSébastien Crozet <developer@crozet.re>2020-09-06 12:16:22 +0200
commitff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b (patch)
tree76578c4a2ff16592b98eea9cbd9c9b07646240a4 /benchmarks3d/balls3.rs
parent3080c6e7d2e7bad0ac55095ccc24b1ac8bd5449a (diff)
downloadrapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.tar.gz
rapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.tar.bz2
rapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.zip
Move benchmark demos into their own directory.
Diffstat (limited to 'benchmarks3d/balls3.rs')
-rw-r--r--benchmarks3d/balls3.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/benchmarks3d/balls3.rs b/benchmarks3d/balls3.rs
new file mode 100644
index 0000000..bdbe75e
--- /dev/null
+++ b/benchmarks3d/balls3.rs
@@ -0,0 +1,58 @@
+use na::Point3;
+use rapier3d::dynamics::{BodyStatus, 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 = 20;
+ let rad = 1.0;
+
+ let shift = rad * 2.0 + 1.0;
+ let centerx = shift * (num as f32) / 2.0;
+ let centery = shift / 2.0;
+ let centerz = shift * (num as f32) / 2.0;
+
+ for i in 0..num {
+ for j in 0usize..num {
+ for k in 0..num {
+ let x = i as f32 * shift - centerx;
+ let y = j as f32 * shift + centery;
+ let z = k as f32 * shift - centerz;
+
+ let status = if j == 0 {
+ BodyStatus::Static
+ } else {
+ BodyStatus::Dynamic
+ };
+ let density = 0.477;
+
+ // Build the rigid body.
+ let rigid_body = RigidBodyBuilder::new(status).translation(x, y, z).build();
+ let handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::ball(rad).density(density).build();
+ colliders.insert(collider, handle, &mut bodies);
+ }
+ }
+ }
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world(bodies, colliders, joints);
+ testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
+}
+
+fn main() {
+ let testbed = Testbed::from_builders(0, vec![("Balls", init_world)]);
+ testbed.run()
+}