Collider shape: use a trait-object instead of an enum.
This commit is contained in:
@@ -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,
|
||||
))),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user