Skip to content

Commit 604f385

Browse files
committed
feat: rename AxisMask to AxesMask + enable LIN_Z only in 3D
1 parent c10c08f commit 604f385

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Add `PdController` and `PidController` for making it easier to control dynamic rigid-bodies at the velocity level.
66
This can for example be used as a building block for a dynamic character controller.
7-
- Add `RigidBodyPosition::pose_errors` which computes the translational and rotational delta between
7+
- Add `RigidBodyPosition::pose_errors` to compute the translational and rotational delta between
88
`RigidBodyPosition::position` and `::next_position`.
99
- Implement `Sub` for `RigidBodyVelocity`.
1010
- Add `RigidBody::local_center_of_mass()` to get its center-of-mass in the rigid-body’s local-space.
@@ -103,9 +103,9 @@ This release introduces two new crates:
103103

104104
### Modified
105105

106-
- Renamed `JointAxesMask::X/Y/Z` to `::LIN_X/LIN_Y/LIN_Z`; and renamed `JointAxisMask::X/Y/Z` to `::LinX/LinY/LynZ` to
106+
- Renamed `JointAxesMask::X/Y/Z` to `::LIN_X/LIN_Y/LIN_Z`; and renamed `JointAxesMask::X/Y/Z` to `::LinX/LinY/LynZ` to
107107
make it clear it is not to be used as angular axes (the angular axis are `JointAxesMask::ANG_X/ANG_Y/AngZ` and
108-
`JointAxisMask::AngX/AngY/AngZ`).
108+
`JointAxesMask::AngX/AngY/AngZ`).
109109
- The contact constraints regularization parameters have been changed from `erp/damping_ratio` to
110110
`natural_frequency/damping_ratio`. This helps define them in a timestep-length independent way. The new variables
111111
are named `IntegrationParameters::contact_natural_frequency` and `IntegrationParameters::contact_damping_ratio`.

