Skip to content

Commit

Permalink
Rename more properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf committed Jun 17, 2023
1 parent f61d673 commit 3d2edfe
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 141 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_xpbd_3d/examples/custom_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl XpbdConstraint<2> for CustomDistanceConstraint {
let [r1, r2] = [Vector::ZERO, Vector::ZERO];

// Compute the positional difference
let delta_x = body1.pos.0 - body2.pos.0;
let delta_x = body1.position.0 - body2.position.0;

// The current separation distance
let length = delta_x.length();
Expand Down
24 changes: 12 additions & 12 deletions src/components/world_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::ops::{AddAssign, SubAssign};
pub struct RigidBodyQuery {
pub entity: Entity,
pub rb: &'static mut RigidBody,
pub pos: &'static mut Position,
pub rot: &'static mut Rotation,
pub prev_pos: &'static mut PreviousPosition,
pub prev_rot: &'static mut PreviousRotation,
pub lin_vel: &'static mut LinearVelocity,
pub pre_solve_lin_vel: &'static mut PreSolveLinearVelocity,
pub ang_vel: &'static mut AngularVelocity,
pub pre_solve_ang_vel: &'static mut PreSolveAngularVelocity,
pub position: &'static mut Position,
pub rotation: &'static mut Rotation,
pub previous_position: &'static mut PreviousPosition,
pub previous_rotation: &'static mut PreviousRotation,
pub linear_velocity: &'static mut LinearVelocity,
pub pre_solve_linear_velocity: &'static mut PreSolveLinearVelocity,
pub angular_velocity: &'static mut AngularVelocity,
pub pre_solve_angular_velocity: &'static mut PreSolveAngularVelocity,
pub mass: &'static mut Mass,
pub inverse_mass: &'static mut InverseMass,
pub inertia: &'static mut Inertia,
Expand All @@ -35,13 +35,13 @@ impl<'w> RigidBodyQueryItem<'w> {
// Computes the world-space inverse inertia tensor.
#[cfg(feature = "3d")]
pub fn world_inv_inertia(&self) -> InverseInertia {
self.inverse_inertia.rotated(&self.rot)
self.inverse_inertia.rotated(&self.rotation)
}
}

#[derive(WorldQuery)]
#[world_query(mutable)]
pub(crate) struct MassPropsQuery {
pub(crate) struct MassPropertiesQuery {
pub mass: &'static mut Mass,
pub inverse_mass: &'static mut InverseMass,
pub inertia: &'static mut Inertia,
Expand All @@ -58,7 +58,7 @@ pub(crate) struct ColliderQuery {
pub previous_mass_properties: &'static mut PreviousColliderMassProperties,
}

impl<'w> AddAssign<ColliderMassProperties> for MassPropsQueryItem<'w> {
impl<'w> AddAssign<ColliderMassProperties> for MassPropertiesQueryItem<'w> {
fn add_assign(&mut self, rhs: ColliderMassProperties) {
self.mass.0 += rhs.mass.0;
self.inverse_mass.0 = 1.0 / self.mass.0;
Expand All @@ -68,7 +68,7 @@ impl<'w> AddAssign<ColliderMassProperties> for MassPropsQueryItem<'w> {
}
}

impl<'w> SubAssign<ColliderMassProperties> for MassPropsQueryItem<'w> {
impl<'w> SubAssign<ColliderMassProperties> for MassPropertiesQueryItem<'w> {
fn sub_assign(&mut self, rhs: ColliderMassProperties) {
self.mass.0 -= rhs.mass.0;
self.inverse_mass.0 = 1.0 / self.mass.0;
Expand Down
16 changes: 8 additions & 8 deletions src/constraints/angular_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ pub trait AngularConstraint: XpbdConstraint<2> {
// `axis.z` is 1 or -1 and it controls if the body should rotate counterclockwise or clockwise
let p = -delta_lagrange * axis.z;

let rot1 = *body1.rot;
let rot2 = *body2.rot;
let rot1 = *body1.rotation;
let rot2 = *body2.rotation;

let inv_inertia1 = body1.world_inv_inertia().0;
let inv_inertia2 = body2.world_inv_inertia().0;

// Apply rotational updates
if body1.rb.is_dynamic() {
*body1.rot += Self::get_delta_rot(rot1, inv_inertia1, p);
*body1.rotation += Self::get_delta_rot(rot1, inv_inertia1, p);
}
if body2.rb.is_dynamic() {
*body2.rot -= Self::get_delta_rot(rot2, inv_inertia2, p);
*body2.rotation -= Self::get_delta_rot(rot2, inv_inertia2, p);
}

p
Expand All @@ -60,18 +60,18 @@ pub trait AngularConstraint: XpbdConstraint<2> {
// Compute angular impulse
let p = -delta_lagrange * axis;

let rot1 = *body1.rot;
let rot2 = *body2.rot;
let rot1 = *body1.rotation;
let rot2 = *body2.rotation;

let inv_inertia1 = body1.world_inv_inertia().0;
let inv_inertia2 = body2.world_inv_inertia().0;

// Apply rotational updates
if body1.rb.is_dynamic() {
*body1.rot += Self::get_delta_rot(rot1, inv_inertia1, p);
*body1.rotation += Self::get_delta_rot(rot1, inv_inertia1, p);
}
if body2.rb.is_dynamic() {
*body2.rot -= Self::get_delta_rot(rot2, inv_inertia2, p);
*body2.rotation -= Self::get_delta_rot(rot2, inv_inertia2, p);
}

p
Expand Down
32 changes: 16 additions & 16 deletions src/constraints/joints/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub struct FixedJoint {
/// Attachment point on the second body.
pub local_anchor2: Vector,
/// Linear damping applied by the joint.
pub damping_lin: Scalar,
pub damping_linear: Scalar,
/// Angular damping applied by the joint.
pub damping_ang: Scalar,
pub damping_angular: Scalar,
/// Lagrange multiplier for the positional correction.
pub pos_lagrange: Scalar,
pub position_lagrange: Scalar,
/// Lagrange multiplier for the angular correction caused by the alignment of the bodies.
pub align_lagrange: Scalar,
/// The joint's compliance, the inverse of stiffness, has the unit meters / Newton.
Expand All @@ -39,7 +39,7 @@ impl XpbdConstraint<2> for FixedJoint {
}

fn clear_lagrange_multipliers(&mut self) {
self.pos_lagrange = 0.0;
self.position_lagrange = 0.0;
self.align_lagrange = 0.0;
}

Expand All @@ -48,13 +48,13 @@ impl XpbdConstraint<2> for FixedJoint {
let compliance = self.compliance;

// Align orientation
let dq = self.get_delta_q(&body1.rot, &body2.rot);
let dq = self.get_delta_q(&body1.rotation, &body2.rotation);
let mut lagrange = self.align_lagrange;
self.align_torque = self.align_orientation(body1, body2, dq, &mut lagrange, compliance, dt);
self.align_lagrange = lagrange;

// Align position of local attachment points
let mut lagrange = self.pos_lagrange;
let mut lagrange = self.position_lagrange;
self.force = self.align_position(
body1,
body2,
Expand All @@ -64,7 +64,7 @@ impl XpbdConstraint<2> for FixedJoint {
compliance,
dt,
);
self.pos_lagrange = lagrange;
self.position_lagrange = lagrange;
}
}

Expand All @@ -75,9 +75,9 @@ impl Joint for FixedJoint {
entity2,
local_anchor1: Vector::ZERO,
local_anchor2: Vector::ZERO,
damping_lin: 1.0,
damping_ang: 1.0,
pos_lagrange: 0.0,
damping_linear: 1.0,
damping_angular: 1.0,
position_lagrange: 0.0,
align_lagrange: 0.0,
compliance: 0.0,
force: Vector::ZERO,
Expand Down Expand Up @@ -108,24 +108,24 @@ impl Joint for FixedJoint {

fn with_lin_vel_damping(self, damping: Scalar) -> Self {
Self {
damping_lin: damping,
damping_linear: damping,
..self
}
}

fn with_ang_vel_damping(self, damping: Scalar) -> Self {
Self {
damping_ang: damping,
damping_angular: damping,
..self
}
}

fn damping_lin(&self) -> Scalar {
self.damping_lin
fn damping_linear(&self) -> Scalar {
self.damping_linear
}

fn damping_ang(&self) -> Scalar {
self.damping_ang
fn damping_angular(&self) -> Scalar {
self.damping_angular
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/constraints/joints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ pub trait Joint: Component + PositionConstraint + AngularConstraint {
fn with_ang_vel_damping(self, damping: Scalar) -> Self;

/// Returns the linear velocity damping of the joint.
fn damping_lin(&self) -> Scalar;
fn damping_linear(&self) -> Scalar;

/// Returns the angular velocity damping of the joint.
fn damping_ang(&self) -> Scalar;
fn damping_angular(&self) -> Scalar;

/// Applies a positional correction that aligns the positions of the local attachment points `r1` and `r2`.
///
Expand All @@ -53,11 +53,11 @@ pub trait Joint: Component + PositionConstraint + AngularConstraint {
compliance: Scalar,
dt: Scalar,
) -> Vector {
let world_r1 = body1.rot.rotate(r1);
let world_r2 = body2.rot.rotate(r2);
let world_r1 = body1.rotation.rotate(r1);
let world_r2 = body2.rotation.rotate(r2);

let delta_x = DistanceLimit::new(0.0, 0.0)
.compute_correction(body1.pos.0 + world_r1, body2.pos.0 + world_r2);
.compute_correction(body1.position.0 + world_r1, body2.position.0 + world_r2);
let magnitude = delta_x.length();

if magnitude <= Scalar::EPSILON {
Expand Down
56 changes: 28 additions & 28 deletions src/constraints/joints/prismatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub struct PrismaticJoint {
/// The extents of the allowed relative translation along the free axis.
pub free_axis_limits: Option<DistanceLimit>,
/// Linear damping applied by the joint.
pub damping_lin: Scalar,
pub damping_linear: Scalar,
/// Angular damping applied by the joint.
pub damping_ang: Scalar,
pub damping_angular: Scalar,
/// Lagrange multiplier for the positional correction.
pub pos_lagrange: Scalar,
pub position_lagrange: Scalar,
/// Lagrange multiplier for the angular correction caused by the alignment of the bodies.
pub align_lagrange: Scalar,
/// The joint's compliance, the inverse of stiffness, has the unit meters / Newton.
Expand All @@ -42,7 +42,7 @@ impl XpbdConstraint<2> for PrismaticJoint {
}

fn clear_lagrange_multipliers(&mut self) {
self.pos_lagrange = 0.0;
self.position_lagrange = 0.0;
self.align_lagrange = 0.0;
}

Expand All @@ -51,7 +51,7 @@ impl XpbdConstraint<2> for PrismaticJoint {
let compliance = self.compliance;

// Align orientations
let dq = self.get_delta_q(&body1.rot, &body2.rot);
let dq = self.get_delta_q(&body1.rotation, &body2.rotation);
let mut lagrange = self.align_lagrange;
self.align_torque = self.align_orientation(body1, body2, dq, &mut lagrange, compliance, dt);
self.align_lagrange = lagrange;
Expand All @@ -70,9 +70,9 @@ impl Joint for PrismaticJoint {
local_anchor2: Vector::ZERO,
free_axis: Vector::X,
free_axis_limits: None,
damping_lin: 1.0,
damping_ang: 1.0,
pos_lagrange: 0.0,
damping_linear: 1.0,
damping_angular: 1.0,
position_lagrange: 0.0,
align_lagrange: 0.0,
compliance: 0.0,
force: Vector::ZERO,
Expand Down Expand Up @@ -103,24 +103,24 @@ impl Joint for PrismaticJoint {

fn with_lin_vel_damping(self, damping: Scalar) -> Self {
Self {
damping_lin: damping,
damping_linear: damping,
..self
}
}

fn with_ang_vel_damping(self, damping: Scalar) -> Self {
Self {
damping_ang: damping,
damping_angular: damping,
..self
}
}

fn damping_lin(&self) -> Scalar {
self.damping_lin
fn damping_linear(&self) -> Scalar {
self.damping_linear
}

fn damping_ang(&self) -> Scalar {
self.damping_ang
fn damping_angular(&self) -> Scalar {
self.damping_angular
}
}

Expand All @@ -134,16 +134,16 @@ impl PrismaticJoint {
body2: &mut RigidBodyQueryItem,
dt: Scalar,
) -> Vector {
let world_r1 = body1.rot.rotate(self.local_anchor1);
let world_r2 = body2.rot.rotate(self.local_anchor2);
let world_r1 = body1.rotation.rotate(self.local_anchor1);
let world_r2 = body2.rotation.rotate(self.local_anchor2);

let mut delta_x = Vector::ZERO;

let axis1 = body1.rot.rotate(self.free_axis);
let axis1 = body1.rotation.rotate(self.free_axis);
if let Some(limits) = self.free_axis_limits {
delta_x += limits.compute_correction_along_axis(
body1.pos.0 + world_r1,
body2.pos.0 + world_r2,
body1.position.0 + world_r1,
body2.position.0 + world_r2,
axis1,
);
}
Expand All @@ -154,8 +154,8 @@ impl PrismaticJoint {
{
let axis2 = Vector::new(axis1.y, -axis1.x);
delta_x += zero_distance_limit.compute_correction_along_axis(
body1.pos.0 + world_r1,
body2.pos.0 + world_r2,
body1.position.0 + world_r1,
body2.position.0 + world_r2,
axis2,
);
}
Expand All @@ -165,13 +165,13 @@ impl PrismaticJoint {
let axis3 = axis1.cross(axis2);

delta_x += zero_distance_limit.compute_correction_along_axis(
body1.pos.0 + world_r1,
body2.pos.0 + world_r2,
body1.position.0 + world_r1,
body2.position.0 + world_r2,
axis2,
);
delta_x += zero_distance_limit.compute_correction_along_axis(
body1.pos.0 + world_r1,
body2.pos.0 + world_r2,
body1.position.0 + world_r1,
body2.position.0 + world_r2,
axis3,
);
}
Expand All @@ -194,20 +194,20 @@ impl PrismaticJoint {

// Compute Lagrange multiplier update
let delta_lagrange = self.compute_lagrange_update(
self.pos_lagrange,
self.position_lagrange,
magnitude,
&gradients,
&w,
self.compliance,
dt,
);
self.pos_lagrange += delta_lagrange;
self.position_lagrange += delta_lagrange;

// Apply positional correction to align the positions of the bodies
self.apply_positional_correction(body1, body2, delta_lagrange, dir, world_r1, world_r2);

// Return constraint force
self.compute_force(self.pos_lagrange, dir, dt)
self.compute_force(self.position_lagrange, dir, dt)
}

/// Sets the joint's free axis. Relative translations are allowed along this free axis.
Expand Down
Loading

0 comments on commit 3d2edfe

Please sign in to comment.