Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed hardcoded values for DebugColor in various places #774

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pipeline/debug_render_pipeline/debug_render_backend.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::DebugColor;
use crate::dynamics::{
ImpulseJoint, ImpulseJointHandle, Multibody, MultibodyLink, RigidBody, RigidBodyHandle,
};
Expand Down Expand Up @@ -43,7 +44,7 @@ pub trait DebugRenderBackend {
object: DebugRenderObject,
a: Point<Real>,
b: Point<Real>,
color: [f32; 4],
color: DebugColor,
);

/// Draws a set of lines.
Expand All @@ -54,7 +55,7 @@ pub trait DebugRenderBackend {
indices: &[[u32; 2]],
transform: &Isometry<Real>,
scale: &Vector<Real>,
color: [f32; 4],
color: DebugColor,
) {
for idx in indices {
let a = transform * (Scale::from(*scale) * vertices[idx[0] as usize]);
Expand All @@ -70,7 +71,7 @@ pub trait DebugRenderBackend {
vertices: &[Point<Real>],
transform: &Isometry<Real>,
scale: &Vector<Real>,
color: [f32; 4],
color: DebugColor,
closed: bool,
) {
for vtx in vertices.windows(2) {
Expand Down
10 changes: 5 additions & 5 deletions src/pipeline/debug_render_pipeline/debug_render_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{outlines, DebugRenderBackend};
use super::{outlines, DebugColor, DebugRenderBackend};
use crate::dynamics::{
GenericJoint, ImpulseJointSet, MultibodyJointSet, RigidBodySet, RigidBodyType,
};
Expand Down Expand Up @@ -180,8 +180,8 @@ impl DebugRenderPipeline {
let mut render_joint = |body1,
body2,
data: &GenericJoint,
mut anchor_color: [f32; 4],
mut separation_color: [f32; 4],
mut anchor_color: DebugColor,
mut separation_color: DebugColor,
object| {
if !backend.filter_object(object) {
return;
Expand Down Expand Up @@ -363,7 +363,7 @@ impl DebugRenderPipeline {
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
pos: &Isometry<Real>,
color: [f32; 4],
color: DebugColor,
) {
match shape.as_typed_shape() {
TypedShape::Ball(s) => {
Expand Down Expand Up @@ -471,7 +471,7 @@ impl DebugRenderPipeline {
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
pos: &Isometry<Real>,
color: [f32; 4],
color: DebugColor,
) {
match shape.as_typed_shape() {
TypedShape::Ball(s) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/debug_render_pipeline/debug_render_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub struct DebugRenderStyle {
/// If a rigid-body is sleeping, its attached entities will have their colors
/// multiplied by this array. (For a joint, both attached rigid-bodies must be sleeping
/// or non-dynamic for this multiplier to be applied).
pub sleep_color_multiplier: [f32; 4],
pub sleep_color_multiplier: DebugColor,
/// If a rigid-body is disabled, its attached entities will have their colors
/// multiplied by this array. (For a joint, both attached rigid-bodies must be disabled
/// for this multiplier to be applied).
pub disabled_color_multiplier: [f32; 4],
pub disabled_color_multiplier: DebugColor,
/// The length of the local coordinate axes rendered for a rigid-body.
pub rigid_body_axes_length: Real,
/// The color for the segments joining the two contact points.
Expand Down
18 changes: 15 additions & 3 deletions src_testbed/debug_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::gizmos::gizmos::Gizmos;
use bevy::prelude::*;
use rapier::math::{Point, Real};
use rapier::pipeline::{
DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline,
DebugColor, DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline,
};

#[derive(Resource)]
Expand Down Expand Up @@ -36,15 +36,27 @@ struct BevyLinesRenderBackend<'w, 's> {

impl<'w, 's> DebugRenderBackend for BevyLinesRenderBackend<'w, 's> {
#[cfg(feature = "dim2")]
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
fn draw_line(
&mut self,
_: DebugRenderObject,
a: Point<Real>,
b: Point<Real>,
color: DebugColor,
) {
self.gizmos.line(
[a.x as f32, a.y as f32, 1.0e-8].into(),
[b.x as f32, b.y as f32, 1.0e-8].into(),
Color::hsla(color[0], color[1], color[2], color[3]),
)
}
#[cfg(feature = "dim3")]
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
fn draw_line(
&mut self,
_: DebugRenderObject,
a: Point<Real>,
b: Point<Real>,
color: DebugColor,
) {
self.gizmos.line(
[a.x as f32, a.y as f32, a.z as f32].into(),
[b.x as f32, b.y as f32, b.z as f32].into(),
Expand Down
Loading