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

Lighter wrappers for rapier types #529

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
11 changes: 7 additions & 4 deletions bevy_rapier2d/examples/debug_despawn2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// in https://github.com/dimforge/bevy_rapier/issues/75

use bevy::prelude::*;
use bevy_rapier2d::dynamics::RevoluteJointBuilderGlam;
use bevy_rapier2d::prelude::*;
use rapier2d::dynamics::RevoluteJointBuilder;

fn main() {
App::new()
Expand Down Expand Up @@ -172,10 +174,11 @@ fn spawn_cube(commands: &mut Commands, game: &mut Game) {
let id = children
.spawn(ImpulseJoint::new(
block_entities[*i],
RevoluteJointBuilder::new()
.local_anchor1(anchor_1)
.local_anchor2(anchor_2)
.build(),
RevoluteJointBuilder::new_glam()
.local_anchor1_glam(anchor_1)
.local_anchor2_glam(anchor_2)
.build()
.data,
))
.id();
game.current_cube_joints.push(id);
Expand Down
11 changes: 7 additions & 4 deletions bevy_rapier2d/examples/joints2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use rapier2d::dynamics::RevoluteJointBuilder;

fn main() {
App::new()
Expand Down Expand Up @@ -55,25 +56,27 @@ pub fn setup_physics(mut commands: Commands) {
// Vertical joint.
if i > 0 {
let parent_entity = *body_entities.last().unwrap();
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(0.0, shift));
let joint =
RevoluteJointBuilder::new_glam().local_anchor2_glam(Vec2::new(0.0, shift));
commands.entity(child_entity).with_children(|cmd| {
// NOTE: we want to attach multiple impulse joints to this entity, so
// we need to add the components to children of the entity. Otherwise
// the second joint component would just overwrite the first one.
cmd.spawn(ImpulseJoint::new(parent_entity, joint));
cmd.spawn(ImpulseJoint::new(parent_entity, joint.build().data));
});
}

// Horizontal joint.
if k > 0 {
let parent_index = body_entities.len() - numi;
let parent_entity = body_entities[parent_index];
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(-shift, 0.0));
let joint =
RevoluteJointBuilder::new_glam().local_anchor2_glam(Vec2::new(-shift, 0.0));
commands.entity(child_entity).with_children(|cmd| {
// NOTE: we want to attach multiple impulse joints to this entity, so
// we need to add the components to children of the entity. Otherwise
// the second joint component would just overwrite the first one.
cmd.spawn(ImpulseJoint::new(parent_entity, joint));
cmd.spawn(ImpulseJoint::new(parent_entity, joint.build().data));
});
}

Expand Down
12 changes: 8 additions & 4 deletions bevy_rapier2d/examples/joints_despawn2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use rapier2d::dynamics::RevoluteJointBuilder;

#[derive(Component, Default)]
pub struct Despawn;
Expand Down Expand Up @@ -67,12 +68,14 @@ pub fn setup_physics(mut commands: Commands, mut despawn: ResMut<DespawnResource
// Vertical joint.
if i > 0 {
let parent_entity = *body_entities.last().unwrap();
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(0.0, shift));
let joint =
RevoluteJointBuilder::new_glam().local_anchor2_glam(Vec2::new(0.0, shift));
commands.entity(child_entity).with_children(|cmd| {
// NOTE: we want to attach multiple impulse joints to this entity, so
// we need to add the components to children of the entity. Otherwise
// the second joint component would just overwrite the first one.
let mut entity = cmd.spawn(ImpulseJoint::new(parent_entity, joint));
let mut entity =
cmd.spawn(ImpulseJoint::new(parent_entity, joint.build().data));
if i == (numi / 2) || (k % 4 == 0 || k == numk - 1) {
entity.insert(Despawn);
}
Expand All @@ -83,12 +86,13 @@ pub fn setup_physics(mut commands: Commands, mut despawn: ResMut<DespawnResource
if k > 0 {
let parent_index = body_entities.len() - numi;
let parent_entity = body_entities[parent_index];
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(-shift, 0.0));
let joint = RevoluteJointBuilder::new().local_anchor2_glam(Vec2::new(-shift, 0.0));
commands.entity(child_entity).with_children(|cmd| {
// NOTE: we want to attach multiple impulse joints to this entity, so
// we need to add the components to children of the entity. Otherwise
// the second joint component would just overwrite the first one.
let mut entity = cmd.spawn(ImpulseJoint::new(parent_entity, joint));
let mut entity =
cmd.spawn(ImpulseJoint::new(parent_entity, joint.build().data));
if i == (numi / 2) || (k % 4 == 0 || k == numk - 1) {
entity.insert(Despawn);
}
Expand Down
23 changes: 14 additions & 9 deletions bevy_rapier3d/examples/joints3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use rapier3d::dynamics::RevoluteJointBuilder;

use bevy_rapier3d::dynamics::RevoluteJointBuilderGlam;
//use rapier3d::dynamics::RevoluteJointBuilder;

fn main() {
App::new()
Expand Down Expand Up @@ -128,25 +132,26 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) {
let x = Vec3::X;
let z = Vec3::Z;

let revs = [
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(-shift, 0.0, 0.0)),
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(shift, 0.0, 0.0)),
let revs: [RevoluteJointBuilder; 4] = [
RevoluteJointBuilder::new_glam(z).local_anchor2_glam(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new_glam(x).local_anchor2_glam(Vec3::new(-shift, 0.0, 0.0)),
RevoluteJointBuilder::new_glam(z).local_anchor2_glam(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new_glam(x).local_anchor2_glam(Vec3::new(shift, 0.0, 0.0)),
];
let joint = ImpulseJoint::new(curr_parent, revs[0].build().data);

commands
.entity(handles[0])
.insert(ImpulseJoint::new(curr_parent, revs[0]));
.insert(ImpulseJoint::new(curr_parent, revs[0].build().data));
commands
.entity(handles[1])
.insert(ImpulseJoint::new(handles[0], revs[1]));
.insert(ImpulseJoint::new(handles[0], revs[1].build().data));
commands
.entity(handles[2])
.insert(ImpulseJoint::new(handles[1], revs[2]));
.insert(ImpulseJoint::new(handles[1], revs[2].build().data));
commands
.entity(handles[3])
.insert(ImpulseJoint::new(handles[2], revs[3]));
.insert(ImpulseJoint::new(handles[2], revs[3].build().data));

curr_parent = handles[3];
}
Expand Down
17 changes: 9 additions & 8 deletions bevy_rapier3d/examples/joints_despawn3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use rapier3d::dynamics::RevoluteJointBuilder;

#[derive(Component)]
pub struct Despawn;
Expand Down Expand Up @@ -116,24 +117,24 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) {
let z = Vec3::Z;

let revs = [
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(-shift, 0.0, 0.0)),
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(shift, 0.0, 0.0)),
RevoluteJointBuilder::new_glam(z).local_anchor2_glam(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new_glam(x).local_anchor2_glam(Vec3::new(-shift, 0.0, 0.0)),
RevoluteJointBuilder::new_glam(z).local_anchor2_glam(Vec3::new(0.0, 0.0, -shift)),
RevoluteJointBuilder::new_glam(x).local_anchor2_glam(Vec3::new(shift, 0.0, 0.0)),
];

commands
.entity(handles[0])
.insert(ImpulseJoint::new(curr_parent, revs[0]));
.insert(ImpulseJoint::new(curr_parent, revs[0].build().data));
commands
.entity(handles[1])
.insert(ImpulseJoint::new(handles[0], revs[1]));
.insert(ImpulseJoint::new(handles[0], revs[1].build().data));
commands
.entity(handles[2])
.insert(ImpulseJoint::new(handles[1], revs[2]));
.insert(ImpulseJoint::new(handles[1], revs[2].build().data));
commands
.entity(handles[3])
.insert(ImpulseJoint::new(handles[2], revs[3]));
.insert(ImpulseJoint::new(handles[2], revs[3].build().data));

curr_parent = handles[3];

Expand Down
6 changes: 6 additions & 0 deletions src/dynamics/generic_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ impl GenericJoint {
}
}

impl From<RapierGenericJoint> for GenericJoint {
fn from(joint: RapierGenericJoint) -> GenericJoint {
Self { raw: joint }
}
}

/*
* NOTE: the following are copy-pasted from Rapier’s GenericJoint, to match its
* construction methods, but using glam types.
Expand Down
Loading
Loading