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,15 +1,13 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
fn create_wall(
testbed: &mut Testbed,
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
offset: Vector3<f32>,
offset: Vector<f32>,
stack_height: usize,
half_extents: Vector3<f32>,
half_extents: Vector<f32>,
) {
let shift = half_extents * 2.0;
let mut k = 0;
@@ -23,22 +21,18 @@ fn create_wall(
- stack_height as f32 * half_extents.z;
// 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 =
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
colliders.insert(collider, handle, bodies);
colliders.insert_with_parent(collider, handle, bodies);
k += 1;
if k % 2 == 0 {
testbed.set_initial_body_color(
handle,
Point3::new(255. / 255., 131. / 255., 244.0 / 255.),
);
testbed.set_initial_body_color(handle, [255. / 255., 131. / 255., 244.0 / 255.]);
} else {
testbed.set_initial_body_color(
handle,
Point3::new(131. / 255., 255. / 255., 244.0 / 255.),
);
testbed.set_initial_body_color(handle, [131. / 255., 255. / 255., 244.0 / 255.]);
}
}
}
@@ -59,11 +53,11 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
colliders.insert(collider, ground_handle, &mut bodies);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create the pyramids.
@@ -79,18 +73,18 @@ pub fn init_world(testbed: &mut Testbed) {
testbed,
&mut bodies,
&mut colliders,
Vector3::new(x, shift_y, 0.0),
vector![x, shift_y, 0.0],
num_z,
Vector3::new(0.5, 0.5, 1.0),
vector![0.5, 0.5, 1.0],
);
create_wall(
testbed,
&mut bodies,
&mut colliders,
Vector3::new(x, shift_y, shift_z),
vector![x, shift_y, shift_z],
num_z,
Vector3::new(0.5, 0.5, 1.0),
vector![0.5, 0.5, 1.0],
);
}
@@ -104,35 +98,45 @@ pub fn init_world(testbed: &mut Testbed) {
.sensor(true)
.build();
let rigid_body = RigidBodyBuilder::new_dynamic()
.linvel(1000.0, 0.0, 0.0)
.translation(-20.0, shift_y + 2.0, 0.0)
.linvel(vector![1000.0, 0.0, 0.0])
.translation(vector![-20.0, shift_y + 2.0, 0.0])
.ccd_enabled(true)
.build();
let sensor_handle = bodies.insert(rigid_body);
colliders.insert(collider, sensor_handle, &mut bodies);
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
// Second rigid-body with CCD enabled.
let collider = ColliderBuilder::ball(1.0).density(10.0).build();
let rigid_body = RigidBodyBuilder::new_dynamic()
.linvel(1000.0, 0.0, 0.0)
.translation(-20.0, shift_y + 2.0, shift_z)
.linvel(vector![1000.0, 0.0, 0.0])
.translation(vector![-20.0, shift_y + 2.0, shift_z])
.ccd_enabled(true)
.build();
let handle = bodies.insert(rigid_body);
colliders.insert(collider.clone(), handle, &mut bodies);
testbed.set_initial_body_color(handle, Point3::new(0.2, 0.2, 1.0));
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
testbed.set_initial_body_color(handle, [0.2, 0.2, 1.0]);
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |mut graphics, physics, events, _| {
while let Ok(prox) = events.intersection_events.try_recv() {
let color = if prox.intersecting {
Point3::new(1.0, 1.0, 0.0)
[1.0, 1.0, 0.0]
} else {
Point3::new(0.5, 0.5, 1.0)
[0.5, 0.5, 1.0]
};
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
let parent_handle1 = physics
.colliders
.get(prox.collider1)
.unwrap()
.parent()
.unwrap();
let parent_handle2 = physics
.colliders
.get(prox.collider2)
.unwrap()
.parent()
.unwrap();
if let Some(graphics) = &mut graphics {
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
@@ -149,5 +153,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());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ 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 floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
colliders.insert(collider, floor_handle, &mut bodies);
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
/*
* Setup groups
@@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) {
* A green floor that will collide with the GREEN group only.
*/
let green_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
.translation(0.0, 1.0, 0.0)
.translation(vector![0.0, 1.0, 0.0])
.collision_groups(GREEN_GROUP)
.build();
let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies);
let green_collider_handle =
colliders.insert_with_parent(green_floor, floor_handle, &mut bodies);
testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0));
testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]);
/*
* A blue floor that will collide with the BLUE group only.
*/
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
.translation(0.0, 2.0, 0.0)
.translation(vector![0.0, 2.0, 0.0])
.collision_groups(BLUE_GROUP)
.build();
let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies);
let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies);
testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0));
testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]);
/*
* Create the cubes
@@ -72,17 +71,19 @@ pub fn init_world(testbed: &mut Testbed) {
// Alternate between the green and blue groups.
let (group, color) = if k % 2 == 0 {
(GREEN_GROUP, Point3::new(0.0, 1.0, 0.0))
(GREEN_GROUP, [0.0, 1.0, 0.0])
} else {
(BLUE_GROUP, Point3::new(0.0, 0.0, 1.0))
(BLUE_GROUP, [0.0, 0.0, 1.0])
};
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 = ColliderBuilder::cuboid(rad, rad, rad)
.collision_groups(group)
.build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, color);
}
@@ -93,5 +94,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Isometry3, Point3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ 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
@@ -46,40 +44,42 @@ pub fn init_world(testbed: &mut Testbed) {
let z = k as f32 * shift * 2.0 - centerz + offset;
// 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);
// First option: attach several colliders to a single rigid-body.
if j < numy / 2 {
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
.translation(rad * 10.0, rad * 10.0, 0.0)
.translation(vector![rad * 10.0, rad * 10.0, 0.0])
.build();
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
.translation(-rad * 10.0, rad * 10.0, 0.0)
.translation(vector![-rad * 10.0, rad * 10.0, 0.0])
.build();
colliders.insert(collider1, handle, &mut bodies);
colliders.insert(collider2, handle, &mut bodies);
colliders.insert(collider3, handle, &mut bodies);
colliders.insert_with_parent(collider1, handle, &mut bodies);
colliders.insert_with_parent(collider2, handle, &mut bodies);
colliders.insert_with_parent(collider3, handle, &mut bodies);
} else {
// Second option: create a compound shape and attach it to a single collider.
let shapes = vec![
(
Isometry3::identity(),
Isometry::identity(),
SharedShape::cuboid(rad * 10.0, rad, rad),
),
(
Isometry3::translation(rad * 10.0, rad * 10.0, 0.0),
Isometry::translation(rad * 10.0, rad * 10.0, 0.0),
SharedShape::cuboid(rad, rad * 10.0, rad),
),
(
Isometry3::translation(-rad * 10.0, rad * 10.0, 0.0),
Isometry::translation(-rad * 10.0, rad * 10.0, 0.0),
SharedShape::cuboid(rad, rad * 10.0, rad),
),
];
let collider = ColliderBuilder::compound(shapes).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -91,5 +91,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());
}

View File

@@ -1,8 +1,6 @@
use na::Point3;
use obj::raw::object::Polygon;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
use rapier3d::parry::bounding_volume;
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
use std::fs::File;
use std::io::BufReader;
@@ -26,11 +24,11 @@ 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 convex decompositions.
@@ -52,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut vertices: Vec<_> = model
.positions
.iter()
.map(|v| Point3::new(v.0, v.1, v.2))
.map(|v| point![v.0, v.1, v.2])
.collect();
use std::iter::FromIterator;
let indices: Vec<_> = model
@@ -90,12 +88,14 @@ pub fn init_world(testbed: &mut Testbed) {
let y = (igeom / width) as f32 * shift + 4.0;
let z = k as f32 * shift;
let body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
let body = RigidBodyBuilder::new_dynamic()
.translation(vector![x, y, z])
.build();
let handle = bodies.insert(body);
for shape in &shapes {
let collider = ColliderBuilder::new(shape.clone()).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -105,7 +105,7 @@ 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());
}
fn models() -> Vec<String> {

View File

@@ -1,8 +1,6 @@
use na::Point3;
use rand::distributions::{Distribution, Standard};
use rand::{rngs::StdRng, SeedableRng};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -20,11 +18,11 @@ 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 polyhedra
@@ -50,17 +48,19 @@ pub fn init_world(testbed: &mut Testbed) {
let mut points = Vec::new();
for _ in 0..10 {
let pt: Point3<f32> = distribution.sample(&mut rng);
let pt: Point<f32> = distribution.sample(&mut rng);
points.push(pt * scale);
}
// 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 = ColliderBuilder::round_convex_hull(&points, border_rad)
.unwrap()
.build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -69,5 +69,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(30.0, 30.0, 30.0), Point3::origin());
testbed.look_at(point![30.0, 30.0, 30.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -24,9 +22,9 @@ pub fn init_world(testbed: &mut Testbed) {
// 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)
.translation(vector![x, y, 0.0])
.linvel(vector![x * 10.0, y * 10.0, 0.0])
.angvel(Vector::z() * 100.0)
.linear_damping((i + 1) as f32 * subdiv * 10.0)
.angular_damping((num - i) as f32 * subdiv * 10.0)
.build();
@@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) {
// Build the collider.
let co = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(co, rb_handle, &mut bodies);
colliders.insert_with_parent(co, rb_handle, &mut bodies);
}
/*
* Set up the testbed.
*/
testbed.set_world_with_params(bodies, colliders, joints, Vector3::zeros(), ());
testbed.look_at(Point3::new(2.0, 2.5, 20.0), Point3::new(2.0, 2.5, 0.0));
testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ());
testbed.look_at(point![2.0, 2.5, 20.0], point![2.0, 2.5, 0.0]);
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -17,22 +15,23 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4).build();
let mut ground_collider_handle = colliders.insert(collider, ground_handle, &mut bodies);
let mut ground_collider_handle =
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Rolling ball
*/
let ball_rad = 0.1;
let rb = RigidBodyBuilder::new_dynamic()
.translation(0.0, 0.2, 0.0)
.translation(vector![0.0, 0.2, 0.0])
.build();
let ball_handle = bodies.insert(rb);
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
colliders.insert(collider, ball_handle, &mut bodies);
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
testbed.add_callback(move |_, physics, _, _| {
// Remove then re-add the ground collider.
@@ -46,14 +45,15 @@ pub fn init_world(testbed: &mut Testbed) {
true,
)
.unwrap();
ground_collider_handle = physics
.colliders
.insert(coll, ground_handle, &mut physics.bodies);
ground_collider_handle =
physics
.colliders
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
});
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HalfSpace, SharedShape};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -16,9 +14,9 @@ pub fn init_world(testbed: &mut Testbed) {
*/
let rigid_body = RigidBodyBuilder::new_static().build();
let handle = bodies.insert(rigid_body);
let halfspace = SharedShape::new(HalfSpace::new(Vector3::y_axis()));
let halfspace = SharedShape::new(HalfSpace::new(Vector::y_axis()));
let collider = ColliderBuilder::new(halfspace).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let mut curr_y = 0.0;
let mut curr_width = 10_000.0;
@@ -28,11 +26,11 @@ pub fn init_world(testbed: &mut Testbed) {
curr_y += curr_height * 4.0;
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, curr_y, 0.0)
.translation(vector![0.0, curr_y, 0.0])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
curr_width /= 5.0;
}
@@ -41,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -19,28 +17,28 @@ pub fn init_world(testbed: &mut Testbed) {
for _ in 0..6 {
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);
}
// Build the dynamic box rigid body.
for _ in 0..6 {
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(1.1, 0.0, 0.0)
.rotation(Vector3::new(0.8, 0.2, 0.1))
.translation(vector![1.1, 0.0, 0.0])
.rotation(vector![0.8, 0.2, 0.1])
.can_sleep(false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(2.0, 0.1, 1.0).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
// This shows a bug when a cylinder is in contact with a very large
@@ -21,11 +19,11 @@ 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
@@ -47,14 +45,16 @@ pub fn init_world(testbed: &mut Testbed) {
let z = -centerz + offset;
// 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 = ColliderBuilder::cylinder(rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(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());
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Isometry3, Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -17,30 +15,30 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
.friction(0.15)
// .restitution(0.5)
.build();
colliders.insert(collider, ground_handle, &mut bodies);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Rolling ball
*/
let ball_rad = 0.1;
let rb = RigidBodyBuilder::new_dynamic()
.translation(0.0, 0.2, 0.0)
.linvel(10.0, 0.0, 0.0)
.translation(vector![0.0, 0.2, 0.0])
.linvel(vector![10.0, 0.0, 0.0])
.build();
let ball_handle = bodies.insert(rb);
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
colliders.insert(collider, ball_handle, &mut bodies);
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
let mut linvel = Vector3::zeros();
let mut angvel = Vector3::zeros();
let mut pos = Isometry3::identity();
let mut linvel = Vector::zeros();
let mut angvel = Vector::zeros();
let mut pos = Isometry::identity();
let mut step = 0;
let mut extra_colliders = Vec::new();
let snapped_frame = 51;
@@ -55,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
let new_ball_collider_handle =
physics
.colliders
.insert(collider, ball_handle, &mut physics.bodies);
.insert_with_parent(collider, ball_handle, &mut physics.bodies);
if let Some(graphics) = &mut graphics {
graphics.add_collider(new_ball_collider_handle, &physics.colliders);
@@ -93,7 +91,7 @@ pub fn init_world(testbed: &mut Testbed) {
// Remove then re-add the ground collider.
// let ground = physics.bodies.get_mut(ground_handle).unwrap();
// ground.set_position(Isometry3::translation(0.0, step as f32 * 0.001, 0.0), false);
// ground.set_position(Isometry::translation(0.0, step as f32 * 0.001, 0.0), false);
// let coll = physics
// .colliders
// .remove(ground_collider_handle, &mut physics.bodies, true)
@@ -104,7 +102,7 @@ pub fn init_world(testbed: &mut Testbed) {
let new_ground_collider_handle =
physics
.colliders
.insert(coll, ground_handle, &mut physics.bodies);
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
if let Some(graphics) = &mut graphics {
graphics.add_collider(new_ground_collider_handle, &physics.colliders);
@@ -117,5 +115,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -22,24 +20,24 @@ pub fn init_world(testbed: &mut Testbed) {
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
.friction(1.5)
.build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
// Build a dynamic box rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 1.1, 0.0)
.rotation(Vector3::y() * 0.3)
.translation(vector![0.0, 1.1, 0.0])
.rotation(Vector::y() * 0.3)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(2.0, 1.0, 3.0).friction(1.5).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = &mut bodies[handle];
let force = rigid_body.position() * Vector3::z() * 50.0;
let force = rigid_body.position() * Vector::z() * 50.0;
rigid_body.set_linvel(force, true);
/*
* 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());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,33 +16,33 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_height = 2.1;
let rigid_body = RigidBodyBuilder::new_static()
.translation(0.0, 4.0, 0.0)
.translation(vector![0.0, 4.0, 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);
let rad = 1.0;
// Build the dynamic box rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 7.0 * rad, 0.0)
.translation(vector![0.0, 7.0 * rad, 0.0])
.can_sleep(false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 2.0 * rad, 0.0)
.translation(vector![0.0, 2.0 * rad, 0.0])
.can_sleep(false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Set up the testbed.
*/
testbed.look_at(Point3::new(100.0, -10.0, 100.0), Point3::origin());
testbed.look_at(point![100.0, -10.0, 100.0], Point::origin());
testbed.set_world(bodies, colliders, joints);
}

View File

@@ -1,20 +1,18 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
fn prismatic_repro(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
box_center: Point3<f32>,
box_center: Point<f32>,
) {
let box_rb = bodies.insert(
RigidBodyBuilder::new_dynamic()
.translation(box_center.x, box_center.y, box_center.z)
.translation(vector![box_center.x, box_center.y, box_center.z])
.build(),
);
colliders.insert(
colliders.insert_with_parent(
ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(),
box_rb,
bodies,
@@ -22,32 +20,32 @@ fn prismatic_repro(
let wheel_y = -1.0;
let wheel_positions = vec![
Vector3::new(1.0, wheel_y, -1.0),
Vector3::new(-1.0, wheel_y, -1.0),
Vector3::new(1.0, wheel_y, 1.0),
Vector3::new(-1.0, wheel_y, 1.0),
vector![1.0, wheel_y, -1.0],
vector![-1.0, wheel_y, -1.0],
vector![1.0, wheel_y, 1.0],
vector![-1.0, wheel_y, 1.0],
];
for pos in wheel_positions {
let wheel_pos_in_world = box_center + pos;
let wheel_rb = bodies.insert(
RigidBodyBuilder::new_dynamic()
.translation(
.translation(vector![
wheel_pos_in_world.x,
wheel_pos_in_world.y,
wheel_pos_in_world.z,
)
wheel_pos_in_world.z
])
.build(),
);
colliders.insert(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies);
colliders.insert_with_parent(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies);
let mut prismatic = rapier3d::dynamics::PrismaticJoint::new(
Point3::new(pos.x, pos.y, pos.z),
Vector3::y_axis(),
Vector3::default(),
Point3::new(0.0, 0.0, 0.0),
Vector3::y_axis(),
Vector3::default(),
point![pos.x, pos.y, pos.z],
Vector::y_axis(),
Vector::zeros(),
Point::origin(),
Vector::y_axis(),
Vector::default(),
);
prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased);
let (stiffness, damping) = (0.05, 0.2);
@@ -59,10 +57,10 @@ fn prismatic_repro(
// put a small box under one of the wheels
let gravel = bodies.insert(
RigidBodyBuilder::new_dynamic()
.translation(box_center.x + 1.0, box_center.y - 2.4, -1.0)
.translation(vector![box_center.x + 1.0, box_center.y - 2.4, -1.0])
.build(),
);
colliders.insert(
colliders.insert_with_parent(
ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(),
gravel,
bodies,
@@ -84,22 +82,22 @@ 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);
prismatic_repro(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(0.0, 5.0, 0.0),
point![0.0, 5.0, 0.0],
);
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Isometry3, Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -17,30 +15,30 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
.friction(0.15)
// .restitution(0.5)
.build();
colliders.insert(collider, ground_handle, &mut bodies);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Rolling ball
*/
let ball_rad = 0.1;
let rb = RigidBodyBuilder::new_dynamic()
.translation(0.0, 0.2, 0.0)
.linvel(10.0, 0.0, 0.0)
.translation(vector![0.0, 0.2, 0.0])
.linvel(vector![10.0, 0.0, 0.0])
.build();
let ball_handle = bodies.insert(rb);
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
colliders.insert(collider, ball_handle, &mut bodies);
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
let mut linvel = Vector3::zeros();
let mut angvel = Vector3::zeros();
let mut pos = Isometry3::identity();
let mut linvel = Vector::zeros();
let mut angvel = Vector::zeros();
let mut pos = Isometry::identity();
let mut step = 0;
let snapped_frame = 51;
@@ -68,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Isometry3, Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -17,30 +15,30 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
.friction(0.15)
// .restitution(0.5)
.build();
colliders.insert(collider, ground_handle, &mut bodies);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Rolling ball
*/
let ball_rad = 0.1;
let rb = RigidBodyBuilder::new_dynamic()
.translation(0.0, 0.2, 0.0)
.linvel(10.0, 0.0, 0.0)
.translation(vector![0.0, 0.2, 0.0])
.linvel(vector![10.0, 0.0, 0.0])
.build();
let ball_handle = bodies.insert(rb);
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
let ball_coll_handle = colliders.insert(collider, ball_handle, &mut bodies);
let ball_coll_handle = colliders.insert_with_parent(collider, ball_handle, &mut bodies);
let mut linvel = Vector3::zeros();
let mut angvel = Vector3::zeros();
let mut pos = Isometry3::identity();
let mut linvel = Vector::zeros();
let mut angvel = Vector::zeros();
let mut pos = Isometry::identity();
let mut step = 0;
let snapped_frame = 51;
@@ -90,7 +88,9 @@ pub fn init_world(testbed: &mut Testbed) {
let z = k as f32 * shiftz - centerz + offset;
// 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 % 5 {
@@ -103,7 +103,7 @@ pub fn init_world(testbed: &mut Testbed) {
_ => ColliderBuilder::capsule_y(rad, rad).build(),
};
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
@@ -114,5 +114,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -13,31 +11,31 @@ pub fn init_world(testbed: &mut Testbed) {
// Triangle ground.
let vtx = [
Point3::new(-10.0, 0.0, -10.0),
Point3::new(10.0, 0.0, -10.0),
Point3::new(0.0, 0.0, 10.0),
point![-10.0, 0.0, -10.0],
point![10.0, 0.0, -10.0],
point![0.0, 0.0, 10.0],
];
let rigid_body = RigidBodyBuilder::new_static()
.translation(0.0, 0.0, 0.0)
.translation(vector![0.0, 0.0, 0.0])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::triangle(vtx[0], vtx[1], vtx[2]).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
// Dynamic box rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(1.1, 0.01, 0.0)
.translation(vector![1.1, 0.01, 0.0])
// .rotation(Vector3::new(0.8, 0.2, 0.1))
.can_sleep(false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(20.0, 0.1, 1.0).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -14,14 +12,14 @@ pub fn init_world(testbed: &mut Testbed) {
// Triangle ground.
let width = 0.5;
let vtx = vec![
Point3::new(-width, 0.0, -width),
Point3::new(width, 0.0, -width),
Point3::new(width, 0.0, width),
Point3::new(-width, 0.0, width),
Point3::new(-width, -width, -width),
Point3::new(width, -width, -width),
Point3::new(width, -width, width),
Point3::new(-width, -width, width),
point![-width, 0.0, -width],
point![width, 0.0, -width],
point![width, 0.0, width],
point![-width, 0.0, width],
point![-width, -width, -width],
point![width, -width, -width],
point![width, -width, width],
point![-width, -width, width],
];
let idx = vec![
[0, 2, 1],
@@ -40,25 +38,25 @@ pub fn init_world(testbed: &mut Testbed) {
// Dynamic box rigid body.
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 35.0, 0.0)
.translation(vector![0.0, 35.0, 0.0])
// .rotation(Vector3::new(0.8, 0.2, 0.1))
.can_sleep(false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.0).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::new_static()
.translation(0.0, 0.0, 0.0)
.translation(vector![0.0, 0.0, 0.0])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::trimesh(vtx, idx).build();
colliders.insert(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, Point3::new(0.3, 0.3, 0.3));
colliders.insert_with_parent(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, [0.3, 0.3, 0.3]);
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Translation3, UnitQuaternion, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ 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
@@ -31,7 +29,7 @@ pub fn init_world(testbed: &mut Testbed) {
let width = 1.0;
let thickness = 0.1;
let colors = [Point3::new(0.7, 0.5, 0.9), Point3::new(0.6, 1.0, 0.6)];
let colors = [[0.7, 0.5, 0.9], [0.6, 1.0, 0.6]];
let mut curr_angle = 0.0;
let mut curr_rad = 10.0;
@@ -50,16 +48,16 @@ pub fn init_world(testbed: &mut Testbed) {
let tilt = if nudged || i == num - 1 { 0.2 } else { 0.0 };
if skip == 0 {
let rot = UnitQuaternion::new(Vector3::y() * curr_angle);
let tilt = UnitQuaternion::new(rot * Vector3::z() * tilt);
let rot = Rotation::new(Vector::y() * curr_angle);
let tilt = Rotation::new(rot * Vector::z() * tilt);
let position =
Translation3::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad)
Translation::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad)
* tilt
* rot;
let rigid_body = RigidBodyBuilder::new_dynamic().position(position).build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, colors[i % 2]);
} else {
skip -= 1;
@@ -76,5 +74,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());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
const MAX_NUMBER_OF_BODIES: usize = 400;
@@ -18,16 +16,16 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_height = 2.1; // 16.0;
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);
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |mut graphics, physics, _, run_state| {
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 10.0, 0.0)
.translation(vector![0.0, 10.0, 0.0])
.build();
let handle = physics.bodies.insert(rigid_body);
let collider = match run_state.timestep_id % 3 {
@@ -38,7 +36,7 @@ pub fn init_world(testbed: &mut Testbed) {
physics
.colliders
.insert(collider, handle, &mut physics.bodies);
.insert_with_parent(collider, handle, &mut physics.bodies);
if let Some(graphics) = &mut graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
@@ -83,5 +81,5 @@ pub fn init_world(testbed: &mut Testbed) {
// .physics_state_mut()
// .integration_parameters
// .velocity_based_erp = 0.2;
testbed.look_at(Point3::new(-30.0, 4.0, -30.0), Point3::new(0.0, 1.0, 0.0));
testbed.look_at(point![-30.0, 4.0, -30.0], point![0.0, 1.0, 0.0]);
}

View File

@@ -1,7 +1,4 @@
extern crate nalgebra as na;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::harness::Harness;
pub fn init_world(harness: &mut Harness) {
@@ -19,11 +16,11 @@ pub fn init_world(harness: &mut Harness) {
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
@@ -47,10 +44,12 @@ pub fn init_world(harness: &mut Harness) {
let z = k as f32 * shift - centerz + offset;
// 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 = ColliderBuilder::capsule_y(rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}

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());
}

View File

@@ -1,49 +1,44 @@
use na::{Isometry3, Point3, Unit, UnitQuaternion, Vector3};
use rapier3d::dynamics::{
BallJoint, FixedJoint, JointSet, PrismaticJoint, RevoluteJoint, RigidBodyBuilder,
RigidBodyHandle, RigidBodySet, RigidBodyType,
};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
fn create_prismatic_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
let shift = 2.0;
let ground = RigidBodyBuilder::new_static()
.translation(origin.x, origin.y, origin.z)
.translation(vector![origin.x, origin.y, origin.z])
.build();
let mut curr_parent = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, curr_parent, bodies);
colliders.insert_with_parent(collider, curr_parent, bodies);
for i in 0..num {
let z = origin.z + (i + 1) as f32 * shift;
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(origin.x, origin.y, z)
.translation(vector![origin.x, origin.y, z])
.build();
let curr_child = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, curr_child, bodies);
colliders.insert_with_parent(collider, curr_child, bodies);
let axis = if i % 2 == 0 {
Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0))
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
} else {
Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0))
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
};
let z = Vector3::z();
let z = Vector::z();
let mut prism = PrismaticJoint::new(
Point3::new(0.0, 0.0, 0.0),
point![0.0, 0.0, 0.0],
axis,
z,
Point3::new(0.0, 0.0, -shift),
point![0.0, 0.0, -shift],
axis,
z,
);
@@ -61,40 +56,40 @@ fn create_actuated_prismatic_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
let shift = 2.0;
let ground = RigidBodyBuilder::new_static()
.translation(origin.x, origin.y, origin.z)
.translation(vector![origin.x, origin.y, origin.z])
.build();
let mut curr_parent = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, curr_parent, bodies);
colliders.insert_with_parent(collider, curr_parent, bodies);
for i in 0..num {
let z = origin.z + (i + 1) as f32 * shift;
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(origin.x, origin.y, z)
.translation(vector![origin.x, origin.y, z])
.build();
let curr_child = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, curr_child, bodies);
colliders.insert_with_parent(collider, curr_child, bodies);
let axis = if i % 2 == 0 {
Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0))
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
} else {
Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0))
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
};
let z = Vector3::z();
let z = Vector::z();
let mut prism = PrismaticJoint::new(
Point3::new(0.0, 0.0, 0.0),
point![0.0, 0.0, 0.0],
axis,
z,
Point3::new(0.0, 0.0, -shift),
point![0.0, 0.0, -shift],
axis,
z,
);
@@ -128,27 +123,27 @@ fn create_revolute_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
let shift = 2.0;
let ground = RigidBodyBuilder::new_static()
.translation(origin.x, origin.y, 0.0)
.translation(vector![origin.x, origin.y, 0.0])
.build();
let mut curr_parent = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, curr_parent, bodies);
colliders.insert_with_parent(collider, curr_parent, bodies);
for i in 0..num {
// Create four bodies.
let z = origin.z + i as f32 * shift * 2.0 + shift;
let positions = [
Isometry3::translation(origin.x, origin.y, z),
Isometry3::translation(origin.x + shift, origin.y, z),
Isometry3::translation(origin.x + shift, origin.y, z + shift),
Isometry3::translation(origin.x, origin.y, z + shift),
Isometry::translation(origin.x, origin.y, z),
Isometry::translation(origin.x + shift, origin.y, z),
Isometry::translation(origin.x + shift, origin.y, z + shift),
Isometry::translation(origin.x, origin.y, z + shift),
];
let mut handles = [curr_parent; 4];
@@ -158,19 +153,19 @@ fn create_revolute_joints(
.build();
handles[k] = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, handles[k], bodies);
colliders.insert_with_parent(collider, handles[k], bodies);
}
// Setup four joints.
let o = Point3::origin();
let x = Vector3::x_axis();
let z = Vector3::z_axis();
let o = Point::origin();
let x = Vector::x_axis();
let z = Vector::z_axis();
let revs = [
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x),
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x),
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x),
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x),
];
joints.insert(bodies, curr_parent, handles[0], revs[0]);
@@ -186,7 +181,7 @@ fn create_fixed_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
@@ -209,18 +204,22 @@ fn create_fixed_joints(
};
let rigid_body = RigidBodyBuilder::new(status)
.translation(origin.x + fk * shift, origin.y, origin.z + fi * shift)
.translation(vector![
origin.x + fk * shift,
origin.y,
origin.z + fi * shift
])
.build();
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad).build();
colliders.insert(collider, child_handle, bodies);
colliders.insert_with_parent(collider, child_handle, bodies);
// Vertical joint.
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint = FixedJoint::new(
Isometry3::identity(),
Isometry3::translation(0.0, 0.0, -shift),
Isometry::identity(),
Isometry::translation(0.0, 0.0, -shift),
);
joints.insert(bodies, parent_handle, child_handle, joint);
}
@@ -230,8 +229,8 @@ fn create_fixed_joints(
let parent_index = body_handles.len() - num;
let parent_handle = body_handles[parent_index];
let joint = FixedJoint::new(
Isometry3::identity(),
Isometry3::translation(-shift, 0.0, 0.0),
Isometry::identity(),
Isometry::translation(-shift, 0.0, 0.0),
);
joints.insert(bodies, parent_handle, child_handle, joint);
}
@@ -264,16 +263,16 @@ fn create_ball_joints(
};
let rigid_body = RigidBodyBuilder::new(status)
.translation(fk * shift, 0.0, fi * shift * 2.0)
.translation(vector![fk * shift, 0.0, fi * shift * 2.0])
.build();
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_z(rad * 1.25, rad).build();
colliders.insert(collider, child_handle, bodies);
colliders.insert_with_parent(collider, child_handle, bodies);
// Vertical joint.
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint = BallJoint::new(Point3::origin(), Point3::new(0.0, 0.0, -shift * 2.0));
let joint = BallJoint::new(Point::origin(), point![0.0, 0.0, -shift * 2.0]);
joints.insert(bodies, parent_handle, child_handle, joint);
}
@@ -281,7 +280,7 @@ fn create_ball_joints(
if k > 0 {
let parent_index = body_handles.len() - num;
let parent_handle = body_handles[parent_index];
let joint = BallJoint::new(Point3::origin(), Point3::new(-shift, 0.0, 0.0));
let joint = BallJoint::new(Point::origin(), point![-shift, 0.0, 0.0]);
joints.insert(bodies, parent_handle, child_handle, joint);
}
@@ -294,7 +293,7 @@ fn create_actuated_revolute_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
@@ -302,10 +301,10 @@ fn create_actuated_revolute_joints(
// We will reuse this base configuration for all the joints here.
let joint_template = RevoluteJoint::new(
Point3::origin(),
Vector3::z_axis(),
Point3::new(0.0, 0.0, -shift),
Vector3::z_axis(),
Point::origin(),
Vector::z_axis(),
point![0.0, 0.0, -shift],
Vector::z_axis(),
);
let mut parent_handle = RigidBodyHandle::invalid();
@@ -325,13 +324,13 @@ fn create_actuated_revolute_joints(
let shifty = (i >= 1) as u32 as f32 * -2.0;
let rigid_body = RigidBodyBuilder::new(status)
.translation(origin.x, origin.y + shifty, origin.z + fi * shift)
.translation(vector![origin.x, origin.y + shifty, origin.z + fi * shift])
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
.build();
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad * 2.0, rad * 6.0 / (fi + 1.0), rad).build();
colliders.insert(collider, child_handle, bodies);
colliders.insert_with_parent(collider, child_handle, bodies);
if i > 0 {
let mut joint = joint_template.clone();
@@ -360,14 +359,14 @@ fn create_actuated_ball_joints(
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
joints: &mut JointSet,
origin: Point3<f32>,
origin: Point<f32>,
num: usize,
) {
let rad = 0.4;
let shift = 2.0;
// We will reuse this base configuration for all the joints here.
let joint_template = BallJoint::new(Point3::new(0.0, 0.0, shift), Point3::origin());
let joint_template = BallJoint::new(point![0.0, 0.0, shift], Point::origin());
let mut parent_handle = RigidBodyHandle::invalid();
@@ -384,24 +383,24 @@ fn create_actuated_ball_joints(
};
let rigid_body = RigidBodyBuilder::new(status)
.translation(origin.x, origin.y, origin.z + fi * shift)
.translation(vector![origin.x, origin.y, origin.z + fi * shift])
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
.build();
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(rad * 2.0 / (fi + 1.0), rad).build();
colliders.insert(collider, child_handle, bodies);
colliders.insert_with_parent(collider, child_handle, bodies);
if i > 0 {
let mut joint = joint_template.clone();
if i == 1 {
joint.configure_motor_velocity(Vector3::new(0.0, 0.5, -2.0), 0.1);
joint.configure_motor_velocity(vector![0.0, 0.5, -2.0], 0.1);
} else if i == num - 1 {
let stiffness = 0.2;
let damping = 1.0;
joint.configure_motor_position(
UnitQuaternion::new(Vector3::new(0.0, 1.0, 3.14 / 2.0)),
Rotation::new(vector![0.0, 1.0, 3.14 / 2.0]),
stiffness,
damping,
);
@@ -426,42 +425,42 @@ pub fn init_world(testbed: &mut Testbed) {
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(20.0, 5.0, 0.0),
point![20.0, 5.0, 0.0],
4,
);
create_actuated_prismatic_joints(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(25.0, 5.0, 0.0),
point![25.0, 5.0, 0.0],
4,
);
create_revolute_joints(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(20.0, 0.0, 0.0),
point![20.0, 0.0, 0.0],
3,
);
create_fixed_joints(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(0.0, 10.0, 0.0),
point![0.0, 10.0, 0.0],
10,
);
create_actuated_revolute_joints(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(20.0, 10.0, 0.0),
point![20.0, 10.0, 0.0],
6,
);
create_actuated_ball_joints(
&mut bodies,
&mut colliders,
&mut joints,
Point3::new(13.0, 10.0, 0.0),
point![13.0, 10.0, 0.0],
3,
);
create_ball_joints(&mut bodies, &mut colliders, &mut joints, 15);
@@ -470,5 +469,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(15.0, 5.0, 42.0), Point3::new(13.0, 1.0, 1.0));
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
}

View File

@@ -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());
}

View File

@@ -1,6 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
// This shows a bug when a cylinder is in contact with a very large
@@ -21,41 +19,41 @@ 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);
/*
* A rectangle that only rotates along the `x` axis.
*/
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 3.0, 0.0)
.translation(vector![0.0, 3.0, 0.0])
.lock_translations()
.restrict_rotations(true, false, false)
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.2, 0.6, 2.0).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* A tilted capsule that cannot rotate.
*/
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 5.0, 0.0)
.rotation(Vector3::x() * 1.0)
.translation(vector![0.0, 5.0, 0.0])
.rotation(Vector::x() * 1.0)
.lock_rotations()
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(0.6, 0.4).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let collider = ColliderBuilder::capsule_x(0.6, 0.4).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 3.0, 0.0), Point3::new(0.0, 3.0, 0.0));
testbed.look_at(point![10.0, 3.0, 0.0], point![0.0, 3.0, 0.0]);
}

