Fix compilation in 2D.
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
## v0.2.0 - WIP
|
## 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::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::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.
|
- Add `ColliderDesc::position(...)` to set the position of a collider relative to the rigid-body it is attached to.
|
||||||
|
|||||||
@@ -28,14 +28,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
.map(|e| e.0)
|
.map(|e| e.0)
|
||||||
.collect();
|
.collect();
|
||||||
for handle in to_remove {
|
for handle in to_remove {
|
||||||
physics.pipeline.remove_rigid_body(
|
physics
|
||||||
handle,
|
.bodies
|
||||||
&mut physics.broad_phase,
|
.remove(handle, &mut physics.colliders, &mut physics.joints);
|
||||||
&mut physics.narrow_phase,
|
|
||||||
&mut physics.bodies,
|
|
||||||
&mut physics.colliders,
|
|
||||||
&mut physics.joints,
|
|
||||||
);
|
|
||||||
graphics.remove_body_nodes(window, handle);
|
graphics.remove_body_nodes(window, handle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ impl Shape {
|
|||||||
}
|
}
|
||||||
Shape::Cuboid(cuboid) => cuboid.toi_and_normal_with_ray(position, ray, max_toi, true),
|
Shape::Cuboid(cuboid) => cuboid.toi_and_normal_with_ray(position, ray, max_toi, true),
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
Shape::Triangle(triangle) => {
|
Shape::Triangle(_) | Shape::Trimesh(_) => {
|
||||||
// This is not implemented yet in 2D.
|
// This is not implemented yet in 2D.
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,7 @@ impl Shape {
|
|||||||
Shape::Triangle(triangle) => {
|
Shape::Triangle(triangle) => {
|
||||||
triangle.toi_and_normal_with_ray(position, ray, max_toi, true)
|
triangle.toi_and_normal_with_ray(position, ray, max_toi, true)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
Shape::Trimesh(trimesh) => {
|
Shape::Trimesh(trimesh) => {
|
||||||
trimesh.toi_and_normal_with_ray(position, ray, max_toi, true)
|
trimesh.toi_and_normal_with_ray(position, ray, max_toi, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
use crate::geometry::{Ray, RayIntersection, Triangle, WQuadtree};
|
use crate::geometry::{Triangle, WQuadtree};
|
||||||
use crate::math::{Isometry, Point};
|
use crate::math::{Isometry, Point};
|
||||||
use crate::ncollide::query::RayCast;
|
|
||||||
use na::Point3;
|
use na::Point3;
|
||||||
use ncollide::bounding_volume::{HasBoundingVolume, AABB};
|
use ncollide::bounding_volume::{HasBoundingVolume, AABB};
|
||||||
|
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
|
use {
|
||||||
|
crate::geometry::{Ray, RayIntersection},
|
||||||
|
ncollide::query::RayCast,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
/// A triangle mesh.
|
/// A triangle mesh.
|
||||||
@@ -105,6 +110,7 @@ impl Trimesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
impl RayCast<f32> for Trimesh {
|
impl RayCast<f32> for Trimesh {
|
||||||
fn toi_and_normal_with_ray(
|
fn toi_and_normal_with_ray(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use crate::geometry::{ColliderHandle, ColliderSet, Ray, AABB};
|
use crate::geometry::{ColliderHandle, ColliderSet, Ray, AABB};
|
||||||
use crate::geometry::{WRay, WAABB};
|
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 crate::simd::{SimdFloat, SIMD_WIDTH};
|
||||||
use ncollide::bounding_volume::BoundingVolume;
|
use ncollide::bounding_volume::BoundingVolume;
|
||||||
use simba::simd::{SimdBool, SimdValue};
|
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
|
// Find the axis with minimum variance. This is the axis along
|
||||||
// which we are **not** subdividing our set.
|
// which we are **not** subdividing our set.
|
||||||
|
#[allow(unused_mut)] // Does not need to be mutable in 2D.
|
||||||
let mut subdiv_dims = [0, 1];
|
let mut subdiv_dims = [0, 1];
|
||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
{
|
{
|
||||||
@@ -466,6 +469,7 @@ impl<T: IndexedData> WQuadtreeIncrementalBuilder<T> {
|
|||||||
|
|
||||||
// Find the axis with minimum variance. This is the axis along
|
// Find the axis with minimum variance. This is the axis along
|
||||||
// which we are **not** subdividing our set.
|
// which we are **not** subdividing our set.
|
||||||
|
#[allow(unused_mut)] // Does not need to be mutable in 2D.
|
||||||
let mut subdiv_dims = [0, 1];
|
let mut subdiv_dims = [0, 1];
|
||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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.
|
/// Executes one timestep of the physics simulation.
|
||||||
pub fn step(
|
pub fn step(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -82,9 +70,9 @@ impl PhysicsPipeline {
|
|||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
events: &dyn EventHandler,
|
events: &dyn EventHandler,
|
||||||
) {
|
) {
|
||||||
// println!("Step");
|
|
||||||
self.counters.step_started();
|
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();
|
bodies.maintain_active_set();
|
||||||
|
|
||||||
// Update kinematic bodies velocities.
|
// Update kinematic bodies velocities.
|
||||||
|
|||||||
@@ -98,10 +98,10 @@ impl Box2dWorld {
|
|||||||
|
|
||||||
fn insert_joints(&mut self, joints: &JointSet) {
|
fn insert_joints(&mut self, joints: &JointSet) {
|
||||||
for joint in joints.iter() {
|
for joint in joints.iter() {
|
||||||
let body_a = self.rapier2box2d[&joint.body1];
|
let body_a = self.rapier2box2d[&joint.1.body1];
|
||||||
let body_b = self.rapier2box2d[&joint.body2];
|
let body_b = self.rapier2box2d[&joint.1.body2];
|
||||||
|
|
||||||
match &joint.params {
|
match &joint.1.params {
|
||||||
JointParams::BallJoint(params) => {
|
JointParams::BallJoint(params) => {
|
||||||
let def = RevoluteJointDef {
|
let def = RevoluteJointDef {
|
||||||
body_a,
|
body_a,
|
||||||
@@ -158,7 +158,7 @@ impl Box2dWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_fixture(collider: &Collider, body: &mut b2::MetaBody<NoUserData>) {
|
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();
|
let mut fixture_def = b2::FixtureDef::new();
|
||||||
|
|
||||||
fixture_def.restitution = 0.0;
|
fixture_def.restitution = 0.0;
|
||||||
@@ -182,7 +182,7 @@ impl Box2dWorld {
|
|||||||
let points: Vec<_> = poly
|
let points: Vec<_> = poly
|
||||||
.vertices()
|
.vertices()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| collider.delta() * p)
|
.map(|p| collider.position_wrt_parent() * p)
|
||||||
.map(|p| na_vec_to_b2_vec(p.coords))
|
.map(|p| na_vec_to_b2_vec(p.coords))
|
||||||
.collect();
|
.collect();
|
||||||
let b2_shape = b2::PolygonShape::new_with(&points);
|
let b2_shape = b2::PolygonShape::new_with(&points);
|
||||||
@@ -229,7 +229,7 @@ impl Box2dWorld {
|
|||||||
|
|
||||||
for coll_handle in body.colliders() {
|
for coll_handle in body.colliders() {
|
||||||
let collider = &mut colliders[*coll_handle];
|
let collider = &mut colliders[*coll_handle];
|
||||||
collider.set_position_debug(pos * collider.delta());
|
collider.set_position_debug(pos * collider.position_wrt_parent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1160,7 +1160,7 @@ impl Testbed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
fn highlight_hovered_body(&mut self, window: &Window) {
|
fn highlight_hovered_body(&mut self, _window: &Window) {
|
||||||
// Do nothing for now.
|
// Do nothing for now.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user