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

f64 support #421

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,28 @@ jobs:
- run: sudo apt update && sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev
- name: Clippy for bevy_rapier2d
run: cargo clippy --verbose -p bevy_rapier2d
- name: Clippy for bevy_rapier2d_f64
run: cargo clippy --verbose -p bevy_rapier2d_f64
- name: Clippy for bevy_rapier3d
run: cargo clippy --verbose -p bevy_rapier3d
- name: Clippy for bevy_rapier3d_f64
run: cargo clippy --verbose -p bevy_rapier3d_f64
- name: Clippy for bevy_rapier2d (debug-render, simd, serde)
run: cargo clippy --verbose -p bevy_rapier2d --features debug-render-2d,simd-stable,serde-serialize
- name: Clippy for bevy_rapier2d_f64 (debug-render, simd, serde)
run: cargo clippy --verbose -p bevy_rapier2d_f64 --features debug-render-2d,simd-stable,serde-serialize
- name: Clippy for bevy_rapier3d (debug-render, simd, serde)
run: cargo clippy --verbose -p bevy_rapier3d --features debug-render-3d,simd-stable,serde-serialize
- name: Clippy for bevy_rapier3d_f64 (debug-render, simd, serde)
run: cargo clippy --verbose -p bevy_rapier3d_f64 --features debug-render-3d,simd-stable,serde-serialize
- name: Test for bevy_rapier2d
run: cargo test --verbose -p bevy_rapier2d
- name: Test for bevy_rapier2d_f64
run: cargo test --verbose -p bevy_rapier2d_f64
- name: Test for bevy_rapier3d
run: cargo test --verbose -p bevy_rapier3d
- name: Test for bevy_rapier3d_f64
run: cargo test --verbose -p bevy_rapier3d_f64
test-wasm:
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["bevy_rapier2d", "bevy_rapier3d"]
members = ["bevy_rapier2d", "bevy_rapier2d_f64", "bevy_rapier3d", "bevy_rapier3d_f64"]
resolver = "2"

[profile.dev]
Expand Down
9 changes: 5 additions & 4 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim2" ]
required-features = [ "dim2", "f32" ]

[features]
default = [ "dim2", "async-collider", "debug-render-2d" ]
default = [ "dim2", "async-collider", "debug-render-2d", "f32" ]
dim2 = []
f32 = []
debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset" ]
debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset" ]
parallel = [ "rapier2d/parallel" ]
simd-stable = [ "rapier2d/simd-stable" ]
simd-nightly = [ "rapier2d/simd-nightly" ]
wasm-bindgen = [ "rapier2d/wasm-bindgen" ]
serde-serialize = [ "rapier2d/serde-serialize", "bevy/serialize", "serde" ]
enhanced-determinism = [ "rapier2d/enhanced-determinism" ]
enhanced-determinism = [ "rapier2d/enhanced-determinism", ]
headless = []
async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]

Expand All @@ -36,7 +37,7 @@ bevy = { version = "0.11", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier2d = "0.17.0"
bitflags = "1"
bitflags = "2.4"
#bevy_prototype_debug_lines = { version = "0.6", optional = true }
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}
Expand Down
53 changes: 53 additions & 0 deletions bevy_rapier2d_f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "bevy_rapier2d_f64"
version = "0.22.0"
authors = ["Sébastien Crozet <[email protected]>"]
description = "2-dimensional physics engine in Rust, official Bevy plugin."
documentation = "http://docs.rs/bevy_rapier3d"
homepage = "http://rapier.rs"
repository = "https://github.com/dimforge/bevy_rapier"
readme = "../README.md"
keywords = [ "physics", "dynamics", "rigid", "real-time", "joints" ]
license = "Apache-2.0"
edition = "2021"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim2", "f64" ]

[features]
default = [ "dim2", "async-collider", "debug-render-2d", "f64" ]
dim2 = []
f64 = []
debug-render = [ "debug-render-3d" ]
debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier2d-f64/debug-render", "bevy/bevy_asset" ]
debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier2d-f64/debug-render", "bevy/bevy_asset" ]
parallel = [ "rapier2d-f64/parallel" ]
simd-stable = [ "rapier2d-f64/simd-stable" ]
simd-nightly = [ "rapier2d-f64/simd-nightly" ]
wasm-bindgen = [ "rapier2d-f64/wasm-bindgen" ]
serde-serialize = [ "rapier2d-f64/serde-serialize", "bevy/serialize", "serde" ]
enhanced-determinism = [ "rapier2d-f64/enhanced-determinism" ]
headless = [ ]
async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]