examples2d/utils/character.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ fn update_pid_controller(
9595
// - If the user is jumping, enable control over Y.
9696
// - If the user isn’t pressing any key, disable all linear controls to let
9797
// gravity/collision do their thing freely.
98-
let mut axes = AxisMask::ANG_Z;
98+
let mut axes = AxesMask::ANG_Z;
9999

100100
if desired_movement.norm() != 0.0 {
101101
axes |= if desired_movement.y == 0.0 {
102-
AxisMask::LIN_X
102+
AxesMask::LIN_X
103103
} else {
104-
AxisMask::LIN_X | AxisMask::LIN_Y
104+
AxesMask::LIN_X | AxesMask::LIN_Y
105105
}
106106
};
107107

examples3d/utils/character.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ fn update_pid_controller(
106106
// - If the user is jumping, enable control over Y.
107107
// - If the user isn’t pressing any key, disable all linear controls to let
108108
// gravity/collision do their thing freely.
109-
let mut axes = AxisMask::ANG_X | AxisMask::ANG_Y | AxisMask::ANG_Z;
109+
let mut axes = AxesMask::ANG_X | AxesMask::ANG_Y | AxesMask::ANG_Z;
110110

111111
if desired_movement.norm() != 0.0 {
112112
axes |= if desired_movement.y == 0.0 {
113-
AxisMask::LIN_X | AxisMask::LIN_Z
113+
AxesMask::LIN_X | AxesMask::LIN_Z
114114
} else {
115-
AxisMask::LIN_X | AxisMask::LIN_Z | AxisMask::LIN_Y
115+
AxesMask::LIN_X | AxesMask::LIN_Z | AxesMask::LIN_Y
116116
}
117117
};
118118

src/control/pid_controller.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::dynamics::{AxisMask, RigidBody, RigidBodyPosition, RigidBodyVelocity};
1+
use crate::dynamics::{AxesMask, RigidBody, RigidBodyPosition, RigidBodyVelocity};
22
use crate::math::{Isometry, Point, Real, Rotation, Vector};
33
use parry::math::AngVector;
44

@@ -38,12 +38,12 @@ pub struct PdController {
3838
///
3939
/// Only coordinate axes with a bit flags set to `true` will be taken into
4040
/// account when calculating the errors and corrections.
41-
pub axes: AxisMask,
41+
pub axes: AxesMask,
4242
}
4343

4444
impl Default for PdController {
4545
fn default() -> Self {
46-
Self::new(60.0, 0.8, AxisMask::all())
46+
Self::new(60.0, 0.8, AxesMask::all())
4747
}
4848
}
4949

@@ -67,7 +67,7 @@ pub struct PidController {
6767

6868
impl Default for PidController {
6969
fn default() -> Self {
70-
Self::new(60.0, 1.0, 0.8, AxisMask::all())
70+
Self::new(60.0, 1.0, 0.8, AxesMask::all())
7171
}
7272
}
7373

@@ -96,7 +96,7 @@ impl PdController {
9696
///
9797
/// Only the axes specified in `axes` will be enabled (but the gain values are set
9898
/// on all axes regardless).
99-
pub fn new(kp: Real, kd: Real, axes: AxisMask) -> PdController {
99+
pub fn new(kp: Real, kd: Real, axes: AxesMask) -> PdController {
100100
#[cfg(feature = "dim2")]
101101
return Self {
102102
lin_kp: Vector::repeat(kp),
@@ -189,27 +189,27 @@ impl PdController {
189189
fn lin_mask(&self) -> Vector<Real> {
190190
#[cfg(feature = "dim2")]
191191
return Vector::new(
192-
self.axes.contains(AxisMask::LIN_X) as u32 as Real,
193-
self.axes.contains(AxisMask::LIN_Y) as u32 as Real,
192+
self.axes.contains(AxesMask::LIN_X) as u32 as Real,
193+
self.axes.contains(AxesMask::LIN_Y) as u32 as Real,
194194
);
195195
#[cfg(feature = "dim3")]
196196
return Vector::new(
197-
self.axes.contains(AxisMask::LIN_X) as u32 as Real,
198-
self.axes.contains(AxisMask::LIN_Y) as u32 as Real,
199-
self.axes.contains(AxisMask::LIN_Z) as u32 as Real,
197+
self.axes.contains(AxesMask::LIN_X) as u32 as Real,
198+
self.axes.contains(AxesMask::LIN_Y) as u32 as Real,
199+
self.axes.contains(AxesMask::LIN_Z) as u32 as Real,
200200
);
201201
}
202202

203203
/// Mask where each component is 1.0 or 0.0 depending on whether
204204
/// the corresponding angular axis is enabled.
205205
fn ang_mask(&self) -> AngVector<Real> {
206206
#[cfg(feature = "dim2")]
207-
return self.axes.contains(AxisMask::ANG_Z) as u32 as Real;
207+
return self.axes.contains(AxesMask::ANG_Z) as u32 as Real;
208208
#[cfg(feature = "dim3")]
209209
return Vector::new(
210-
self.axes.contains(AxisMask::ANG_X) as u32 as Real,
211-
self.axes.contains(AxisMask::ANG_Y) as u32 as Real,
212-
self.axes.contains(AxisMask::ANG_Z) as u32 as Real,
210+
self.axes.contains(AxesMask::ANG_X) as u32 as Real,
211+
self.axes.contains(AxesMask::ANG_Y) as u32 as Real,
212+
self.axes.contains(AxesMask::ANG_Z) as u32 as Real,
213213
);
214214
}
215215

@@ -245,7 +245,7 @@ impl PidController {
245245
///
246246
/// Only the axes specified in `axes` will be enabled (but the gain values are set
247247
/// on all axes regardless).
248-
pub fn new(kp: Real, ki: Real, kd: Real, axes: AxisMask) -> PidController {
248+
pub fn new(kp: Real, ki: Real, kd: Real, axes: AxesMask) -> PidController {
249249
#[cfg(feature = "dim2")]
250250
return Self {
251251
pd: PdController::new(kp, kd, axes),
@@ -268,12 +268,12 @@ impl PidController {
268268
/// Set the axes errors and corrections are computed for.
269269
///
270270
/// This doesn’t modify any of the gains.
271-
pub fn set_axes(&mut self, axes: AxisMask) {
271+
pub fn set_axes(&mut self, axes: AxesMask) {
272272
self.pd.axes = axes;
273273
}
274274

275275
/// Get the axes errors and corrections are computed for.
276-
pub fn axes(&self) -> AxisMask {
276+
pub fn axes(&self) -> AxesMask {
277277
self.pd.axes
278278
}
279279

src/dynamics/rigid_body_components.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,13 @@ bitflags::bitflags! {
228228
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
229229
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
230230
/// Flags affecting the behavior of the constraints solver for a given contact manifold.
231-
pub struct AxisMask: u8 {
231+
pub struct AxesMask: u8 {
232232
/// The translational X axis.
233233
const LIN_X = 1 << 0;
234234
/// The translational Y axis.
235235
const LIN_Y = 1 << 1;
236236
/// The translational Z axis.
237+
#[cfg(feature = "dim3")]
237238
const LIN_Z = 1 << 2;
238239
/// The rotational X axis.
239240
#[cfg(feature = "dim3")]
@@ -246,9 +247,9 @@ bitflags::bitflags! {
246247
}
247248
}
248249

249-
impl Default for AxisMask {
250+
impl Default for AxesMask {
250251
fn default() -> Self {
251-
AxisMask::empty()
252+
AxesMask::empty()
252253
}
253254
}
254255

0 commit comments

Comments
 (0)