aboutsummaryrefslogtreecommitdiff
path: root/src_testbed/objects
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-01-26 16:41:21 +0100
committerCrozet Sébastien <developer@crozet.re>2021-01-26 16:41:21 +0100
commit23a86c294e48da9c3aad82284a09791aabfeb88d (patch)
treec4adf2ccf4703ef103247f5035838f4071bf8c7c /src_testbed/objects
parente1f50eb6e8daa9529e41f7044e67736cc5c50953 (diff)
downloadrapier-23a86c294e48da9c3aad82284a09791aabfeb88d.tar.gz
rapier-23a86c294e48da9c3aad82284a09791aabfeb88d.tar.bz2
rapier-23a86c294e48da9c3aad82284a09791aabfeb88d.zip
Allow using polylines as a collider shape.
Diffstat (limited to 'src_testbed/objects')
-rw-r--r--src_testbed/objects/mod.rs1
-rw-r--r--src_testbed/objects/node.rs23
-rw-r--r--src_testbed/objects/polyline.rs64
3 files changed, 35 insertions, 53 deletions
diff --git a/src_testbed/objects/mod.rs b/src_testbed/objects/mod.rs
index e4d7bc4..8e12dbe 100644
--- a/src_testbed/objects/mod.rs
+++ b/src_testbed/objects/mod.rs
@@ -7,6 +7,7 @@ pub mod cylinder;
pub mod heightfield;
pub mod mesh;
pub mod node;
+pub mod polyline;
//pub mod plane;
//#[cfg(feature = "dim2")]
//pub mod polyline;
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs
index d1de799..64c8ad4 100644
--- a/src_testbed/objects/node.rs
+++ b/src_testbed/objects/node.rs
@@ -5,8 +5,7 @@ use crate::objects::convex::Convex;
use crate::objects::heightfield::HeightField;
use crate::objects::mesh::Mesh;
//use crate::objects::plane::Plane;
-//#[cfg(feature = "dim2")]
-//use crate::objects::polyline::Polyline;
+use crate::objects::polyline::Polyline;
use kiss3d::window::Window;
use na::Point3;
@@ -26,8 +25,7 @@ pub enum Node {
Box(Box),
HeightField(HeightField),
Capsule(Capsule),
- // #[cfg(feature = "dim2")]
- // Polyline(Polyline),
+ Polyline(Polyline),
Mesh(Mesh),
Convex(Convex),
Cylinder(Cylinder),
@@ -42,8 +40,7 @@ impl Node {
Node::Box(ref mut n) => n.select(),
Node::Capsule(ref mut n) => n.select(),
Node::HeightField(ref mut n) => n.select(),
- // #[cfg(feature = "dim2")]
- // Node::Polyline(ref mut n) => n.select(),
+ Node::Polyline(ref mut n) => n.select(),
Node::Mesh(ref mut n) => n.select(),
Node::Convex(ref mut n) => n.select(),
Node::Cylinder(ref mut n) => n.select(),
@@ -58,8 +55,7 @@ impl Node {
Node::Box(ref mut n) => n.unselect(),
Node::Capsule(ref mut n) => n.unselect(),
Node::HeightField(ref mut n) => n.unselect(),
- // #[cfg(feature = "dim2")]
- // Node::Polyline(ref mut n) => n.unselect(),
+ Node::Polyline(ref mut n) => n.unselect(),
Node::Mesh(ref mut n) => n.unselect(),
Node::Convex(ref mut n) => n.unselect(),
Node::Cylinder(ref mut n) => n.unselect(),
@@ -74,8 +70,7 @@ impl Node {
Node::Box(ref mut n) => n.update(colliders),
Node::Capsule(ref mut n) => n.update(colliders),
Node::HeightField(ref mut n) => n.update(colliders),
- // #[cfg(feature = "dim2")]
- // Node::Polyline(ref mut n) => n.update(colliders),
+ Node::Polyline(ref mut n) => n.update(colliders),
Node::Mesh(ref mut n) => n.update(colliders),
Node::Convex(ref mut n) => n.update(colliders),
Node::Cylinder(ref mut n) => n.update(colliders),
@@ -86,7 +81,7 @@ impl Node {
#[cfg(feature = "dim2")]
pub fn draw(&mut self, window: &mut Window) {
match *self {
- // Node::Polyline(ref mut n) => n.draw(_window),
+ Node::Polyline(ref mut n) => n.draw(window),
Node::HeightField(ref mut n) => n.draw(window),
// Node::Plane(ref mut n) => n.draw(_window),
_ => {}
@@ -139,8 +134,7 @@ impl Node {
Node::Box(ref n) => n.object(),
Node::Capsule(ref n) => n.object(),
Node::HeightField(ref n) => n.object(),
- // #[cfg(feature = "dim2")]
- // Node::Polyline(ref n) => n.object(),
+ Node::Polyline(ref n) => n.object(),
Node::Mesh(ref n) => n.object(),
Node::Convex(ref n) => n.object(),
Node::Cylinder(ref n) => n.object(),
@@ -155,8 +149,7 @@ impl Node {
Node::Box(ref mut n) => n.set_color(color),
Node::Capsule(ref mut n) => n.set_color(color),
Node::HeightField(ref mut n) => n.set_color(color),
- // #[cfg(feature = "dim2")]
- // Node::Polyline(ref mut n) => n.set_color(color),
+ Node::Polyline(ref mut n) => n.set_color(color),
Node::Mesh(ref mut n) => n.set_color(color),
Node::Convex(ref mut n) => n.set_color(color),
Node::Cylinder(ref mut n) => n.set_color(color),
diff --git a/src_testbed/objects/polyline.rs b/src_testbed/objects/polyline.rs
index cdc0f21..98a8f24 100644
--- a/src_testbed/objects/polyline.rs
+++ b/src_testbed/objects/polyline.rs
@@ -1,38 +1,32 @@
use kiss3d::window::Window;
-use na::{Isometry2, Point2, Point3};
-use nphysics2d::object::{ColliderAnchor, DefaultColliderHandle, DefaultColliderSet};
-use parry2d::shape;
+use na::Point3;
+use rapier::geometry::{ColliderHandle, ColliderSet};
+use rapier::math::{Isometry, Point};
pub struct Polyline {
color: Point3<f32>,
base_color: Point3<f32>,
- vertices: Vec<Point2<f32>>,
- indices: Vec<Point2<usize>>,
- collider: DefaultColliderHandle,
- pos: Isometry2<f32>,
+ vertices: Vec<Point<f32>>,
+ indices: Vec<[u32; 2]>,
+ collider: ColliderHandle,
+ pos: Isometry<f32>,
}
impl Polyline {
pub fn new(
- collider: DefaultColliderHandle,
- colliders: &DefaultColliderSet<f32>,
- _: Isometry2<f32>,
- vertices: Vec<Point2<f32>>,
- indices: Vec<Point2<usize>>,
+ collider: ColliderHandle,
+ vertices: Vec<Point<f32>>,
+ indices: Vec<[u32; 2]>,
color: Point3<f32>,
- _: &mut Window,
) -> Polyline {
- let mut res = Polyline {
+ Polyline {
color,
- pos: Isometry2::identity(),
+ pos: Isometry::identity(),
base_color: color,
vertices,
indices,
collider,
- };
-
- res.update(colliders);
- res
+ }
}
pub fn select(&mut self) {
@@ -48,32 +42,26 @@ impl Polyline {
self.base_color = color;
}
- pub fn update(&mut self, colliders: &DefaultColliderSet<f32>) {
- // Update if some deformation occurred.
- // FIXME: don't update if it did not move.
- if let Some(c) = colliders.get(self.collider) {
- self.pos = *c.position();
- if let ColliderAnchor::OnDeformableBody { .. } = c.anchor() {
- let shape = c.shape().as_shape::<shape::Polyline<f32>>().unwrap();
- self.vertices = shape.points().to_vec();
- self.indices.clear();
-
- for e in shape.edges() {
- self.indices.push(e.indices);
- }
- }
- }
+ pub fn update(&mut self, colliders: &ColliderSet) {
+ self.pos = colliders
+ .get(self.collider)
+ .map(|c| *c.position())
+ .unwrap_or(Isometry::identity());
}
- pub fn object(&self) -> DefaultColliderHandle {
+ pub fn object(&self) -> ColliderHandle {
self.collider
}
pub fn draw(&mut self, window: &mut Window) {
for idx in &self.indices {
- let p1 = self.pos * self.vertices[idx.x];
- let p2 = self.pos * self.vertices[idx.y];
- window.draw_planar_line(&p1, &p2, &self.color)
+ let p1 = self.pos * self.vertices[idx[0] as usize];
+ let p2 = self.pos * self.vertices[idx[1] as usize];
+
+ #[cfg(feature = "dim2")]
+ window.draw_planar_line(&p1, &p2, &self.color);
+ #[cfg(feature = "dim3")]
+ window.draw_line(&p1, &p2, &self.color);
}
}
}