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, Point2};
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
use na::ComplexField;
use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -19,18 +18,18 @@ pub fn init_world(testbed: &mut Testbed) {
let step_size = ground_size / (nsubdivs as f32);
let mut points = Vec::new();
points.push(Point2::new(-ground_size / 2.0, 40.0));
points.push(point![-ground_size / 2.0, 40.0]);
for i in 1..nsubdivs - 1 {
let x = -ground_size / 2.0 + i as f32 * step_size;
let y = ComplexField::cos(i as f32 * step_size) * 2.0;
points.push(Point2::new(x, y));
points.push(point![x, y]);
}
points.push(Point2::new(ground_size / 2.0, 40.0));
points.push(point![ground_size / 2.0, 40.0]);
let rigid_body = RigidBodyBuilder::new_static().build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::polyline(points, None).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
@@ -48,15 +47,17 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(vector![x, y])
.build();
let handle = bodies.insert(rigid_body);
if j % 2 == 0 {
let collider = ColliderBuilder::cuboid(rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
} else {
let collider = ColliderBuilder::ball(rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -65,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point2::new(0.0, 0.0), 10.0);
testbed.look_at(point![0.0, 0.0], 10.0);
}