Fix compilation in 2D.

This commit is contained in:
Crozet Sébastien
2020-10-06 15:49:22 +02:00
parent c5a8e03df7
commit e87b73a2a2
8 changed files with 32 additions and 34 deletions

View File

@@ -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.

View File

@@ -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);
}
});

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -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")]
{

View File

@@ -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.

View File

@@ -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());
}
}
}

View File

@@ -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.
}