Add convex polygons support.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "dim2")]
|
||||
use ncollide::shape::ConvexPolygon;
|
||||
use ncollide::shape::{Ball, Capsule, Cuboid, HeightField, ShapeHandle};
|
||||
use nphysics::force_generator::DefaultForceGeneratorSet;
|
||||
use nphysics::joint::{
|
||||
@@ -144,6 +146,7 @@ impl NPhysicsWorld {
|
||||
self.mechanical_world
|
||||
.integration_parameters
|
||||
.set_dt(params.dt());
|
||||
self.mechanical_world.integration_parameters.warmstart_coeff = params.warmstart_coeff;
|
||||
|
||||
counters.step_started();
|
||||
self.mechanical_world.step(
|
||||
@@ -175,12 +178,15 @@ fn nphysics_collider_from_rapier_collider(
|
||||
collider: &Collider,
|
||||
is_dynamic: bool,
|
||||
) -> Option<ColliderDesc<f32>> {
|
||||
let margin = ColliderDesc::<f32>::default_margin();
|
||||
let mut margin = ColliderDesc::<f32>::default_margin();
|
||||
let mut pos = *collider.position_wrt_parent();
|
||||
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(cuboid) = shape.as_round_cuboid() {
|
||||
margin = cuboid.border_radius;
|
||||
ShapeHandle::new(Cuboid::new(cuboid.base_shape.half_extents))
|
||||
} else if let Some(ball) = shape.as_ball() {
|
||||
ShapeHandle::new(Ball::new(ball.radius - margin))
|
||||
} else if let Some(capsule) = shape.as_capsule() {
|
||||
@@ -208,7 +214,12 @@ fn nphysics_collider_from_rapier_collider(
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim2")]
|
||||
{
|
||||
if let Some(polygon) = shape.as_round_convex_polygon() {
|
||||
margin = polygon.border_radius;
|
||||
ShapeHandle::new(ConvexPolygon::try_from_points(polygon.base_shape.points()).unwrap())
|
||||
} else if let Some(polygon) = shape.as_convex_polygon() {
|
||||
ShapeHandle::new(ConvexPolygon::try_from_points(polygon.points()).unwrap())
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
@@ -219,6 +230,7 @@ fn nphysics_collider_from_rapier_collider(
|
||||
ColliderDesc::new(shape)
|
||||
.position(pos)
|
||||
.density(density)
|
||||
.sensor(collider.is_sensor()),
|
||||
.sensor(collider.is_sensor())
|
||||
.margin(margin),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user