diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-10-06 15:49:22 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-10-06 15:49:22 +0200 |
| commit | e87b73a2a20fee1ed333d564ba46dbf1c3ca75e2 (patch) | |
| tree | a4031976bb6a9f8cf81880c8ed4e0d1c72e919cb | |
| parent | c5a8e03df7b3009b24e7c272fafcc49b4bc4e829 (diff) | |
| download | rapier-e87b73a2a20fee1ed333d564ba46dbf1c3ca75e2.tar.gz rapier-e87b73a2a20fee1ed333d564ba46dbf1c3ca75e2.tar.bz2 rapier-e87b73a2a20fee1ed333d564ba46dbf1c3ca75e2.zip | |
Fix compilation in 2D.
| -rw-r--r-- | CHANGELOG | 6 | ||||
| -rw-r--r-- | examples2d/add_remove2.rs | 11 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 3 | ||||
| -rw-r--r-- | src/geometry/trimesh.rs | 10 | ||||
| -rw-r--r-- | src/geometry/wquadtree.rs | 6 | ||||
| -rw-r--r-- | src/pipeline/physics_pipeline.rs | 16 | ||||
| -rw-r--r-- | src_testbed/box2d_backend.rs | 12 | ||||
| -rw-r--r-- | src_testbed/testbed.rs | 2 |
8 files changed, 32 insertions, 34 deletions
@@ -1,6 +1,10 @@ ## v0.2.0 - WIP +The most significant change on this version is the addition of the `QueryPipeline` responsible for performing +scene-wide queries. So far only ray-casting has been implemented. -- Add `PhysicsPipeline::remove_collider(...)` to remove a collider from the `ColliderSet`. +- Add `ColliderSet::remove(...)` to remove a collider from the `ColliderSet`. +- Replace `PhysicsPipeline::remove_rigid_body` by `RigidBodySet::remove`. +- The `JointSet.iter()` now returns an iterator yielding `(JointHandle, &Joint)` instead of just `&Joint`. - Add `ColliderDesc::translation(...)` to set the translation of a collider relative to the rigid-body it is attached to. - Add `ColliderDesc::rotation(...)` to set the rotation of a collider relative to the rigid-body it is attached to. - Add `ColliderDesc::position(...)` to set the position of a collider relative to the rigid-body it is attached to. diff --git a/examples2d/add_remove2.rs b/examples2d/add_remove2.rs index 3a32a95..67075fe 100644 --- a/examples2d/add_remove2.rs +++ b/examples2d/add_remove2.rs @@ -28,14 +28,9 @@ pub fn init_world(testbed: &mut Testbed) { .map(|e| e.0) .collect(); for handle in to_remove { - physics.pipeline.remove_rigid_body( - handle, - &mut physics.broad_phase, - &mut physics.narrow_phase, - &mut physics.bodies, - &mut physics.colliders, - &mut physics.joints, - ); + physics + .bodies + .remove(handle, &mut physics.colliders, &mut physics.joints); graphics.remove_body_nodes(window, handle); } }); diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 23345f7..7c293b6 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -124,7 +124,7 @@ impl Shape { } Shape::Cuboid(cuboid) => cuboid.toi_and_normal_with_ray(position, ray, max_toi, true), #[cfg(feature = "dim2")] - Shape::Triangle(triangle) => { + Shape::Triangle(_) | Shape::Trimesh(_) => { // This is not implemented yet in 2D. None } @@ -132,6 +132,7 @@ impl Shape { Shape::Triangle(triangle) => { triangle.toi_and_normal_with_ray(position, ray, max_toi, true) } + #[cfg(feature = "dim3")] Shape::Trimesh(trimesh) => { trimesh.toi_and_normal_with_ray(position, ray, max_toi, true) } diff --git a/src/geometry/trimesh.rs b/src/geometry/trimesh.rs index dd8cb4b..b6e23e7 100644 --- a/src/geometry/trimesh.rs +++ b/src/geometry/trimesh.rs @@ -1,9 +1,14 @@ -use crate::geometry::{Ray, RayIntersection, Triangle, WQuadtree}; +use crate::geometry::{Triangle, WQuadtree}; use crate::math::{Isometry, Point}; -use crate::ncollide::query::RayCast; use na::Point3; use ncollide::bounding_volume::{HasBoundingVolume, AABB}; +#[cfg(feature = "dim3")] +use { + crate::geometry::{Ray, RayIntersection}, + ncollide::query::RayCast, +}; + #[derive(Clone)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] /// A triangle mesh. @@ -105,6 +110,7 @@ impl Trimesh { } } +#[cfg(feature = "dim3")] impl RayCast<f32> for Trimesh { fn toi_and_normal_with_ray( &self, diff --git a/src/geometry/wquadtree.rs b/src/geometry/wquadtree.rs index 233ebd1..fce04eb 100644 --- a/src/geometry/wquadtree.rs +++ b/src/geometry/wquadtree.rs @@ -1,6 +1,8 @@ use crate::geometry::{ColliderHandle, ColliderSet, Ray, AABB}; use crate::geometry::{WRay, WAABB}; -use crate::math::{Point, Vector}; +use crate::math::Point; +#[cfg(feature = "dim3")] +use crate::math::Vector; use crate::simd::{SimdFloat, SIMD_WIDTH}; use ncollide::bounding_volume::BoundingVolume; use simba::simd::{SimdBool, SimdValue}; @@ -252,6 +254,7 @@ impl<T: IndexedData> WQuadtree<T> { // Find the axis with minimum variance. This is the axis along // which we are **not** subdividing our set. + #[allow(unused_mut)] // Does not need to be mutable in 2D. let mut subdiv_dims = [0, 1]; #[cfg(feature = "dim3")] { @@ -466,6 +469,7 @@ impl<T: IndexedData> WQuadtreeIncrementalBuilder<T> { // Find the axis with minimum variance. This is the axis along // which we are **not** subdividing our set. + #[allow(unused_mut)] // Does not need to be mutable in 2D. let mut subdiv_dims = [0, 1]; #[cfg(feature = "dim3")] { diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index 4a39f79..462b341 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -58,18 +58,6 @@ impl PhysicsPipeline { } } - /// Remove this. - pub fn maintain( - &mut self, - broad_phase: &mut BroadPhase, - narrow_phase: &mut NarrowPhase, - bodies: &mut RigidBodySet, - colliders: &mut ColliderSet, - ) { - broad_phase.maintain(colliders); - narrow_phase.maintain(colliders, bodies); - } - /// Executes one timestep of the physics simulation. pub fn step( &mut self, @@ -82,9 +70,9 @@ impl PhysicsPipeline { joints: &mut JointSet, events: &dyn EventHandler, ) { - // println!("Step"); self.counters.step_started(); - self.maintain(broad_phase, narrow_phase, bodies, colliders); + broad_phase.maintain(colliders); + narrow_phase.maintain(colliders, bodies); bodies.maintain_active_set(); // Update kinematic bodies velocities. diff --git a/src_testbed/box2d_backend.rs b/src_testbed/box2d_backend.rs index 07cef1e..c25ff1f 100644 --- a/src_testbed/box2d_backend.rs +++ b/src_testbed/box2d_backend.rs @@ -98,10 +98,10 @@ impl Box2dWorld { fn insert_joints(&mut self, joints: &JointSet) { for joint in joints.iter() { - let body_a = self.rapier2box2d[&joint.body1]; - let body_b = self.rapier2box2d[&joint.body2]; + let body_a = self.rapier2box2d[&joint.1.body1]; + let body_b = self.rapier2box2d[&joint.1.body2]; - match &joint.params { + match &joint.1.params { JointParams::BallJoint(params) => { let def = RevoluteJointDef { body_a, @@ -158,7 +158,7 @@ impl Box2dWorld { } fn create_fixture(collider: &Collider, body: &mut b2::MetaBody<NoUserData>) { - let center = na_vec_to_b2_vec(collider.delta().translation.vector); + let center = na_vec_to_b2_vec(collider.position_wrt_parent().translation.vector); let mut fixture_def = b2::FixtureDef::new(); fixture_def.restitution = 0.0; @@ -182,7 +182,7 @@ impl Box2dWorld { let points: Vec<_> = poly .vertices() .iter() - .map(|p| collider.delta() * p) + .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); @@ -229,7 +229,7 @@ impl Box2dWorld { for coll_handle in body.colliders() { let collider = &mut colliders[*coll_handle]; - collider.set_position_debug(pos * collider.delta()); + collider.set_position_debug(pos * collider.position_wrt_parent()); } } } diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index c145af5..3d7fd7d 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -1160,7 +1160,7 @@ impl Testbed { } #[cfg(feature = "dim2")] - fn highlight_hovered_body(&mut self, window: &Window) { + fn highlight_hovered_body(&mut self, _window: &Window) { // Do nothing for now. } |
