aboutsummaryrefslogtreecommitdiff
path: root/src_testbed
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-26 15:12:10 +0100
committerCrozet Sébastien <developer@crozet.re>2020-10-26 15:12:10 +0100
commit3da333f11c93898808eb9233c0cf333743bbf906 (patch)
tree0ef0972450f615125c64f4cc8742d5486ce71e45 /src_testbed
parente028f4504065b228bea8b736265e8b1bfb58f7f3 (diff)
downloadrapier-3da333f11c93898808eb9233c0cf333743bbf906.tar.gz
rapier-3da333f11c93898808eb9233c0cf333743bbf906.tar.bz2
rapier-3da333f11c93898808eb9233c0cf333743bbf906.zip
Fix testbed compilation with other backends.
Diffstat (limited to 'src_testbed')
-rw-r--r--src_testbed/box2d_backend.rs74
-rw-r--r--src_testbed/nphysics_backend.rs48
-rw-r--r--src_testbed/physx_backend.rs38
3 files changed, 80 insertions, 80 deletions
diff --git a/src_testbed/box2d_backend.rs b/src_testbed/box2d_backend.rs
index c25ff1f..9156c2a 100644
--- a/src_testbed/box2d_backend.rs
+++ b/src_testbed/box2d_backend.rs
@@ -167,44 +167,42 @@ impl Box2dWorld {
fixture_def.is_sensor = collider.is_sensor();
fixture_def.filter = b2::Filter::new();
- match collider.shape() {
- Shape::Ball(b) => {
- let mut b2_shape = b2::CircleShape::new();
- b2_shape.set_radius(b.radius);
- b2_shape.set_position(center);
- body.create_fixture(&b2_shape, &mut fixture_def);
- }
- Shape::Cuboid(c) => {
- let b2_shape = b2::PolygonShape::new_box(c.half_extents.x, c.half_extents.y);
- body.create_fixture(&b2_shape, &mut fixture_def);
- }
- Shape::Polygon(poly) => {
- let points: Vec<_> = poly
- .vertices()
- .iter()
- .map(|p| collider.position_wrt_parent() * p)
- .map(|p| na_vec_to_b2_vec(p.coords))
- .collect();
- let b2_shape = b2::PolygonShape::new_with(&points);
- body.create_fixture(&b2_shape, &mut fixture_def);
- }
- Shape::HeightField(heightfield) => {
- let mut segments = heightfield.segments();
- let seg1 = segments.next().unwrap();
- let mut vertices = vec![
- na_vec_to_b2_vec(seg1.a.coords),
- na_vec_to_b2_vec(seg1.b.coords),
- ];
-
- // TODO: this will not handle holes properly.
- segments.for_each(|seg| {
- vertices.push(na_vec_to_b2_vec(seg.b.coords));
- });
-
- let b2_shape = b2::ChainShape::new_chain(&vertices);
- body.create_fixture(&b2_shape, &mut fixture_def);
- }
- _ => eprintln!("Creating a shape unknown to the Box2d backend."),
+ let shape = collider.shape();
+
+ if let Some(b) = shape.as_ball() {
+ let mut b2_shape = b2::CircleShape::new();
+ b2_shape.set_radius(b.radius);
+ b2_shape.set_position(center);
+ body.create_fixture(&b2_shape, &mut fixture_def);
+ } else if let Some(c) = shape.as_cuboid() {
+ let b2_shape = b2::PolygonShape::new_box(c.half_extents.x, c.half_extents.y);
+ body.create_fixture(&b2_shape, &mut fixture_def);
+ // } else if let Some(polygon) = shape.as_polygon() {
+ // let points: Vec<_> = poly
+ // .vertices()
+ // .iter()
+ // .map(|p| collider.position_wrt_parent() * p)
+ // .map(|p| na_vec_to_b2_vec(p.coords))
+ // .collect();
+ // let b2_shape = b2::PolygonShape::new_with(&points);
+ // body.create_fixture(&b2_shape, &mut fixture_def);
+ } else if let Some(heightfield) = shape.as_heightfield() {
+ let mut segments = heightfield.segments();
+ let seg1 = segments.next().unwrap();
+ let mut vertices = vec![
+ na_vec_to_b2_vec(seg1.a.coords),
+ na_vec_to_b2_vec(seg1.b.coords),
+ ];
+
+ // TODO: this will not handle holes properly.
+ segments.for_each(|seg| {
+ vertices.push(na_vec_to_b2_vec(seg.b.coords));
+ });
+
+ let b2_shape = b2::ChainShape::new_chain(&vertices);
+ body.create_fixture(&b2_shape, &mut fixture_def);
+ } else {
+ eprintln!("Creating a shape unknown to the Box2d backend.");
}
}
diff --git a/src_testbed/nphysics_backend.rs b/src_testbed/nphysics_backend.rs
index c2a7fb1..b449c44 100644
--- a/src_testbed/nphysics_backend.rs
+++ b/src_testbed/nphysics_backend.rs
@@ -177,28 +177,36 @@ fn nphysics_collider_from_rapier_collider(
) -> Option<ColliderDesc<f32>> {
let margin = ColliderDesc::<f32>::default_margin();
let mut pos = *collider.position_wrt_parent();
-
- let shape = match collider.shape() {
- Shape::Cuboid(cuboid) => {
- ShapeHandle::new(Cuboid::new(cuboid.half_extents.map(|e| e - margin)))
+ let shape = collider.shape();
+
+ let shape = if let Some(cuboid) = shape.as_cuboid() {
+ ShapeHandle::new(Cuboid::new(cuboid.half_extents.map(|e| e - margin)))
+ } else if let Some(ball) = shape.as_ball() {
+ ShapeHandle::new(Ball::new(ball.radius - margin))
+ } else if let Some(capsule) = shape.as_capsule() {
+ ShapeHandle::new(Capsule::new(capsule.half_height, capsule.radius))
+ } else if let Some(heightfield) = shape.as_heightfield() {
+ ShapeHandle::new(heightfield.clone())
+ } else {
+ #[cfg(feature = "dim3")]
+ if let Some(trimesh) = shape.as_trimesh() {
+ ShapeHandle::new(TriMesh::new(
+ trimesh.vertices().to_vec(),
+ trimesh
+ .indices()
+ .iter()
+ .map(|idx| na::convert(*idx))
+ .collect(),
+ None,
+ ))
+ } else {
+ return None;
}
- Shape::Ball(ball) => ShapeHandle::new(Ball::new(ball.radius - margin)),
- Shape::Capsule(capsule) => {
- pos *= capsule.transform_wrt_y();
- ShapeHandle::new(Capsule::new(capsule.half_height(), capsule.radius))
+
+ #[cfg(feature = "dim2")]
+ {
+ return None;
}
- Shape::HeightField(heightfield) => ShapeHandle::new(heightfield.clone()),
- #[cfg(feature = "dim3")]
- Shape::Trimesh(trimesh) => ShapeHandle::new(TriMesh::new(
- trimesh.vertices().to_vec(),
- trimesh
- .indices()
- .iter()
- .map(|idx| na::convert(*idx))
- .collect(),
- None,
- )),
- _ => return None,
};
let density = if is_dynamic { collider.density() } else { 0.0 };
diff --git a/src_testbed/physx_backend.rs b/src_testbed/physx_backend.rs
index ec2e2bf..822ad08 100644
--- a/src_testbed/physx_backend.rs
+++ b/src_testbed/physx_backend.rs
@@ -422,27 +422,22 @@ fn physx_collider_from_rapier_collider(
collider: &Collider,
) -> Option<(ColliderDesc, Isometry3<f32>)> {
let mut local_pose = *collider.position_wrt_parent();
- let desc = match collider.shape() {
- Shape::Cuboid(cuboid) => ColliderDesc::Box(
+ let shape = collider.shape();
+
+ let desc = if let Some(cuboid) = shape.as_cuboid() {
+ ColliderDesc::Box(
cuboid.half_extents.x,
cuboid.half_extents.y,
cuboid.half_extents.z,
- ),
- Shape::Ball(ball) => ColliderDesc::Sphere(ball.radius),
- Shape::Capsule(capsule) => {
- let center = capsule.center();
- let mut dir = capsule.b - capsule.a;
-
- if dir.x < 0.0 {
- dir = -dir;
- }
-
- let rot = UnitQuaternion::rotation_between(&Vector3::x(), &dir);
- local_pose *=
- Translation3::from(center.coords) * rot.unwrap_or(UnitQuaternion::identity());
- ColliderDesc::Capsule(capsule.radius, capsule.height())
- }
- Shape::Trimesh(trimesh) => ColliderDesc::TriMesh {
+ )
+ } else if let Some(ball) = shape.as_ball() {
+ ColliderDesc::Sphere(ball.radius)
+ } else if let Some(capsule) = shape.as_capsule() {
+ let rot = UnitQuaternion::rotation_between(&Vector3::x(), &Vector3::y());
+ local_pose *= rot.unwrap_or(UnitQuaternion::identity());
+ ColliderDesc::Capsule(capsule.radius, capsule.height())
+ } else if let Some(trimesh) = shape.as_trimesh() {
+ ColliderDesc::TriMesh {
vertices: trimesh
.vertices()
.iter()
@@ -450,11 +445,10 @@ fn physx_collider_from_rapier_collider(
.collect(),
indices: trimesh.flat_indices().to_vec(),
mesh_scale: Vector3::repeat(1.0).into_glam(),
- },
- _ => {
- eprintln!("Creating a shape unknown to the PhysX backend.");
- return None;
}
+ } else {
+ eprintln!("Creating a shape unknown to the PhysX backend.");
+ return None;
};
Some((desc, local_pose))