[dependencies]
bevy = { version = "0.11", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier2d-f64 = "0.17"
bitflags = "2.4"
#bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true }
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.11", default-features = false, features = ["x11"]}
approx = "0.5.1"
glam = { version = "0.24", features = [ "approx" ] }

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
features = [ "debug-render-2d", "serde-serialize" ]
9 changes: 5 additions & 4 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim3" ]
required-features = [ "dim3", "f32" ]

[features]
default = [ "dim3", "async-collider", "debug-render-3d" ]
default = [ "dim3", "async-collider", "debug-render-3d", "f32" ]
dim3 = []
f32 = []
debug-render = [ "debug-render-3d" ]
debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset" ]
debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset" ]
Expand All @@ -36,8 +37,8 @@ async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]
bevy = { version = "0.11", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier3d = "0.17.0"
bitflags = "1"
rapier3d = "0.17"
bitflags = "2.4"
#bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true }
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/examples/joints3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn setup_graphics(mut commands: Commands) {
});
}

fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) {
fn create_prismatic_joints(commands: &mut Commands, origin: Vec3, num: usize) {
let rad = 0.4;
let shift = 1.0;

Expand Down Expand Up @@ -62,7 +62,7 @@ fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) {
}
}

fn create_rope_joints(commands: &mut Commands, origin: Vect, num: usize) {
fn create_rope_joints(commands: &mut Commands, origin: Vec3, num: usize) {
let rad = 0.4;
let shift = 1.0;

Expand Down
8 changes: 6 additions & 2 deletions bevy_rapier3d/examples/ray_casting3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ fn cast_ray(
) {
let window = windows.single();

let Some(cursor_position) = window.cursor_position() else { return; };
let Some(cursor_position) = window.cursor_position() else {
return;
};

// We will color in read the colliders hovered by the mouse.
for (camera, camera_transform) in &cameras {
// First, compute a ray from the mouse position.
let Some(ray) = camera.viewport_to_world(camera_transform, cursor_position) else { return; };
let Some(ray) = camera.viewport_to_world(camera_transform, cursor_position) else {
return;
};

// Then cast the ray.
let hit = rapier_context.cast_ray(
Expand Down
12 changes: 6 additions & 6 deletions bevy_rapier3d/examples/static_trimesh3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn setup_graphics(mut commands: Commands) {
}

fn ramp_size() -> Vec3 {
Vec3::new(10.0, 1.0, 1.0)
Vec3::new(10.0, 1.5, 1.0)
}

pub fn setup_physics(mut commands: Commands) {
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn setup_physics(mut commands: Commands) {
let mut indices: Vec<[u32; 3]> = Vec::new();

let segments = 32;
let bowl_size = Vec3::new(10.0, 3.0, 10.0);
let bowl_size = Vec3::new(10.0, 6.0, 10.0);

for ix in 0..=segments {
for iz in 0..=segments {
Expand Down Expand Up @@ -111,9 +111,9 @@ impl Default for BallState {
fn default() -> Self {
Self {
seconds_until_next_spawn: 0.5,
seconds_between_spawns: 2.0,
seconds_between_spawns: 2.5,
balls_spawned: 0,
max_balls: 10,
max_balls: 200,
}
}
}
Expand All @@ -129,7 +129,7 @@ fn ball_spawner(

// NOTE: The timing here only works properly with `time_dependent_number_of_timesteps`
// disabled, as it is for examples.
ball_state.seconds_until_next_spawn -= rapier_context.integration_parameters.dt;
ball_state.seconds_until_next_spawn -= rapier_context.integration_parameters.dt as f32;
if ball_state.seconds_until_next_spawn > 0.0 {
return;
}
Expand All @@ -142,7 +142,7 @@ fn ball_spawner(
commands.spawn((
TransformBundle::from(Transform::from_xyz(
ramp_size.x * 0.9,
ramp_size.y / 2.0 + rad * 3.0,
ramp_size.y + rad * 3.0,
0.0,
)),
RigidBody::Dynamic,
Expand Down
53 changes: 53 additions & 0 deletions bevy_rapier3d_f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "bevy_rapier3d_f64"
version = "0.22.0"
authors = ["Sébastien Crozet <[email protected]>"]
description = "3-dimensional physics engine in Rust, official Bevy plugin."
documentation = "http://docs.rs/bevy_rapier3d"
homepage = "http://rapier.rs"
repository = "https://github.com/dimforge/bevy_rapier"
readme = "../README.md"
keywords = [ "physics", "dynamics", "rigid", "real-time", "joints" ]
license = "Apache-2.0"
edition = "2021"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim3", "f64" ]

[features]
default = [ "dim3", "async-collider", "debug-render-3d", "f64" ]
dim3 = []
f64 = []
debug-render = [ "debug-render-3d" ]
debug-render-2d = [ "bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier3d-f64/debug-render", "bevy/bevy_asset" ]
debug-render-3d = [ "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier3d-f64/debug-render", "bevy/bevy_asset" ]
parallel = [ "rapier3d-f64/parallel" ]
simd-stable = [ "rapier3d-f64/simd-stable" ]
simd-nightly = [ "rapier3d-f64/simd-nightly" ]
wasm-bindgen = [ "rapier3d-f64/wasm-bindgen" ]
serde-serialize = [ "rapier3d-f64/serde-serialize", "bevy/serialize", "serde" ]
enhanced-determinism = [ "rapier3d-f64/enhanced-determinism" ]
headless = [ ]
async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ]

[dependencies]
bevy = { version = "0.11", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] }
# Don't enable the default features because we don't need the ColliderSet/RigidBodySet
rapier3d-f64 = "0.17"
bitflags = "2.4"
#bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true }
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}

[dev-dependencies]
bevy = { version = "0.11", default-features = false, features = ["x11"]}
approx = "0.5.1"
glam = { version = "0.24", features = [ "approx" ] }

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
features = [ "debug-render-3d", "serde-serialize" ]
34 changes: 17 additions & 17 deletions src/dynamics/fixed_joint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dynamics::{GenericJoint, GenericJointBuilder};
use crate::math::{Rot, Vect};
use crate::math::{AsPrecise, Rot, Vect};
use rapier::dynamics::JointAxesMask;

#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -41,8 +41,8 @@ impl FixedJoint {
}

/// Sets the joint’s basis, expressed in the first rigid-body’s local-space.
pub fn set_local_basis1(&mut self, local_basis: Rot) -> &mut Self {
self.data.set_local_basis1(local_basis);
pub fn set_local_basis1(&mut self, local_basis: impl AsPrecise<Out = Rot>) -> &mut Self {
self.data.set_local_basis1(local_basis.as_precise());
self
}

Expand All @@ -53,8 +53,8 @@ impl FixedJoint {
}

/// Sets joint’s basis, expressed in the second rigid-body’s local-space.
pub fn set_local_basis2(&mut self, local_basis: Rot) -> &mut Self {
self.data.set_local_basis2(local_basis);
pub fn set_local_basis2(&mut self, local_basis: impl AsPrecise<Out = Rot>) -> &mut Self {
self.data.set_local_basis2(local_basis.as_precise());
self
}

Expand All @@ -65,8 +65,8 @@ impl FixedJoint {
}

/// Sets the joint’s anchor, expressed in the local-space of the first rigid-body.
pub fn set_local_anchor1(&mut self, anchor1: Vect) -> &mut Self {
self.data.set_local_anchor1(anchor1);
pub fn set_local_anchor1(&mut self, anchor1: impl AsPrecise<Out = Vect>) -> &mut Self {
self.data.set_local_anchor1(anchor1.as_precise());
self
}

Expand All @@ -77,8 +77,8 @@ impl FixedJoint {
}

/// Sets the joint’s anchor, expressed in the local-space of the second rigid-body.
pub fn set_local_anchor2(&mut self, anchor2: Vect) -> &mut Self {
self.data.set_local_anchor2(anchor2);
pub fn set_local_anchor2(&mut self, anchor2: impl AsPrecise<Out = Vect>) -> &mut Self {
self.data.set_local_anchor2(anchor2.as_precise());
self
}
}
Expand All @@ -101,29 +101,29 @@ impl FixedJointBuilder {

/// Sets the joint’s basis, expressed in the first rigid-body’s local-space.
#[must_use]
pub fn local_basis1(mut self, local_basis: Rot) -> Self {
self.0.set_local_basis1(local_basis);
pub fn local_basis1(mut self, local_basis: impl AsPrecise<Out = Rot>) -> Self {
self.0.set_local_basis1(local_basis.as_precise());
self
}

/// Sets joint’s basis, expressed in the second rigid-body’s local-space.
#[must_use]
pub fn local_basis2(mut self, local_basis: Rot) -> Self {
self.0.set_local_basis2(local_basis);
pub fn local_basis2(mut self, local_basis: impl AsPrecise<Out = Rot>) -> Self {
self.0.set_local_basis2(local_basis.as_precise());
self
}

/// Sets the joint’s anchor, expressed in the local-space of the first rigid-body.
#[must_use]
pub fn local_anchor1(mut self, anchor1: Vect) -> Self {
self.0.set_local_anchor1(anchor1);
pub fn local_anchor1(mut self, anchor1: impl AsPrecise<Out = Vect>) -> Self {
self.0.set_local_anchor1(anchor1.as_precise());
self
}

/// Sets the joint’s anchor, expressed in the local-space of the second rigid-body.
#[must_use]
pub fn local_anchor2(mut self, anchor2: Vect) -> Self {
self.0.set_local_anchor2(anchor2);
pub fn local_anchor2(mut self, anchor2: impl AsPrecise<Out = Vect>) -> Self {
self.0.set_local_anchor2(anchor2.as_precise());
self
}

Expand Down
Loading