aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/debug_render_pipeline
diff options
context:
space:
mode:
authorSébastien Crozet <sebcrozet@dimforge.com>2024-03-17 21:20:18 +0100
committerSébastien Crozet <sebcrozet@dimforge.com>2024-03-17 21:24:28 +0100
commitecd308338b189ab569816a38a03e3f8b89669dde (patch)
treefa612abff2f23ea6a5ff04c64c07296d9fb065c8 /src/pipeline/debug_render_pipeline
parentda92e5c2837b27433286cf0dd9d887fd44dda254 (diff)
downloadrapier-bevy-glam.tar.gz
rapier-bevy-glam.tar.bz2
rapier-bevy-glam.zip
feat: start experimenting with a glam/bevy versionbevy-glam
Diffstat (limited to 'src/pipeline/debug_render_pipeline')
-rw-r--r--src/pipeline/debug_render_pipeline/debug_render_backend.rs44
-rw-r--r--src/pipeline/debug_render_pipeline/debug_render_pipeline.rs29
-rw-r--r--src/pipeline/debug_render_pipeline/outlines.rs6
3 files changed, 41 insertions, 38 deletions
diff --git a/src/pipeline/debug_render_pipeline/debug_render_backend.rs b/src/pipeline/debug_render_pipeline/debug_render_backend.rs
index 664bf46..84aa2cc 100644
--- a/src/pipeline/debug_render_pipeline/debug_render_backend.rs
+++ b/src/pipeline/debug_render_pipeline/debug_render_backend.rs
@@ -2,9 +2,8 @@ use crate::dynamics::{
ImpulseJoint, ImpulseJointHandle, Multibody, MultibodyLink, RigidBody, RigidBodyHandle,
};
use crate::geometry::{Aabb, Collider, ContactPair};
-use crate::math::{Isometry, Point, Real, Vector};
+use crate::math::*;
use crate::prelude::{ColliderHandle, MultibodyJointHandle};
-use na::Scale;
/// The object currently being rendered by the debug-renderer.
#[derive(Copy, Clone)]
@@ -38,27 +37,25 @@ pub trait DebugRenderBackend {
/// Draws a colored line.
///
/// Note that this method can be called multiple time for the same `object`.
- fn draw_line(
- &mut self,
- object: DebugRenderObject,
- a: Point<Real>,
- b: Point<Real>,
- color: [f32; 4],
- );
+ fn draw_line(&mut self, object: DebugRenderObject, a: Point, b: Point, color: [f32; 4]);
/// Draws a set of line.
fn draw_polyline(
&mut self,
object: DebugRenderObject,
- vertices: &[Point<Real>],
+ vertices: &[Point],
indices: &[[u32; 2]],
- transform: &Isometry<Real>,
- scale: &Vector<Real>,
+ transform: &Isometry,
+ scale: &Vector,
color: [f32; 4],
) {
for idx in indices {
- let a = transform * (Scale::from(*scale) * vertices[idx[0] as usize]);
- let b = transform * (Scale::from(*scale) * vertices[idx[1] as usize]);
+ let a = transform.transform_point(&Point::from(
+ vertices[idx[0] as usize].as_vector().component_mul(scale),
+ ));
+ let b = transform.transform_point(&Point::from(
+ vertices[idx[1] as usize].as_vector().component_mul(scale),
+ ));
self.draw_line(object, a, b, color);
}
}
@@ -67,21 +64,26 @@ pub trait DebugRenderBackend {
fn draw_line_strip(
&mut self,
object: DebugRenderObject,
- vertices: &[Point<Real>],
- transform: &Isometry<Real>,
- scale: &Vector<Real>,
+ vertices: &[Point],
+ transform: &Isometry,
+ scale: &Vector,
color: [f32; 4],
closed: bool,
) {
for vtx in vertices.windows(2) {
- let a = transform * (Scale::from(*scale) * vtx[0]);
- let b = transform * (Scale::from(*scale) * vtx[1]);
+ let a =
+ transform.transform_point(&Point::from(vtx[0].as_vector().component_mul(scale)));
+ let b =
+ transform.transform_point(&Point::from(vtx[1].as_vector().component_mul(scale)));
self.draw_line(object, a, b, color);
}
if closed && vertices.len() > 2 {
- let a = transform * (Scale::from(*scale) * vertices[0]);
- let b = transform * (Scale::from(*scale) * vertices.last().unwrap());
+ let a = transform
+ .transform_point(&Point::from(vertices[0].as_vector().component_mul(scale)));
+ let b = transform.transform_point(&Point::from(
+ vertices.last().unwrap().as_vector().component_mul(scale),
+ ));
self.draw_line(object, a, b, color);
}
}
diff --git a/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs b/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs
index b429c90..779e220 100644
--- a/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs
+++ b/src/pipeline/debug_render_pipeline/debug_render_pipeline.rs
@@ -5,7 +5,7 @@ use crate::dynamics::{
use crate::geometry::{Ball, ColliderSet, Cuboid, NarrowPhase, Shape, TypedShape};
#[cfg(feature = "dim3")]
use crate::geometry::{Cone, Cylinder};
-use crate::math::{Isometry, Point, Real, Vector, DIM};
+use crate::math::*;
use crate::pipeline::debug_render_pipeline::debug_render_backend::DebugRenderObject;
use crate::pipeline::debug_render_pipeline::DebugRenderStyle;
use crate::utils::SimdBasis;
@@ -42,9 +42,9 @@ impl Default for DebugRenderMode {
}
#[cfg(feature = "dim2")]
-type InstancesMap = HashMap<TypeId, Vec<Point<Real>>>;
+type InstancesMap = HashMap<TypeId, Vec<Point>>;
#[cfg(feature = "dim3")]
-type InstancesMap = HashMap<TypeId, (Vec<Point<Real>>, Vec<[u32; 2]>)>;
+type InstancesMap = HashMap<TypeId, (Vec<Point>, Vec<[u32; 2]>)>;
/// Pipeline responsible for rendering the state of the physics engine for debugging purpose.
pub struct DebugRenderPipeline {
@@ -117,16 +117,17 @@ impl DebugRenderPipeline {
for contact in manifold.contacts() {
backend.draw_line(
object,
- co1.position() * contact.local_p1,
- co2.position() * contact.local_p2,
+ co1.position().transform_point(&contact.local_p1),
+ co2.position().transform_point(&contact.local_p2),
self.style.contact_depth_color,
);
backend.draw_line(
object,
- co1.position() * contact.local_p1,
- co1.position()
- * (contact.local_p1
+ co1.position().transform_point(&contact.local_p1),
+ co1.position().transform_point(
+ &(contact.local_p1
+ manifold.local_n1 * self.style.contact_normal_length),
+ ),
self.style.contact_normal_color,
);
}
@@ -193,10 +194,10 @@ impl DebugRenderPipeline {
let frame1 = rb1.position() * data.local_frame1;
let frame2 = rb2.position() * data.local_frame2;
- let a = *rb1.translation();
- let b = frame1.translation.vector;
- let c = frame2.translation.vector;
- let d = *rb2.translation();
+ let a = rb1.translation();
+ let b = frame1.translation.into_vector();
+ let c = frame2.translation.into_vector();
+ let d = rb2.translation();
for k in 0..4 {
anchor_color[k] *= coeff[k];
@@ -351,7 +352,7 @@ impl DebugRenderPipeline {
object: DebugRenderObject,
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
- pos: &Isometry<Real>,
+ pos: &Isometry,
color: [f32; 4],
) {
match shape.as_typed_shape() {
@@ -451,7 +452,7 @@ impl DebugRenderPipeline {
object: DebugRenderObject,
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
- pos: &Isometry<Real>,
+ pos: &Isometry,
color: [f32; 4],
) {
match shape.as_typed_shape() {
diff --git a/src/pipeline/debug_render_pipeline/outlines.rs b/src/pipeline/debug_render_pipeline/outlines.rs
index cd0b6ed..56e26ec 100644
--- a/src/pipeline/debug_render_pipeline/outlines.rs
+++ b/src/pipeline/debug_render_pipeline/outlines.rs
@@ -1,12 +1,12 @@
use crate::geometry::{Ball, Cuboid};
#[cfg(feature = "dim3")]
use crate::geometry::{Cone, Cylinder};
-use crate::math::{Point, Real, Vector};
+use crate::math::*;
use std::any::TypeId;
use std::collections::HashMap;
#[cfg(feature = "dim2")]
-pub fn instances(nsubdivs: u32) -> HashMap<TypeId, Vec<Point<Real>>> {
+pub fn instances(nsubdivs: u32) -> HashMap<TypeId, Vec<Point>> {
let mut result = HashMap::new();
result.insert(
TypeId::of::<Cuboid>(),
@@ -18,7 +18,7 @@ pub fn instances(nsubdivs: u32) -> HashMap<TypeId, Vec<Point<Real>>> {
#[cfg(feature = "dim3")]
#[allow(clippy::type_complexity)]
-pub fn instances(nsubdivs: u32) -> HashMap<TypeId, (Vec<Point<Real>>, Vec<[u32; 2]>)> {
+pub fn instances(nsubdivs: u32) -> HashMap<TypeId, (Vec<Point>, Vec<[u32; 2]>)> {
let mut result = HashMap::new();
result.insert(
TypeId::of::<Cuboid>(),