View File

@@ -1,7 +1,4 @@
use na::{Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet};
use rapier3d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
struct OneWayPlatformHook {
@@ -10,10 +7,6 @@ struct OneWayPlatformHook {
}
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
fn active_hooks(&self) -> PhysicsHooksFlags {
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
}
fn modify_solver_contacts(
&self,
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
@@ -30,20 +23,20 @@ impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
// - If context.collider2 == self.platform1 then the allowed normal is -y.
// - If context.collider1 == self.platform2 then its allowed normal +y needs to be flipped to -y.
// - If context.collider2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
let mut allowed_local_n1 = Vector3::zeros();
let mut allowed_local_n1 = Vector::zeros();
if context.collider1 == self.platform1 {
allowed_local_n1 = Vector3::y();
allowed_local_n1 = Vector::y();
} else if context.collider2 == self.platform1 {
// Flip the allowed direction.
allowed_local_n1 = -Vector3::y();
allowed_local_n1 = -Vector::y();
}
if context.collider1 == self.platform2 {
allowed_local_n1 = -Vector3::y();
allowed_local_n1 = -Vector::y();
} else if context.collider2 == self.platform2 {
// Flip the allowed direction.
allowed_local_n1 = Vector3::y();
allowed_local_n1 = Vector::y();
}
// Call the helper function that simulates one-way platforms.
@@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) {
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
.translation(0.0, 2.0, 30.0)
.modify_solver_contacts(true)
.translation(vector![0.0, 2.0, 30.0])
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
.build();
let platform1 = colliders.insert(collider, handle, &mut bodies);
let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies);
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
.translation(0.0, -2.0, -30.0)
.modify_solver_contacts(true)
.translation(vector![0.0, -2.0, -30.0])
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
.build();
let platform2 = colliders.insert(collider, handle, &mut bodies);
let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Setup the one-way platform hook.
@@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) {
// Spawn a new cube.
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build();
let body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 6.0, 20.0)
.translation(vector![0.0, 6.0, 20.0])
.build();
let handle = physics.bodies.insert(body);
physics
.colliders
.insert(collider, handle, &mut physics.bodies);
.insert_with_parent(collider, handle, &mut physics.bodies);
if let Some(graphics) = graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
@@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) {
bodies,
colliders,
joints,
Vector3::new(0.0, -9.81, 0.0),
vector![0.0, -9.81, 0.0],
physics_hooks,
);
testbed.look_at(Point3::new(-100.0, 0.0, 0.0), Point3::origin());
testbed.look_at(point![-100.0, 0.0, 0.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ 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 boxes
@@ -43,10 +41,12 @@ 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 = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -55,11 +55,11 @@ pub fn init_world(testbed: &mut Testbed) {
* Setup a kinematic rigid body.
*/
let platform_body = RigidBodyBuilder::new_kinematic()
.translation(0.0, 1.5 + 0.8, -10.0 * rad)
.translation(vector![0.0, 1.5 + 0.8, -10.0 * rad])
.build();
let platform_handle = bodies.insert(platform_body);
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build();
colliders.insert(collider, platform_handle, &mut bodies);
colliders.insert_with_parent(collider, platform_handle, &mut bodies);
/*
* Setup a callback to control the platform.
@@ -93,5 +93,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Run the simulation.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(-10.0, 5.0, -10.0), Point3::origin());
testbed.look_at(point![-10.0, 5.0, -10.0], Point::origin());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_height = 2.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 primitives
@@ -47,7 +45,9 @@ pub fn init_world(testbed: &mut Testbed) {
let z = k as f32 * shiftz - centerz + offset;
// 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 % 5 {
@@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
_ => ColliderBuilder::capsule_y(rad, rad).build(),
};
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
@@ -71,5 +71,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());
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_height = 1.0;
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, 2.0)
.restitution(1.0)
.build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
let num = 10;
let rad = 0.5;
@@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) {
for i in 0..=num {
let x = (i as f32) - num as f32 / 2.0;
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(x * 2.0, 10.0 * (j as f32 + 1.0), 0.0)
.translation(vector![x * 2.0, 10.0 * (j as f32 + 1.0), 0.0])
.build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad)
.restitution((i as f32) / (num as f32))
.build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
@@ -47,5 +45,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(0.0, 3.0, 30.0), Point3::new(0.0, 3.0, 0.0));
testbed.look_at(point![0.0, 3.0, 30.0], point![0.0, 3.0, 0.0]);
}

View File

@@ -1,6 +1,4 @@
use na::Point3;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
@@ -18,11 +16,11 @@ 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 ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
colliders.insert(collider, ground_handle, &mut bodies);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create some boxes.
@@ -41,12 +39,14 @@ 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 = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0));
testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]);
}
}
@@ -56,33 +56,36 @@ pub fn init_world(testbed: &mut Testbed) {
// Rigid body so that the sensor can move.
let sensor = RigidBodyBuilder::new_dynamic()
.translation(0.0, 5.0, 0.0)
.translation(vector![0.0, 5.0, 0.0])
.build();
let sensor_handle = bodies.insert(sensor);
// Solid cube attached to the sensor which
// other colliders can touch.
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, sensor_handle, &mut bodies);
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
// We create a collider desc without density because we don't
// want it to contribute to the rigid body mass.
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
let sensor_collider = ColliderBuilder::ball(rad * 5.0)
.density(0.0)
.sensor(true)
.build();
colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies);
testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0));
testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]);
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |mut graphics, physics, events, _| {
while let Ok(prox) = events.intersection_events.try_recv() {
let color = if prox.intersecting {
Point3::new(1.0, 1.0, 0.0)
[1.0, 1.0, 0.0]
} else {
Point3::new(0.5, 0.5, 1.0)
[0.5, 0.5, 1.0]
};
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
let parent_handle1 = physics.colliders[prox.collider1].parent().unwrap();
let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap();
if let Some(graphics) = &mut graphics {
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
@@ -99,5 +102,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(-6.0, 4.0, -6.0), Point3::new(0.0, 1.0, 0.0));
testbed.look_at(point![-6.0, 4.0, -6.0], point![0.0, 1.0, 0.0]);
}

View File

@@ -1,6 +1,5 @@
use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3};
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField, 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![100.0, 1.0, 100.0];
let nsubdivs = 20;
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
@@ -39,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::new_static().build();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::trimesh(vertices, indices).build();
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
@@ -60,7 +59,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 {
@@ -74,15 +75,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),
),
];
@@ -91,7 +92,7 @@ pub fn init_world(testbed: &mut Testbed) {
}
};
colliders.insert(collider, handle, &mut bodies);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
@@ -100,5 +101,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());
}