aboutsummaryrefslogtreecommitdiff
path: root/examples3d/keva3.rs
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-05-25 11:00:13 +0200
committerCrozet Sébastien <developer@crozet.re>2021-05-25 11:00:13 +0200
commit1bef66fea941307a7305ddaebdb0abe3d0cb281f (patch)
tree450bc3cd2fd611f91cb7d7809edcc4260f043b0b /examples3d/keva3.rs
parent47139323e01f978a94ed7aa2c33bbf63b00f4c30 (diff)
downloadrapier-1bef66fea941307a7305ddaebdb0abe3d0cb281f.tar.gz
rapier-1bef66fea941307a7305ddaebdb0abe3d0cb281f.tar.bz2
rapier-1bef66fea941307a7305ddaebdb0abe3d0cb281f.zip
Add prelude + use vectors for setting linvel/translation in builders
Diffstat (limited to 'examples3d/keva3.rs')
-rw-r--r--examples3d/keva3.rs38
1 files changed, 18 insertions, 20 deletions
diff --git a/examples3d/keva3.rs b/examples3d/keva3.rs
index 9e6807a..38a0432 100644
--- a/examples3d/keva3.rs
+++ b/examples3d/keva3.rs
@@ -1,14 +1,12 @@
-use na::{Point3, Vector3};
-use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
-use rapier3d::geometry::{ColliderBuilder, ColliderSet};
+use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn build_block(
testbed: &mut Testbed,
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
- half_extents: Vector3<f32>,
- shift: Vector3<f32>,
+ half_extents: Vector<f32>,
+ shift: Vector<f32>,
mut numx: usize,
numy: usize,
mut numz: usize,
@@ -17,8 +15,8 @@ pub fn build_block(
let block_width = 2.0 * half_extents.z * numx as f32;
let block_height = 2.0 * half_extents.y * numy as f32;
let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0);
- let mut color0 = Point3::new(0.7, 0.5, 0.9);
- let mut color1 = Point3::new(0.6, 1.0, 0.6);
+ let mut color0 = [0.7, 0.5, 0.9];
+ let mut color1 = [0.6, 1.0, 0.6];
for i in 0..numy {
std::mem::swap(&mut numx, &mut numz);
@@ -41,15 +39,15 @@ pub fn build_block(
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
- .translation(
+ .translation(vector![
x + dim.x + shift.x,
y + dim.y + shift.y,
- z + dim.z + shift.z,
- )
+ z + dim.z + shift.z
+ ])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
- colliders.insert(collider, handle, bodies);
+ colliders.insert_with_parent(collider, handle, bodies);
testbed.set_initial_body_color(handle, color0);
std::mem::swap(&mut color0, &mut color1);
@@ -64,15 +62,15 @@ pub fn build_block(
for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize {
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
- .translation(
+ .translation(vector![
i as f32 * dim.x * 2.0 + dim.x + shift.x,
dim.y + shift.y + block_height,
- j as f32 * dim.z * 2.0 + dim.z + shift.z,
- )
+ j as f32 * dim.z * 2.0 + dim.z + shift.z
+ ])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
- colliders.insert(collider, handle, bodies);
+ colliders.insert_with_parent(collider, handle, bodies);
testbed.set_initial_body_color(handle, color0);
std::mem::swap(&mut color0, &mut color1);
}
@@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_height = 0.1;
let rigid_body = RigidBodyBuilder::new_static()
- .translation(0.0, -ground_height, 0.0)
+ .translation(vector![0.0, -ground_height, 0.0])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
- colliders.insert(collider, handle, &mut bodies);
+ colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
- let half_extents = Vector3::new(0.02, 0.1, 0.4) / 2.0 * 10.0;
+ let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0;
let mut block_height = 0.0;
// These should only be set to odd values otherwise
// the blocks won't align in the nicest way.
@@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) {
&mut bodies,
&mut colliders,
half_extents,
- Vector3::new(-block_width / 2.0, block_height, -block_width / 2.0),
+ vector![-block_width / 2.0, block_height, -block_width / 2.0],
numx,
numy,
numz,
@@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
- testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
+ testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
}