Skip to content

Commit

Permalink
Remove Deref from AngularVelocity in 2D
Browse files Browse the repository at this point in the history
Numbers have `.to_radians()`, but angular velocity is already in radians,
which can lead to incorrect usage.
  • Loading branch information
Jondolf committed Jun 17, 2023
1 parent fbcea35 commit 457259b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub struct PreSolveLinearVelocity(pub Vector);

/// The angular velocity of a body in radians. Positive values will result in counter-clockwise rotation.
#[cfg(feature = "2d")]
#[derive(Reflect, Clone, Copy, Component, Debug, Default, Deref, DerefMut, PartialEq, From)]
#[derive(Reflect, Clone, Copy, Component, Debug, Default, PartialEq, From)]
#[reflect(Component)]
pub struct AngularVelocity(pub Scalar);

Expand All @@ -165,7 +165,7 @@ impl From<Vec3> for AngularVelocity {

/// The angular velocity of a body in radians before the velocity solve is performed. Positive values will result in counter-clockwise rotation.
#[cfg(feature = "2d")]
#[derive(Reflect, Clone, Copy, Component, Debug, Default, Deref, DerefMut, PartialEq, From)]
#[derive(Reflect, Clone, Copy, Component, Debug, Default, PartialEq, From)]
#[reflect(Component)]
pub struct PreSolveAngularVelocity(pub Scalar);

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/integrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ fn integrate_rot(
if rb.is_dynamic() {
let delta_ang_vel = sub_dt.0
* inverse_inertia.rotated(&rot).0
* (external_torque.0 - ang_vel.cross(inertia.rotated(&rot).0 * ang_vel.0));
* (external_torque.0 - ang_vel.0.cross(inertia.rotated(&rot).0 * ang_vel.0));
ang_vel.0 += delta_ang_vel;
}

let q = Quaternion::from_vec4(ang_vel.extend(0.0)) * rot.0;
let q = Quaternion::from_vec4(ang_vel.0.extend(0.0)) * rot.0;
let (x, y, z, w) = (
rot.x + sub_dt.0 * 0.5 * q.x,
rot.y + sub_dt.0 * 0.5 * q.y,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ fn update_aabb(
let lin_vel_len = lin_vel.map_or(0.0, |v| v.length());

#[cfg(feature = "2d")]
let ang_vel_len = ang_vel.map_or(0.0, |v| v.abs());
let ang_vel_len = ang_vel.map_or(0.0, |v| v.0.abs());
#[cfg(feature = "3d")]
let ang_vel_len = ang_vel.map_or(0.0, |v| v.length());
let ang_vel_len = ang_vel.map_or(0.0, |v| v.0.length());

let computed_aabb = collider_query
.collider
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/sleeping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn mark_sleeping_bodies(
let lin_vel_sq = lin_vel.length_squared();

#[cfg(feature = "2d")]
let ang_vel_sq = ang_vel.powi(2);
let ang_vel_sq = ang_vel.0.powi(2);
#[cfg(feature = "3d")]
let ang_vel_sq = ang_vel.dot(ang_vel.0);
let ang_vel_sq = ang_vel.0.dot(ang_vel.0);

// Negative thresholds indicate that sleeping is disabled.
let lin_sleeping_threshold_sq = sleep_threshold.linear * sleep_threshold.linear.abs();
Expand Down

0 comments on commit 457259b

Please sign in to comment.