-
-
Notifications
You must be signed in to change notification settings - Fork 267
rapier 0.20 feature: RevoluteJoint::angle
+ more detailed joints enum
#530
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
Changes from 11 commits
a49031a
e92ece0
4085212
ae822d7
227c23c
f4d1f32
e3ef235
cce0ce3
3c642d0
b4016ab
5b7363f
e537660
d0299c5
7f173ea
2a1e5d1
dd7ede2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,73 @@ | ||
use crate::dynamics::GenericJoint; | ||
use bevy::prelude::*; | ||
use rapier::dynamics::{ImpulseJointHandle, MultibodyJointHandle}; | ||
|
||
pub use rapier::dynamics::{JointAxesMask, JointAxis, MotorModel}; | ||
|
||
use super::{FixedJoint, GenericJoint, PrismaticJoint, RevoluteJoint, RopeJoint, SpringJoint}; | ||
|
||
#[cfg(feature = "dim3")] | ||
use super::SphericalJoint; | ||
|
||
/// Wrapper enum over a specific joint. | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum JointDescription { | ||
/// See [`FixedJoint`] | ||
FixedJoint(FixedJoint), | ||
/// See [`GenericJoint`] | ||
GenericJoint(GenericJoint), | ||
/// See [`PrismaticJoint`] | ||
PrismaticJoint(PrismaticJoint), | ||
/// See [`RevoluteJoint`] | ||
RevoluteJoint(RevoluteJoint), | ||
/// See [`RopeJoint`] | ||
RopeJoint(RopeJoint), | ||
/// See [`SphericalJoint`] | ||
#[cfg(feature = "dim3")] | ||
SphericalJoint(SphericalJoint), | ||
/// See [`SpringJoint`] | ||
SpringJoint(SpringJoint), | ||
} | ||
|
||
impl JointDescription { | ||
/// The underlying generic joint. | ||
pub fn generic_joint(&self) -> &GenericJoint { | ||
match self { | ||
JointDescription::FixedJoint(j) => &j.data, | ||
JointDescription::GenericJoint(j) => j, | ||
JointDescription::PrismaticJoint(j) => &j.data, | ||
JointDescription::RevoluteJoint(j) => j.data(), | ||
JointDescription::RopeJoint(j) => j.data(), | ||
#[cfg(feature = "dim3")] | ||
JointDescription::SphericalJoint(j) => j.data(), | ||
JointDescription::SpringJoint(j) => j.data(), | ||
} | ||
} | ||
/// The underlying generic joint. | ||
pub fn generic_joint_mut(&mut self) -> &mut GenericJoint { | ||
match self { | ||
JointDescription::FixedJoint(ref mut j) => &mut j.data, | ||
JointDescription::GenericJoint(ref mut j) => j, | ||
JointDescription::PrismaticJoint(ref mut j) => &mut j.data, | ||
JointDescription::RevoluteJoint(ref mut j) => &mut j.data, | ||
JointDescription::RopeJoint(ref mut j) => &mut j.data, | ||
#[cfg(feature = "dim3")] | ||
JointDescription::SphericalJoint(ref mut j) => &mut j.data, | ||
JointDescription::SpringJoint(ref mut j) => &mut j.data, | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, I'll do that. For the story behind this explicit naming: ideally I would have liked to wrap our joints ( See #529 for similar reasoning logic. |
||
|
||
/// A trait used for different constraint types applied to joints, | ||
/// see [`ImpulseJoint`] and [`MultibodyJoint`]. | ||
pub trait JointConstraint { | ||
/// The entity containing the rigid-body used as the first endpoint of this joint. | ||
fn parent(&self) -> Entity; | ||
/// Access the joint’s description. | ||
fn data(&self) -> &JointDescription; | ||
/// Access mutably the joint’s description. | ||
fn data_mut(&mut self) -> &mut JointDescription; | ||
} | ||
Vrixyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// The handle of an impulse joint added to the physics scene. | ||
#[derive(Copy, Clone, Debug, Component)] | ||
pub struct RapierImpulseJointHandle(pub ImpulseJointHandle); | ||
|
@@ -28,12 +92,12 @@ pub struct ImpulseJoint { | |
/// The entity containing the rigid-body used as the first endpoint of this joint. | ||
pub parent: Entity, | ||
/// The joint’s description. | ||
pub data: GenericJoint, | ||
pub data: JointDescription, | ||
} | ||
|
||
impl ImpulseJoint { | ||
/// Initializes an impulse-based joint from its first endpoint and the joint description. | ||
pub fn new(parent: Entity, data: impl Into<GenericJoint>) -> Self { | ||
pub fn new(parent: Entity, data: impl Into<JointDescription>) -> Self { | ||
Self { | ||
parent, | ||
data: data.into(), | ||
|
@@ -55,16 +119,26 @@ pub struct MultibodyJoint { | |
/// The entity containing the rigid-body used as the first endpoint of this joint. | ||
pub parent: Entity, | ||
/// The joint’s description. | ||
pub data: GenericJoint, | ||
pub data: JointDescription, | ||
} | ||
|
||
impl MultibodyJoint { | ||
/// Initializes an joint based on reduced coordinates from its first endpoint and | ||
/// the joint description. | ||
pub fn new(parent: Entity, data: impl Into<GenericJoint>) -> Self { | ||
Self { | ||
parent, | ||
data: data.into(), | ||
} | ||
pub fn new(parent: Entity, data: JointDescription) -> Self { | ||
Self { parent, data } | ||
} | ||
} | ||
impl JointConstraint for ImpulseJoint { | ||
fn parent(&self) -> Entity { | ||
self.parent | ||
} | ||
|
||
fn data(&self) -> &JointDescription { | ||
&self.data | ||
} | ||
|
||
fn data_mut(&mut self) -> &mut JointDescription { | ||
&mut self.data | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.