Skip to content

Commit

Permalink
Merge pull request bevyengine#22 from superdump/rapier-0.3
Browse files Browse the repository at this point in the history
Rapier 0.3
  • Loading branch information
sebcrozet authored Oct 31, 2020
2 parents a5ed558 + 1b3e1b0 commit f00bc2c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ enhanced-determinism = [ "rapier2d/enhanced-determinism" ]

[dependencies]
bevy = "0.2"
nalgebra = "0.22"
rapier2d = "0.2"
nalgebra = "0.23"
rapier2d = "0.3"
concurrent-queue = "1"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ enhanced-determinism = [ "rapier3d/enhanced-determinism" ]

[dependencies]
bevy = "0.2"
nalgebra = "0.22"
rapier3d = "0.2"
nalgebra = "0.23"
rapier3d = "0.3"
concurrent-queue = "1"

[dev-dependencies]
3 changes: 2 additions & 1 deletion src/physics/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bevy::prelude::*;
use rapier::dynamics::{IntegrationParameters, JointSet, RigidBodyBuilder, RigidBodySet};
use rapier::geometry::{BroadPhase, ColliderBuilder, ColliderSet, NarrowPhase};
use rapier::math::Isometry;
use rapier::ncollide::utils::IsometryOps;
use rapier::pipeline::PhysicsPipeline;

// TODO: right now we only support one collider attached to one body.
Expand Down Expand Up @@ -106,6 +105,8 @@ pub fn step_world_system(
&mut bodies,
&mut colliders,
&mut joints,
None,
None,
&*events,
);
}
Expand Down
30 changes: 21 additions & 9 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::physics::{ColliderHandleComponent, RapierConfiguration};
use crate::render::RapierRenderColor;
use bevy::prelude::*;
use rapier::dynamics::RigidBodySet;
use rapier::geometry::{ColliderSet, Shape};
use rapier::geometry::{ColliderSet, ShapeType};

/// System responsible for attaching a PbrComponents to each entity having a collider.
pub fn create_collider_renders_system(
Expand Down Expand Up @@ -50,31 +50,43 @@ pub fn create_collider_renders_system(
icolor += 1;
palette[icolor % palette.len()]
};

let shape = collider.shape();

let color = debug_color
.map(|c| Color::rgb(c.0, c.1, c.2))
.unwrap_or(default_color);

let mesh = match collider.shape() {
let mesh = match shape.shape_type() {
#[cfg(feature = "dim3")]
Shape::Cuboid(_) => Mesh::from(shape::Cube { size: 1.0 }),
ShapeType::Cuboid => Mesh::from(shape::Cube { size: 1.0 }),
#[cfg(feature = "dim2")]
Shape::Cuboid(_) => Mesh::from(shape::Quad {
ShapeType::Cuboid => Mesh::from(shape::Quad {
size: Vec2::new(2.0, 2.0),
flip: false,
}),
Shape::Ball(_) => Mesh::from(shape::Icosphere {
ShapeType::Ball => Mesh::from(shape::Icosphere {
subdivisions: 2,
radius: 1.0,
}),
_ => unimplemented!(),
};

let scale = match collider.shape() {
let scale = match shape.shape_type() {
#[cfg(feature = "dim2")]
Shape::Cuboid(c) => Vec3::new(c.half_extents.x, c.half_extents.y, 1.0),
ShapeType::Cuboid => {
let c = shape.as_cuboid().unwrap();
Vec3::new(c.half_extents.x, c.half_extents.y, 1.0)
},
#[cfg(feature = "dim3")]
Shape::Cuboid(c) => Vec3::from_slice_unaligned(c.half_extents.as_slice()),
Shape::Ball(b) => Vec3::new(b.radius, b.radius, b.radius),
ShapeType::Cuboid => {
let c = shape.as_cuboid().unwrap();
Vec3::from_slice_unaligned(c.half_extents.as_slice())
},
ShapeType::Ball => {
let b = shape.as_ball().unwrap();
Vec3::new(b.radius, b.radius, b.radius)
},
_ => unimplemented!(),
} * configuration.scale;

Expand Down

0 comments on commit f00bc2c

Please sign in to comment.