Add prelude + use vectors for setting linvel/translation in builders

This commit is contained in:
Crozet Sébastien
2021-05-25 11:00:13 +02:00
parent 47139323e0
commit 1bef66fea9
93 changed files with 1528 additions and 1259 deletions

View File

@@ -1,6 +1,5 @@
use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
use na::ComplexField;
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let ground_size = Vector3::new(100.0, 1.0, 100.0);
let ground_size = Vector::new(100.0, 1.0, 100.0);
let nsubdivs = 20;
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
@@ -34,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::new_static().build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
@@ -55,7 +54,9 @@ pub fn init_world(testbed: &mut Testbed) {
let z = k as f32 * shift - centerz;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(vector![x, y, z])
.build();
let handle = bodies.insert(rigid_body);
let collider = match j % 6 {
@@ -69,15 +70,15 @@ pub fn init_world(testbed: &mut Testbed) {
_ => {
let shapes = vec![
(
Isometry3::identity(),
Isometry::identity(),
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
),
(
Isometry3::translation(rad, 0.0, 0.0),
Isometry::translation(rad, 0.0, 0.0),
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
),
(
Isometry3::translation(-rad, 0.0, 0.0),
Isometry::translation(-rad, 0.0, 0.0),
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
),
];
@@ -86,7 +87,7 @@ pub fn init_world(testbed: &mut Testbed) {
}
};
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -95,5 +96,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());
}