aboutsummaryrefslogtreecommitdiff
path: root/src_testbed
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-20 11:55:33 +0200
committerCrozet Sébastien <developer@crozet.re>2020-10-20 11:56:09 +0200
commit865ce8a8e5301b23ca474adaaffe8b43e725803e (patch)
tree67b57d0c63d11a6d5e4a23c6f1242f72efc721b9 /src_testbed
parent947c4813c9666fd8215743de298fe17780fa3ef2 (diff)
downloadrapier-865ce8a8e5301b23ca474adaaffe8b43e725803e.tar.gz
rapier-865ce8a8e5301b23ca474adaaffe8b43e725803e.tar.bz2
rapier-865ce8a8e5301b23ca474adaaffe8b43e725803e.zip
Collider shape: use a trait-object instead of an enum.
Diffstat (limited to 'src_testbed')
-rw-r--r--src_testbed/engine.rs65
1 files changed, 41 insertions, 24 deletions
diff --git a/src_testbed/engine.rs b/src_testbed/engine.rs
index ca2d71f..ca1a2b8 100644
--- a/src_testbed/engine.rs
+++ b/src_testbed/engine.rs
@@ -350,33 +350,44 @@ impl GraphicsManager {
color: Point3<f32>,
out: &mut Vec<Node>,
) {
- match collider.shape() {
- Shape::Ball(ball) => {
- out.push(Node::Ball(Ball::new(handle, ball.radius, color, window)))
- }
- Shape::Polygon(poly) => out.push(Node::Convex(Convex::new(
- handle,
- poly.vertices().to_vec(),
- color,
- window,
- ))),
- Shape::Cuboid(cuboid) => out.push(Node::Box(BoxNode::new(
+ let shape = collider.shape();
+
+ if let Some(ball) = shape.as_ball() {
+ out.push(Node::Ball(Ball::new(handle, ball.radius, color, window)))
+ }
+
+ // Shape::Polygon(poly) => out.push(Node::Convex(Convex::new(
+ // handle,
+ // poly.vertices().to_vec(),
+ // color,
+ // window,
+ // ))),
+
+ if let Some(cuboid) = shape.as_cuboid() {
+ out.push(Node::Box(BoxNode::new(
handle,
cuboid.half_extents,
color,
window,
- ))),
- Shape::Capsule(capsule) => {
- out.push(Node::Capsule(Capsule::new(handle, capsule, color, window)))
- }
- Shape::Triangle(triangle) => out.push(Node::Mesh(Mesh::new(
+ )))
+ }
+
+ if let Some(capsule) = shape.as_capsule() {
+ out.push(Node::Capsule(Capsule::new(handle, capsule, color, window)))
+ }
+
+ if let Some(triangle) = shape.as_triangle() {
+ out.push(Node::Mesh(Mesh::new(
handle,
vec![triangle.a, triangle.b, triangle.c],
vec![Point3::new(0, 1, 2)],
color,
window,
- ))),
- Shape::Trimesh(trimesh) => out.push(Node::Mesh(Mesh::new(
+ )))
+ }
+
+ if let Some(trimesh) = shape.as_trimesh() {
+ out.push(Node::Mesh(Mesh::new(
handle,
trimesh.vertices().to_vec(),
trimesh
@@ -386,21 +397,27 @@ impl GraphicsManager {
.collect(),
color,
window,
- ))),
- Shape::HeightField(heightfield) => out.push(Node::HeightField(HeightField::new(
+ )))
+ }
+
+ if let Some(heightfield) = shape.as_heightfield() {
+ out.push(Node::HeightField(HeightField::new(
handle,
heightfield,
color,
window,
- ))),
- #[cfg(feature = "dim3")]
- Shape::Cylinder(cylinder) => out.push(Node::Cylinder(Cylinder::new(
+ )))
+ }
+
+ #[cfg(feature = "dim3")]
+ if let Some(cylinder) = shape.as_cylinder() {
+ out.push(Node::Cylinder(Cylinder::new(
handle,
cylinder.half_height,
cylinder.radius,
color,
window,
- ))),
+ )))
}
}