From aa61fe65e3ff0289ecab57b4053a3410cf6d4a87 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 4 Jan 2021 15:14:25 +0100 Subject: Add support of 64-bits reals. --- src/dynamics/integration_parameters.rs | 56 +++++----- src/dynamics/joint/ball_joint.rs | 16 +-- src/dynamics/joint/fixed_joint.rs | 10 +- src/dynamics/joint/prismatic_joint.rs | 68 ++++++------ src/dynamics/joint/revolute_joint.rs | 24 ++-- src/dynamics/rigid_body.rs | 122 +++++++++++---------- src/dynamics/solver/delta_vel.rs | 4 +- src/dynamics/solver/interaction_groups.rs | 2 +- .../joint_constraint/ball_position_constraint.rs | 32 +++--- .../ball_position_constraint_wide.rs | 6 +- .../joint_constraint/ball_velocity_constraint.rs | 34 +++--- .../ball_velocity_constraint_wide.rs | 10 +- .../joint_constraint/fixed_position_constraint.rs | 40 +++---- .../joint_constraint/fixed_velocity_constraint.rs | 54 ++++----- .../fixed_velocity_constraint_wide.rs | 12 +- .../solver/joint_constraint/joint_constraint.rs | 5 +- .../joint_constraint/joint_position_constraint.rs | 4 +- .../prismatic_position_constraint.rs | 38 +++---- .../prismatic_velocity_constraint.rs | 74 ++++++------- .../prismatic_velocity_constraint_wide.rs | 10 +- .../revolute_position_constraint.rs | 34 +++--- .../revolute_velocity_constraint.rs | 44 ++++---- .../revolute_velocity_constraint_wide.rs | 10 +- src/dynamics/solver/parallel_island_solver.rs | 10 +- src/dynamics/solver/parallel_position_solver.rs | 4 +- src/dynamics/solver/parallel_velocity_solver.rs | 2 +- src/dynamics/solver/position_constraint.rs | 26 ++--- src/dynamics/solver/position_constraint_wide.rs | 6 +- src/dynamics/solver/position_ground_constraint.rs | 20 ++-- .../solver/position_ground_constraint_wide.rs | 6 +- src/dynamics/solver/position_solver.rs | 4 +- src/dynamics/solver/solver_constraints.rs | 7 +- src/dynamics/solver/velocity_constraint.rs | 28 ++--- src/dynamics/solver/velocity_constraint_wide.rs | 6 +- src/dynamics/solver/velocity_ground_constraint.rs | 20 ++-- .../solver/velocity_ground_constraint_wide.rs | 6 +- src/dynamics/solver/velocity_solver.rs | 3 +- 37 files changed, 432 insertions(+), 425 deletions(-) (limited to 'src/dynamics') diff --git a/src/dynamics/integration_parameters.rs b/src/dynamics/integration_parameters.rs index b31c3f6..706fb3f 100644 --- a/src/dynamics/integration_parameters.rs +++ b/src/dynamics/integration_parameters.rs @@ -1,11 +1,13 @@ +use crate::math::Real; + /// Parameters for a time-step of the physics engine. #[derive(Clone)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] pub struct IntegrationParameters { /// The timestep length (default: `1.0 / 60.0`) - dt: f32, + dt: Real, /// The inverse of `dt`. - inv_dt: f32, + inv_dt: Real, // /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`). // /// // /// This parameter is ignored if rapier is not compiled with is `parallel` feature. @@ -19,31 +21,31 @@ pub struct IntegrationParameters { pub return_after_ccd_substep: bool, /// The Error Reduction Parameter in `[0, 1]` is the proportion of /// the positional error to be corrected at each time step (default: `0.2`). - pub erp: f32, + pub erp: Real, /// The Error Reduction Parameter for joints in `[0, 1]` is the proportion of /// the positional error to be corrected at each time step (default: `0.2`). - pub joint_erp: f32, + pub joint_erp: Real, /// Each cached impulse are multiplied by this coefficient in `[0, 1]` /// when they are re-used to initialize the solver (default `1.0`). - pub warmstart_coeff: f32, + pub warmstart_coeff: Real, /// Contacts at points where the involved bodies have a relative /// velocity smaller than this threshold wont be affected by the restitution force (default: `1.0`). - pub restitution_velocity_threshold: f32, + pub restitution_velocity_threshold: Real, /// Amount of penetration the engine wont attempt to correct (default: `0.001m`). - pub allowed_linear_error: f32, + pub allowed_linear_error: Real, /// The maximal distance separating two objects that will generate predictive contacts (default: `0.002`). - pub prediction_distance: f32, + pub prediction_distance: Real, /// Amount of angular drift of joint limits the engine wont /// attempt to correct (default: `0.001rad`). - pub allowed_angular_error: f32, + pub allowed_angular_error: Real, /// Maximum linear correction during one step of the non-linear position solver (default: `0.2`). - pub max_linear_correction: f32, + pub max_linear_correction: Real, /// Maximum angular correction during one step of the non-linear position solver (default: `0.2`). - pub max_angular_correction: f32, + pub max_angular_correction: Real, /// Maximum nonlinear SOR-prox scaling parameter when the constraint /// correction direction is close to the kernel of the involved multibody's /// jacobian (default: `0.2`). - pub max_stabilization_multiplier: f32, + pub max_stabilization_multiplier: Real, /// Maximum number of iterations performed by the velocity constraints solver (default: `4`). pub max_velocity_iterations: usize, /// Maximum number of iterations performed by the position-based constraints solver (default: `1`). @@ -88,18 +90,18 @@ pub struct IntegrationParameters { impl IntegrationParameters { /// Creates a set of integration parameters with the given values. pub fn new( - dt: f32, + dt: Real, // multithreading_enabled: bool, - erp: f32, - joint_erp: f32, - warmstart_coeff: f32, - restitution_velocity_threshold: f32, - allowed_linear_error: f32, - allowed_angular_error: f32, - max_linear_correction: f32, - max_angular_correction: f32, - prediction_distance: f32, - max_stabilization_multiplier: f32, + erp: Real, + joint_erp: Real, + warmstart_coeff: Real, + restitution_velocity_threshold: Real, + allowed_linear_error: Real, + allowed_angular_error: Real, + max_linear_correction: Real, + max_angular_correction: Real, + prediction_distance: Real, + max_stabilization_multiplier: Real, max_velocity_iterations: usize, max_position_iterations: usize, max_ccd_position_iterations: usize, @@ -140,7 +142,7 @@ impl IntegrationParameters { /// The current time-stepping length. #[inline(always)] - pub fn dt(&self) -> f32 { + pub fn dt(&self) -> Real { self.dt } @@ -148,7 +150,7 @@ impl IntegrationParameters { /// /// This is zero if `self.dt` is zero. #[inline(always)] - pub fn inv_dt(&self) -> f32 { + pub fn inv_dt(&self) -> Real { self.inv_dt } @@ -156,7 +158,7 @@ impl IntegrationParameters { /// /// This automatically recompute `self.inv_dt`. #[inline] - pub fn set_dt(&mut self, dt: f32) { + pub fn set_dt(&mut self, dt: Real) { assert!(dt >= 0.0, "The time-stepping length cannot be negative."); self.dt = dt; if dt == 0.0 { @@ -170,7 +172,7 @@ impl IntegrationParameters { /// /// This automatically recompute `self.dt`. #[inline] - pub fn set_inv_dt(&mut self, inv_dt: f32) { + pub fn set_inv_dt(&mut self, inv_dt: Real) { self.inv_dt = inv_dt; if inv_dt == 0.0 { self.dt = 0.0 diff --git a/src/dynamics/joint/ball_joint.rs b/src/dynamics/joint/ball_joint.rs index ec255d4..82e2a10 100644 --- a/src/dynamics/joint/ball_joint.rs +++ b/src/dynamics/joint/ball_joint.rs @@ -1,29 +1,29 @@ -use crate::math::{Point, Vector}; +use crate::math::{Point, Real, Vector}; #[derive(Copy, Clone)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] /// A joint that removes all relative linear motion between a pair of points on two bodies. pub struct BallJoint { /// Where the ball joint is attached on the first body, expressed in the first body local frame. - pub local_anchor1: Point, + pub local_anchor1: Point, /// Where the ball joint is attached on the first body, expressed in the first body local frame. - pub local_anchor2: Point, + pub local_anchor2: Point, /// The impulse applied by this joint on the first body. /// /// The impulse applied to the second body is given by `-impulse`. - pub impulse: Vector, + pub impulse: Vector, } impl BallJoint { /// Creates a new Ball joint from two anchors given on the local spaces of the respective bodies. - pub fn new(local_anchor1: Point, local_anchor2: Point) -> Self { + pub fn new(local_anchor1: Point, local_anchor2: Point) -> Self { Self::with_impulse(local_anchor1, local_anchor2, Vector::zeros()) } pub(crate) fn with_impulse( - local_anchor1: Point, - local_anchor2: Point, - impulse: Vector, + local_anchor1: Point, + local_anchor2: Point, + impulse: Vector, ) -> Self { Self { local_anchor1, diff --git a/src/dynamics/joint/fixed_joint.rs b/src/dynamics/joint/fixed_joint.rs index 0731cfb..359e14a 100644 --- a/src/dynamics/joint/fixed_joint.rs +++ b/src/dynamics/joint/fixed_joint.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, SpacialVector}; +use crate::math::{Isometry, Real, SpacialVector}; #[derive(Copy, Clone)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] @@ -8,22 +8,22 @@ use crate::math::{Isometry, SpacialVector}; pub struct FixedJoint { /// The frame of reference for the first body affected by this joint, expressed in the local frame /// of the first body. - pub local_anchor1: Isometry, + pub local_anchor1: Isometry, /// The frame of reference for the second body affected by this joint, expressed in the local frame /// of the first body. - pub local_anchor2: Isometry, + pub local_anchor2: Isometry, /// The impulse applied to the first body affected by this joint. /// /// The impulse applied to the second body affected by this joint is given by `-impulse`. /// This combines both linear and angular impulses: /// - In 2D, `impulse.xy()` gives the linear impulse, and `impulse.z` the angular impulse. /// - In 3D, `impulse.xyz()` gives the linear impulse, and `(impulse[3], impulse[4], impulse[5])` the angular impulse. - pub impulse: SpacialVector, + pub impulse: SpacialVector, } impl FixedJoint { /// Creates a new fixed joint from the frames of reference of both bodies. - pub fn new(local_anchor1: Isometry, local_anchor2: Isometry) -> Self { + pub fn new(local_anchor1: Isometry, local_anchor2: Isometry) -> Self { Self { local_anchor1, local_anchor2, diff --git a/src/dynamics/joint/prismatic_joint.rs b/src/dynamics/joint/prismatic_joint.rs index a6fd558..174ce79 100644 --- a/src/dynamics/joint/prismatic_joint.rs +++ b/src/dynamics/joint/prismatic_joint.rs @@ -1,4 +1,4 @@ -use crate::math::{Isometry, Point, Vector, DIM}; +use crate::math::{Isometry, Point, Real, Vector, DIM}; use crate::utils::WBasis; use na::Unit; #[cfg(feature = "dim2")] @@ -11,35 +11,35 @@ use na::Vector5; /// A joint that removes all relative motion between two bodies, except for the translations along one axis. pub struct PrismaticJoint { /// Where the prismatic joint is attached on the first body, expressed in the local space of the first attached body. - pub local_anchor1: Point, + pub local_anchor1: Point, /// Where the prismatic joint is attached on the second body, expressed in the local space of the second attached body. - pub local_anchor2: Point, - pub(crate) local_axis1: Unit>, - pub(crate) local_axis2: Unit>, - pub(crate) basis1: [Vector; DIM - 1], - pub(crate) basis2: [Vector; DIM - 1], + pub local_anchor2: Point, + pub(crate) local_axis1: Unit>, + pub(crate) local_axis2: Unit>, + pub(crate) basis1: [Vector; DIM - 1], + pub(crate) basis2: [Vector; DIM - 1], /// The impulse applied by this joint on the first body. /// /// The impulse applied to the second body is given by `-impulse`. #[cfg(feature = "dim3")] - pub impulse: Vector5, + pub impulse: Vector5, /// The impulse applied by this joint on the first body. /// /// The impulse applied to the second body is given by `-impulse`. #[cfg(feature = "dim2")] - pub impulse: Vector2, + pub impulse: Vector2, /// Whether or not this joint should enforce translational limits along its axis. pub limits_enabled: bool, /// The min an max relative position of the attached bodies along this joint's axis. - pub limits: [f32; 2], + pub limits: [Real; 2], /// The impulse applied by this joint on the first body to enforce the position limit along this joint's axis. /// /// The impulse applied to the second body is given by `-impulse`. - pub limits_impulse: f32, + pub limits_impulse: Real, // pub motor_enabled: bool, - // pub target_motor_vel: f32, - // pub max_motor_impulse: f32, - // pub motor_impulse: f32, + // pub target_motor_vel: Real, + // pub max_motor_impulse: Real, + // pub motor_impulse: Real, } impl PrismaticJoint { @@ -47,10 +47,10 @@ impl PrismaticJoint { /// in the local-space of the affected bodies. #[cfg(feature = "dim2")] pub fn new( - local_anchor1: Point, - local_axis1: Unit>, - local_anchor2: Point, - local_axis2: Unit>, + local_anchor1: Point, + local_axis1: Unit>, + local_anchor2: Point, + local_axis2: Unit>, ) -> Self { Self { local_anchor1, @@ -61,11 +61,11 @@ impl PrismaticJoint { basis2: local_axis2.orthonormal_basis(), impulse: na::zero(), limits_enabled: false, - limits: [-f32::MAX, f32::MAX], + limits: [-Real::MAX, Real::MAX], limits_impulse: 0.0, // motor_enabled: false, // target_motor_vel: 0.0, - // max_motor_impulse: f32::MAX, + // max_motor_impulse: Real::MAX, // motor_impulse: 0.0, } } @@ -78,12 +78,12 @@ impl PrismaticJoint { /// computed arbitrarily. #[cfg(feature = "dim3")] pub fn new( - local_anchor1: Point, - local_axis1: Unit>, - local_tangent1: Vector, - local_anchor2: Point, - local_axis2: Unit>, - local_tangent2: Vector, + local_anchor1: Point, + local_axis1: Unit>, + local_tangent1: Vector, + local_anchor2: Point, + local_axis2: Unit>, + local_tangent2: Vector, ) -> Self { let basis1 = if let Some(local_bitangent1) = Unit::try_new(local_axis1.cross(&local_tangent1), 1.0e-3) @@ -116,28 +116,28 @@ impl PrismaticJoint { basis2, impulse: na::zero(), limits_enabled: false, - limits: [-f32::MAX, f32::MAX], + limits: [-Real::MAX, Real::MAX], limits_impulse: 0.0, // motor_enabled: false, // target_motor_vel: 0.0, - // max_motor_impulse: f32::MAX, + // max_motor_impulse: Real::MAX, // motor_impulse: 0.0, } } /// The local axis of this joint, expressed in the local-space of the first attached body. - pub fn local_axis1(&self) -> Unit> { + pub fn local_axis1(&self) -> Unit> { self.local_axis1 } /// The local axis of this joint, expressed in the local-space of the second attached body. - pub fn local_axis2(&self) -> Unit> { + pub fn local_axis2(&self) -> Unit> { self.local_axis2 } // FIXME: precompute this? #[cfg(feature = "dim2")] - pub(crate) fn local_frame1(&self) -> Isometry { + pub(crate) fn local_frame1(&self) -> Isometry { use na::{Matrix2, Rotation2, UnitComplex}; let mat = Matrix2::from_columns(&[self.local_axis1.into_inner(), self.basis1[0]]); @@ -149,7 +149,7 @@ impl PrismaticJoint { // FIXME: precompute this? #[cfg(feature = "dim2")] - pub(crate) fn local_frame2(&self) -> Isometry { + pub(crate) fn local_frame2(&self) -> Isometry { use na::{Matrix2, Rotation2, UnitComplex}; let mat = Matrix2::from_columns(&[self.local_axis2.into_inner(), self.basis2[0]]); @@ -161,7 +161,7 @@ impl PrismaticJoint { // FIXME: precompute this? #[cfg(feature = "dim3")] - pub(crate) fn local_frame1(&self) -> Isometry { + pub(crate) fn local_frame1(&self) -> Isometry { use na::{Matrix3, Rotation3, UnitQuaternion}; let mat = Matrix3::from_columns(&[ @@ -177,7 +177,7 @@ impl PrismaticJoint { // FIXME: precompute this? #[cfg(feature = "dim3")] - pub(crate) fn local_frame2(&self) -> Isometry { + pub(crate) fn local_frame2(&self) -> Isometry { use na::{Matrix3, Rotation3, UnitQuaternion}; let mat = Matrix3::from_columns(&[ diff --git a/src/dynamics/joint/revolute_joint.rs b/src/dynamics/joint/revolute_joint.rs index cdb424b..ad7db0d 100644 --- a/src/dynamics/joint/revolute_joint.rs +++ b/src/dynamics/joint/revolute_joint.rs @@ -1,4 +1,4 @@ -use crate::math::{Point, Vector}; +use crate::math::{Point, Real, Vector}; use crate::utils::WBasis; use na::{Unit, Vector5}; @@ -7,31 +7,31 @@ use na::{Unit, Vector5}; /// A joint that removes all relative motion between two bodies, except for the rotations along one axis. pub struct RevoluteJoint { /// Where the revolute joint is attached on the first body, expressed in the local space of the first attached body. - pub local_anchor1: Point, + pub local_anchor1: Point, /// Where the revolute joint is attached on the second body, expressed in the local space of the second attached body. - pub local_anchor2: Point, + pub local_anchor2: Point, /// The rotation axis of this revolute joint expressed in the local space of the first attached body. - pub local_axis1: Unit>, + pub local_axis1: Unit>, /// The rotation axis of this revolute joint expressed in the local space of the second attached body. - pub local_axis2: Unit>, + pub local_axis2: Unit>, /// The basis orthonormal to `local_axis1`, expressed in the local space of the first attached body. - pub basis1: [Vector; 2], + pub basis1: [Vector; 2], /// The basis orthonormal to `local_axis2`, expressed in the local space of the second attached body. - pub basis2: [Vector; 2], + pub basis2: [Vector; 2], /// The impulse applied by this joint on the first body. /// /// The impulse applied to the second body is given by `-impulse`. - pub impulse: Vector5, + pub impulse: Vector5, } impl RevoluteJoint { /// Creates a new revolute joint with the given point of applications and axis, all expressed /// in the local-space of the affected bodies. pub fn new( - local_anchor1: Point, - local_axis1: Unit>, - local_anchor2: Point, - local_axis2: Unit>, + local_anchor1: Point, + local_axis1: Unit>, + local_anchor2: Point, + local_axis2: Unit>, ) -> Self { Self { local_anchor1, diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 5128b6f..683cca8 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -2,7 +2,9 @@ use crate::dynamics::MassProperties; use crate::geometry::{ Collider, ColliderHandle, ColliderSet, InteractionGraph, RigidBodyGraphIndex, }; -use crate::math::{AngVector, AngularInertia, Isometry, Point, Rotation, Translation, Vector}; +use crate::math::{ + AngVector, AngularInertia, Isometry, Point, Real, Rotation, Translation, Vector, +}; use crate::utils::{self, WCross, WDot}; use num::Zero; @@ -54,24 +56,24 @@ bitflags::bitflags! { #[derive(Debug, Clone)] pub struct RigidBody { /// The world-space position of the rigid-body. - pub(crate) position: Isometry, - pub(crate) predicted_position: Isometry, + pub(crate) position: Isometry, + pub(crate) predicted_position: Isometry, /// The local mass properties of the rigid-body. pub(crate) mass_properties: MassProperties, /// The world-space center of mass of the rigid-body. - pub world_com: Point, + pub world_com: Point, /// The square-root of the inverse angular inertia tensor of the rigid-body. - pub world_inv_inertia_sqrt: AngularInertia, + pub world_inv_inertia_sqrt: AngularInertia, /// The linear velocity of the rigid-body. - pub(crate) linvel: Vector, + pub(crate) linvel: Vector, /// The angular velocity of the rigid-body. - pub(crate) angvel: AngVector, + pub(crate) angvel: AngVector, /// Damping factor for gradually slowing down the translational motion of the rigid-body. - pub linear_damping: f32, + pub linear_damping: Real, /// Damping factor for gradually slowing down the angular motion of the rigid-body. - pub angular_damping: f32, - pub(crate) linacc: Vector, - pub(crate) angacc: AngVector, + pub angular_damping: Real, + pub(crate) linacc: Vector, + pub(crate) angacc: AngVector, pub(crate) colliders: Vec, /// Whether or not this rigid-body is sleeping. pub activation: ActivationStatus, @@ -125,7 +127,7 @@ impl RigidBody { self.active_set_timestamp = 0; } - pub(crate) fn integrate_accelerations(&mut self, dt: f32, gravity: Vector) { + pub(crate) fn integrate_accelerations(&mut self, dt: Real, gravity: Vector) { if self.mass_properties.inv_mass != 0.0 { self.linvel += (gravity + self.linacc) * dt; self.angvel += self.angacc * dt; @@ -184,7 +186,7 @@ impl RigidBody { /// The mass of this rigid body. /// /// Returns zero if this rigid body has an infinite mass. - pub fn mass(&self) -> f32 { + pub fn mass(&self) -> Real { utils::inv(self.mass_properties.inv_mass) } @@ -193,7 +195,7 @@ impl RigidBody { /// If this rigid-body is kinematic this value is set by the `set_next_kinematic_position` /// method and is used for estimating the kinematic body velocity at the next timestep. /// For non-kinematic bodies, this value is currently unspecified. - pub fn predicted_position(&self) -> &Isometry { + pub fn predicted_position(&self) -> &Isometry { &self.predicted_position } @@ -311,13 +313,13 @@ impl RigidBody { !self.linvel.is_zero() || !self.angvel.is_zero() } - fn integrate_velocity(&self, dt: f32) -> Isometry { + fn integrate_velocity(&self, dt: Real) -> Isometry { let com = &self.position * self.mass_properties.local_com; let shift = Translation::from(com.coords); shift * Isometry::new(self.linvel * dt, self.angvel * dt) * shift.inverse() } - pub(crate) fn integrate(&mut self, dt: f32) { + pub(crate) fn integrate(&mut self, dt: Real) { // TODO: do we want to apply damping before or after the velocity integration? self.linvel *= 1.0 / (1.0 + dt * self.linear_damping); self.angvel *= 1.0 / (1.0 + dt * self.angular_damping); @@ -326,19 +328,19 @@ impl RigidBody { } /// The linear velocity of this rigid-body. - pub fn linvel(&self) -> &Vector { + pub fn linvel(&self) -> &Vector { &self.linvel } /// The angular velocity of this rigid-body. #[cfg(feature = "dim2")] - pub fn angvel(&self) -> f32 { + pub fn angvel(&self) -> Real { self.angvel } /// The angular velocity of this rigid-body. #[cfg(feature = "dim3")] - pub fn angvel(&self) -> &Vector { + pub fn angvel(&self) -> &Vector { &self.angvel } @@ -346,7 +348,7 @@ impl RigidBody { /// /// If `wake_up` is `true` then the rigid-body will be woken up if it was /// put to sleep because it did not move for a while. - pub fn set_linvel(&mut self, linvel: Vector, wake_up: bool) { + pub fn set_linvel(&mut self, linvel: Vector, wake_up: bool) { self.linvel = linvel; if self.is_dynamic() && wake_up { @@ -359,7 +361,7 @@ impl RigidBody { /// If `wake_up` is `true` then the rigid-body will be woken up if it was /// put to sleep because it did not move for a while. #[cfg(feature = "dim2")] - pub fn set_angvel(&mut self, angvel: f32, wake_up: bool) { + pub fn set_angvel(&mut self, angvel: Real, wake_up: bool) { self.angvel = angvel; if self.is_dynamic() && wake_up { @@ -372,7 +374,7 @@ impl RigidBody { /// If `wake_up` is `true` then the rigid-body will be woken up if it was /// put to sleep because it did not move for a while. #[cfg(feature = "dim3")] - pub fn set_angvel(&mut self, angvel: Vector, wake_up: bool) { + pub fn set_angvel(&mut self, angvel: Vector, wake_up: bool) { self.angvel = angvel; if self.is_dynamic() && wake_up { @@ -381,7 +383,7 @@ impl RigidBody { } /// The world-space position of this rigid-body. - pub fn position(&self) -> &Isometry { + pub fn position(&self) -> &Isometry { &self.position } @@ -394,7 +396,7 @@ impl RigidBody { /// /// If `wake_up` is `true` then the rigid-body will be woken up if it was /// put to sleep because it did not move for a while. - pub fn set_position(&mut self, pos: Isometry, wake_up: bool) { + pub fn set_position(&mut self, pos: Isometry, wake_up: bool) { self.changes.insert(RigidBodyChanges::POSITION); self.set_position_internal(pos); @@ -404,7 +406,7 @@ impl RigidBody { } } - pub(crate) fn set_position_internal(&mut self, pos: Isometry) { + pub(crate) fn set_position_internal(&mut self, pos: Isometry) { self.position = pos; // TODO: update the predicted position for dynamic bodies too? @@ -414,13 +416,13 @@ impl RigidBody { } /// If this rigid body is kinematic, sets its future position after the next timestep integration. - pub fn set_next_kinematic_position(&mut self, pos: Isometry) { + pub fn set_next_kinematic_position(&mut self, pos: Isometry) { if self.is_kinematic() { self.predicted_position = pos; } } - pub(crate) fn compute_velocity_from_predicted_position(&mut self, inv_dt: f32) { + pub(crate) fn compute_velocity_from_predicted_position(&mut self, inv_dt: Real) { let dpos = self.predicted_position * self.position.inverse(); #[cfg(feature = "dim2")] { @@ -433,7 +435,7 @@ impl RigidBody { self.linvel = dpos.translation.vector * inv_dt; } - pub(crate) fn update_predicted_position(&mut self, dt: f32) { + pub(crate) fn update_predicted_position(&mut self, dt: Real) { self.predicted_position = self.integrate_velocity(dt) * self.position; } @@ -448,7 +450,7 @@ impl RigidBody { * Application of forces/impulses. */ /// Applies a force at the center-of-mass of this rigid-body. - pub fn apply_force(&mut self, force: Vector, wake_up: bool) { + pub fn apply_force(&mut self, force: Vector, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.linacc += force * self.mass_properties.inv_mass; @@ -459,7 +461,7 @@ impl RigidBody { } /// Applies an impulse at the center-of-mass of this rigid-body. - pub fn apply_impulse(&mut self, impulse: Vector, wake_up: bool) { + pub fn apply_impulse(&mut self, impulse: Vector, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.linvel += impulse * self.mass_properties.inv_mass; @@ -471,7 +473,7 @@ impl RigidBody { /// Applies a torque at the center-of-mass of this rigid-body. #[cfg(feature = "dim2")] - pub fn apply_torque(&mut self, torque: f32, wake_up: bool) { + pub fn apply_torque(&mut self, torque: Real, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.angacc += self.world_inv_inertia_sqrt * (self.world_inv_inertia_sqrt * torque); @@ -483,7 +485,7 @@ impl RigidBody { /// Applies a torque at the center-of-mass of this rigid-body. #[cfg(feature = "dim3")] - pub fn apply_torque(&mut self, torque: Vector, wake_up: bool) { + pub fn apply_torque(&mut self, torque: Vector, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.angacc += self.world_inv_inertia_sqrt * (self.world_inv_inertia_sqrt * torque); @@ -495,7 +497,7 @@ impl RigidBody { /// Applies an impulsive torque at the center-of-mass of this rigid-body. #[cfg(feature = "dim2")] - pub fn apply_torque_impulse(&mut self, torque_impulse: f32, wake_up: bool) { + pub fn apply_torque_impulse(&mut self, torque_impulse: Real, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.angvel += self.world_inv_inertia_sqrt * (self.world_inv_inertia_sqrt * torque_impulse); @@ -508,7 +510,7 @@ impl RigidBody { /// Applies an impulsive torque at the center-of-mass of this rigid-body. #[cfg(feature = "dim3")] - pub fn apply_torque_impulse(&mut self, torque_impulse: Vector, wake_up: bool) { + pub fn apply_torque_impulse(&mut self, torque_impulse: Vector, wake_up: bool) { if self.body_status == BodyStatus::Dynamic { self.angvel += self.world_inv_inertia_sqrt * (self.world_inv_inertia_sqrt * torque_impulse); @@ -520,7 +522,7 @@ impl RigidBody { } /// Applies a force at the given world-space point of this rigid-body. - pub fn apply_force_at_point(&mut self, force: Vector, point: Point, wake_up: bool) { + pub fn apply_force_at_point(&mut self, force: Vector, point: Point, wake_up: bool) { let torque = (point - self.world_com).gcross(force); self.apply_force(force, wake_up); self.apply_torque(torque, wake_up); @@ -529,8 +531,8 @@ impl RigidBody { /// Applies an impulse at the given world-space point of this rigid-body. pub fn apply_impulse_at_point( &mut self, - impulse: Vector, - point: Point, + impulse: Vector, + point: Point, wake_up: bool, ) { let torque_impulse = (point - self.world_com).gcross(impulse); @@ -539,7 +541,7 @@ impl RigidBody { } /// The velocity of the given world-space point on this rigid-body. - pub fn velocity_at_point(&self, point: &Point) -> Vector { + pub fn velocity_at_point(&self, point: &Point) -> Vector { let dpt = point - self.world_com; self.linvel + self.angvel.gcross(dpt) } @@ -547,11 +549,11 @@ impl RigidBody { /// A builder for rigid-bodies. pub struct RigidBodyBuilder { - position: Isometry, - linvel: Vector, - angvel: AngVector, - linear_damping: f32, - angular_damping: f32, + position: Isometry, + linvel: Vector, + angvel: AngVector, + linear_damping: Real, + angular_damping: Real, body_status: BodyStatus, flags: RigidBodyFlags, mass_properties: MassProperties, @@ -595,7 +597,7 @@ impl RigidBodyBuilder { /// Sets the initial translation of the rigid-body to be created. #[cfg(feature = "dim2")] - pub fn translation(mut self, x: f32, y: f32) -> Self { + pub fn translation(mut self, x: Real, y: Real) -> Self { self.position.translation.x = x; self.position.translation.y = y; self @@ -603,7 +605,7 @@ impl RigidBodyBuilder { /// Sets the initial translation of the rigid-body to be created. #[cfg(feature = "dim3")] - pub fn translation(mut self, x: f32, y: f32, z: f32) -> Self { + pub fn translation(mut self, x: Real, y: Real, z: Real) -> Self { self.position.translation.x = x; self.position.translation.y = y; self.position.translation.z = z; @@ -611,13 +613,13 @@ impl RigidBodyBuilder { } /// Sets the initial orientation of the rigid-body to be created. - pub fn rotation(mut self, angle: AngVector) -> Self { + pub fn rotation(mut self, angle: AngVector) -> Self { self.position.rotation = Rotation::new(angle); self } /// Sets the initial position (translation and orientation) of the rigid-body to be created. - pub fn position(mut self, pos: Isometry) -> Self { + pub fn position(mut self, pos: Isometry) -> Self { self.position = pos; self } @@ -675,7 +677,7 @@ impl RigidBodyBuilder { /// will depends on the initial mass set by this method to which is added /// the contributions of all the colliders with non-zero density attached to /// this rigid-body. - pub fn mass(mut self, mass: f32, colliders_contribution_enabled: bool) -> Self { + pub fn mass(mut self, mass: Real, colliders_contribution_enabled: bool) -> Self { self.mass_properties.inv_mass = utils::inv(mass); self.flags.set( RigidBodyFlags::IGNORE_COLLIDER_MASS, @@ -696,7 +698,7 @@ impl RigidBodyBuilder { #[cfg(feature = "dim2")] pub fn principal_angular_inertia( mut self, - inertia: f32, + inertia: Real, colliders_contribution_enabled: bool, ) -> Self { self.mass_properties.inv_principal_inertia_sqrt = utils::inv(inertia); @@ -712,7 +714,7 @@ impl RigidBodyBuilder { /// Use `self.principal_angular_inertia` instead. #[cfg(feature = "dim2")] #[deprecated(note = "renamed to `principal_angular_inertia`.")] - pub fn principal_inertia(self, inertia: f32, colliders_contribution_enabled: bool) -> Self { + pub fn principal_inertia(self, inertia: Real, colliders_contribution_enabled: bool) -> Self { self.principal_angular_inertia(inertia, colliders_contribution_enabled) } @@ -731,7 +733,7 @@ impl RigidBodyBuilder { #[cfg(feature = "dim3")] pub fn principal_angular_inertia( mut self, - inertia: AngVector, + inertia: AngVector, colliders_contribution_enabled: AngVector, ) -> Self { self.mass_properties.inv_principal_inertia_sqrt = inertia.map(utils::inv); @@ -755,7 +757,7 @@ impl RigidBodyBuilder { #[deprecated(note = "renamed to `principal_angular_inertia`.")] pub fn principal_inertia( self, - inertia: AngVector, + inertia: AngVector, colliders_contribution_enabled: AngVector, ) -> Self { self.principal_angular_inertia(inertia, colliders_contribution_enabled) @@ -765,7 +767,7 @@ impl RigidBodyBuilder { /// /// The higher the linear damping factor is, the more quickly the rigid-body /// will slow-down its translational movement. - pub fn linear_damping(mut self, factor: f32) -> Self { + pub fn linear_damping(mut self, factor: Real) -> Self { self.linear_damping = factor; self } @@ -774,27 +776,27 @@ impl RigidBodyBuilder { /// /// The higher the angular damping factor is, the more quickly the rigid-body /// will slow-down its rotational movement. - pub fn angular_damping(mut self, factor: f32) -> Self { + pub fn angular_damping(mut self, factor: Real) -> Self { self.angular_damping = factor; self } /// Sets the initial linear velocity of the rigid-body to be created. #[cfg(feature = "dim2")] - pub fn linvel(mut self, x: f32, y: f32) -> Self { + pub fn linvel(mut self, x: Real, y: Real) -> Self { self.linvel = Vector::new(x, y); self } /// Sets the initial linear velocity of the rigid-body to be created. #[cfg(feature = "dim3")] - pub fn linvel(mut self, x: f32, y: f32, z: f32) -> Self { + pub fn linvel(mut self, x: Real, y: Real, z: Real) -> Self { self.linvel = Vector::new(x, y, z); self } /// Sets the initial angular velocity of the rigid-body to be created. - pub fn angvel(mut self, angvel: AngVector) -> Self { + pub fn angvel(mut self, angvel: AngVector) -> Self { self.angvel = angvel; self } @@ -845,16 +847,16 @@ impl RigidBodyBuilder { #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] pub struct ActivationStatus { /// The threshold pseudo-kinetic energy bellow which the body can fall asleep. - pub threshold: f32, + pub threshold: Real, /// The current pseudo-kinetic energy of the body. - pub energy: f32, + pub energy: Real, /// Is this body already sleeping? pub sleeping: bool, } impl ActivationStatus { /// The default amount of energy bellow which a body can be put to sleep by nphysics. - pub fn default_threshold() -> f32 { + pub fn default_threshold() -> Real { 0.01 } diff --git a/src/dynamics/solver/delta_vel.rs b/src/dynamics/solver/delta_vel.rs index c4a424b..4614ed7 100644 --- a/src/dynamics/solver/delta_vel.rs +++ b/src/dynamics/solver/delta_vel.rs @@ -1,9 +1,9 @@ -use crate::math::{AngVector, Vector}; +use crate::math::{AngVector, Real, Vector}; use na::{Scalar, SimdRealField}; #[derive(Copy, Clone, Debug)] //#[repr(align(64))] -pub(crate) struct DeltaVel { +pub(crate) struct DeltaVel { pub linear: Vector, pub angular: AngVector, } diff --git a/src/dynamics/solver/interaction_groups.rs b/src/dynamics/solver/interaction_groups.rs index b5f8173..b409f98 100644 --- a/src/dynamics/solver/interaction_groups.rs +++ b/src/dynamics/solver/interaction_groups.rs @@ -2,7 +2,7 @@ use crate::dynamics::{BodyPair, JointGraphEdge, JointIndex, RigidBodySet}; use crate::geometry::{ContactManifold, ContactManifoldIndex}; #[cfg(feature = "simd-is-enabled")] use { - crate::math::{SIMD_LAST_INDEX, SIMD_WIDTH}, + crate::math::{Real, SIMD_LAST_INDEX, SIMD_WIDTH}, vec_map::VecMap, }; diff --git a/src/dynamics/solver/joint_constraint/ball_position_constraint.rs b/src/dynamics/solver/joint_constraint/ball_position_constraint.rs index 21a537e..8bc9072 100644 --- a/src/dynamics/solver/joint_constraint/ball_position_constraint.rs +++ b/src/dynamics/solver/joint_constraint/ball_position_constraint.rs @@ -1,7 +1,7 @@ use crate::dynamics::{BallJoint, IntegrationParameters, RigidBody}; #[cfg(feature = "dim2")] use crate::math::SdpMatrix; -use crate::math::{AngularInertia, Isometry, Point, Rotation}; +use crate::math::{AngularInertia, Isometry, Point, Real, Rotation}; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; #[derive(Debug)] @@ -9,17 +9,17 @@ pub(crate) struct BallPositionConstraint { position1: usize, position2: usize, - local_com1: Point, - local_com2: Point, + local_com1: Point, + local_com2: Point, - im1: f32, - im2: f32, + im1: Real, + im2: Real, - ii1: AngularInertia, - ii2: AngularInertia, + ii1: AngularInertia, + ii2: AngularInertia, - local_anchor1: Point, - local_anchor2: Point, + local_anchor1: Point, + local_anchor2: Point, } impl BallPositionConstraint { @@ -38,7 +38,7 @@ impl BallPositionConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position1 = positions[self.position1 as usize]; let mut position2 = positions[self.position2 as usize]; @@ -95,11 +95,11 @@ impl BallPositionConstraint { #[derive(Debug)] pub(crate) struct BallPositionGroundConstraint { position2: usize, - anchor1: Point, - im2: f32, - ii2: AngularInertia, - local_anchor2: Point, - local_com2: Point, + anchor1: Point, + im2: Real, + ii2: AngularInertia, + local_anchor2: Point, + local_com2: Point, } impl BallPositionGroundConstraint { @@ -133,7 +133,7 @@ impl BallPositionGroundConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position2 = positions[self.position2 as usize]; let anchor2 = position2 * self.local_anchor2; diff --git a/src/dynamics/solver/joint_constraint/ball_position_constraint_wide.rs b/src/dynamics/solver/joint_constraint/ball_position_constraint_wide.rs index f1ca4b6..2f2ffc3 100644 --- a/src/dynamics/solver/joint_constraint/ball_position_constraint_wide.rs +++ b/src/dynamics/solver/joint_constraint/ball_position_constraint_wide.rs @@ -1,7 +1,7 @@ use crate::dynamics::{BallJoint, IntegrationParameters, RigidBody}; #[cfg(feature = "dim2")] use crate::math::SdpMatrix; -use crate::math::{AngularInertia, Isometry, Point, Rotation, SimdReal, SIMD_WIDTH}; +use crate::math::{AngularInertia, Isometry, Point, Real, Rotation, SimdReal, SIMD_WIDTH}; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; use simba::simd::SimdValue; @@ -60,7 +60,7 @@ impl WBallPositionConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position1 = Isometry::from(array![|ii| positions[self.position1[ii]]; SIMD_WIDTH]); let mut position2 = Isometry::from(array![|ii| positions[self.position2[ii]]; SIMD_WIDTH]); @@ -164,7 +164,7 @@ impl WBallPositionGroundConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position2 = Isometry::from(array![|ii| positions[self.position2[ii]]; SIMD_WIDTH]); let anchor2 = position2 * self.local_anchor2; diff --git a/src/dynamics/solver/joint_constraint/ball_velocity_constraint.rs b/src/dynamics/solver/joint_constraint/ball_velocity_constraint.rs index 97ba244..9f47624 100644 --- a/src/dynamics/solver/joint_constraint/ball_velocity_constraint.rs +++ b/src/dynamics/solver/joint_constraint/ball_velocity_constraint.rs @@ -2,7 +2,7 @@ use crate::dynamics::solver::DeltaVel; use crate::dynamics::{ BallJoint, IntegrationParameters, JointGraphEdge, JointIndex, JointParams, RigidBody, }; -use crate::math::{SdpMatrix, Vector}; +use crate::math::{Real, SdpMatrix, Vector}; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; #[derive(Debug)] @@ -12,16 +12,16 @@ pub(crate) struct BallVelocityConstraint { joint_id: JointIndex, - rhs: Vector, - pub(crate) impulse: Vector, + rhs: Vector, + pub(crate) impulse: Vector, - gcross1: Vector, - gcross2: Vector, + gcross1: Vector, + gcross2: Vector, - inv_lhs: SdpMatrix, + inv_lhs: SdpMatrix, - im1: f32, - im2: f32, + im1: Real, + im2: Real, } impl BallVelocityConstraint { @@ -91,7 +91,7 @@ impl BallVelocityConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = mj_lambdas[self.mj_lambda1 as usize]; let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; @@ -104,7 +104,7 @@ impl BallVelocityConstraint { mj_lambdas[self.mj_lambda2 as usize] = mj_lambda2; } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = mj_lambdas[self.mj_lambda1 as usize]; let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; @@ -137,11 +137,11 @@ impl BallVelocityConstraint { pub(crate) struct BallVelocityGroundConstraint { mj_lambda2: usize, joint_id: JointIndex, - rhs: Vector, - impulse: Vector, - gcross2: Vector, - inv_lhs: SdpMatrix, - im2: f32, + rhs: Vector, + impulse: Vector, + gcross2: Vector, + inv_lhs: SdpMatrix, + im2: Real, } impl BallVelocityGroundConstraint { @@ -206,14 +206,14 @@ impl BallVelocityGroundConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; mj_lambda2.linear -= self.im2 * self.impulse; mj_lambda2.angular -= self.gcross2.gcross(self.impulse); mj_lambdas[self.mj_lambda2 as usize] = mj_lambda2; } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; let vel2 = mj_lambda2.linear + mj_lambda2.angular.gcross(self.gcross2); diff --git a/src/dynamics/solver/joint_constraint/ball_velocity_constraint_wide.rs b/src/dynamics/solver/joint_constraint/ball_velocity_constraint_wide.rs index bbb709e..2806233 100644 --- a/src/dynamics/solver/joint_constraint/ball_velocity_constraint_wide.rs +++ b/src/dynamics/solver/joint_constraint/ball_velocity_constraint_wide.rs @@ -3,7 +3,7 @@ use crate::dynamics::{ BallJoint, IntegrationParameters, JointGraphEdge, JointIndex, JointParams, RigidBody, }; use crate::math::{ - AngVector, AngularInertia, Isometry, Point, SdpMatrix, SimdReal, Vector, SIMD_WIDTH, + AngVector, AngularInertia, Isometry, Point, Real, SdpMatrix, SimdReal, Vector, SIMD_WIDTH, }; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; use simba::simd::SimdValue; @@ -107,7 +107,7 @@ impl WBallVelocityConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda1[ii] as usize].linear; SIMD_WIDTH], @@ -140,7 +140,7 @@ impl WBallVelocityConstraint { } } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1: DeltaVel = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda1[ii] as usize].linear; SIMD_WIDTH], @@ -274,7 +274,7 @@ impl WBallVelocityGroundConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda2[ii] as usize].linear; SIMD_WIDTH], @@ -293,7 +293,7 @@ impl WBallVelocityGroundConstraint { } } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2: DeltaVel = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda2[ii] as usize].linear; SIMD_WIDTH], diff --git a/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs b/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs index 24001cd..cf9dcb7 100644 --- a/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs +++ b/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs @@ -1,22 +1,22 @@ use crate::dynamics::{FixedJoint, IntegrationParameters, RigidBody}; -use crate::math::{AngularInertia, Isometry, Point, Rotation}; +use crate::math::{AngularInertia, Isometry, Point, Real, Rotation}; use crate::utils::WAngularInertia; #[derive(Debug)] pub(crate) struct FixedPositionConstraint { position1: usize, position2: usize, - local_anchor1: Isometry, - local_anchor2: Isometry, - local_com1: Point, - local_com2: Point, - im1: f32, - im2: f32, - ii1: AngularInertia, - ii2: AngularInertia, - - lin_inv_lhs: f32, - ang_inv_lhs: AngularInertia, + local_anchor1: Isometry, + local_anchor2: Isometry, + local_com1: Point, + local_com2: Point, + im1: Real, + im2: Real, + ii1: AngularInertia, + ii2: AngularInertia, + + lin_inv_lhs: Real, + ang_inv_lhs: AngularInertia, } impl FixedPositionConstraint { @@ -44,7 +44,7 @@ impl FixedPositionConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position1 = positions[self.position1 as usize]; let mut position2 = positions[self.position2 as usize]; @@ -81,12 +81,12 @@ impl FixedPositionConstraint { #[derive(Debug)] pub(crate) struct FixedPositionGroundConstraint { position2: usize, - anchor1: Isometry, - local_anchor2: Isometry, - local_com2: Point, - im2: f32, - ii2: AngularInertia, - impulse: f32, + anchor1: Isometry, + local_anchor2: Isometry, + local_com2: Point, + im2: Real, + ii2: AngularInertia, + impulse: Real, } impl FixedPositionGroundConstraint { @@ -118,7 +118,7 @@ impl FixedPositionGroundConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position2 = positions[self.position2 as usize]; // Angular correction. diff --git a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs index e4187c8..715b7dd 100644 --- a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs +++ b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs @@ -2,7 +2,7 @@ use crate::dynamics::solver::DeltaVel; use crate::dynamics::{ FixedJoint, IntegrationParameters, JointGraphEdge, JointIndex, JointParams, RigidBody, }; -use crate::math::{AngularInertia, Dim, SpacialVector, Vector}; +use crate::math::{AngularInertia, Dim, Real, SpacialVector, Vector}; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; #[cfg(feature = "dim2")] use na::{Matrix3, Vector3}; @@ -16,29 +16,29 @@ pub(crate) struct FixedVelocityConstraint { joint_id: JointIndex, - impulse: SpacialVector, + impulse: SpacialVector, #[cfg(feature = "dim3")] - inv_lhs: Matrix6, // FIXME: replace by Cholesky. + inv_lhs: Matrix6, // FIXME: replace by Cholesky. #[cfg(feature = "dim3")] - rhs: Vector6, + rhs: Vector6, #[cfg(feature = "dim2")] - inv_lhs: Matrix3, // FIXME: replace by Cholesky. + inv_lhs: Matrix3, // FIXME: replace by Cholesky. #[cfg(feature = "dim2")] - rhs: Vector3, + rhs: Vector3, - im1: f32, - im2: f32, + im1: Real, + im2: Real, - ii1: AngularInertia, - ii2: AngularInertia, + ii1: AngularInertia, + ii2: AngularInertia, - ii1_sqrt: AngularInertia, - ii2_sqrt: AngularInertia, + ii1_sqrt: AngularInertia, + ii2_sqrt: AngularInertia, - r1: Vector, - r2: Vector, + r1: Vector, + r2: Vector, } impl FixedVelocityConstraint { @@ -128,7 +128,7 @@ impl FixedVelocityConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = mj_lambdas[self.mj_lambda1 as usize]; let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; @@ -152,7 +152,7 @@ impl FixedVelocityConstraint { mj_lambdas[self.mj_lambda2 as usize] = mj_lambda2; } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = mj_lambdas[self.mj_lambda1 as usize]; let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; @@ -207,22 +207,22 @@ pub(crate) struct FixedVelocityGroundConstraint { joint_id: JointIndex, - impulse: SpacialVector, + impulse: SpacialVector, #[cfg(feature = "dim3")] - inv_lhs: Matrix6, // FIXME: replace by Cholesky. + inv_lhs: Matrix6, // FIXME: replace by Cholesky. #[cfg(feature = "dim3")] - rhs: Vector6, + rhs: Vector6, #[cfg(feature = "dim2")] - inv_lhs: Matrix3, // FIXME: replace by Cholesky. + inv_lhs: Matrix3, // FIXME: replace by Cholesky. #[cfg(feature = "dim2")] - rhs: Vector3, + rhs: Vector3, - im2: f32, - ii2: AngularInertia, - ii2_sqrt: AngularInertia, - r2: Vector, + im2: Real, + ii2: AngularInertia, + ii2_sqrt: AngularInertia, + r2: Vector, } impl FixedVelocityGroundConstraint { @@ -312,7 +312,7 @@ impl FixedVelocityGroundConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; let lin_impulse = self.impulse.fixed_rows::(0).into_owned(); @@ -329,7 +329,7 @@ impl FixedVelocityGroundConstraint { mj_lambdas[self.mj_lambda2 as usize] = mj_lambda2; } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = mj_lambdas[self.mj_lambda2 as usize]; let ang_vel2 = self.ii2_sqrt.transform_vector(mj_lambda2.angular); diff --git a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs index 6584ea2..48a6cba 100644 --- a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs +++ b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs @@ -5,8 +5,8 @@ use crate::dynamics::{ FixedJoint, IntegrationParameters, JointGraphEdge, JointIndex, JointParams, RigidBody, }; use crate::math::{ - AngVector, AngularInertia, CrossMatrix, Dim, Isometry, Point, SimdReal, SpacialVector, Vector, - SIMD_WIDTH, + AngVector, AngularInertia, CrossMatrix, Dim, Isometry, Point, Real, SimdReal, SpacialVector, + Vector, SIMD_WIDTH, }; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; #[cfg(feature = "dim3")] @@ -158,7 +158,7 @@ impl WFixedVelocityConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1 = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda1[ii] as usize].linear; SIMD_WIDTH], @@ -202,7 +202,7 @@ impl WFixedVelocityConstraint { } } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda1: DeltaVel = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda1[ii] as usize].linear; SIMD_WIDTH], @@ -393,7 +393,7 @@ impl WFixedVelocityGroundConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2 = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda2[ii] as usize].linear; SIMD_WIDTH], @@ -420,7 +420,7 @@ impl WFixedVelocityGroundConstraint { } } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { let mut mj_lambda2: DeltaVel = DeltaVel { linear: Vector::from( array![|ii| mj_lambdas[self.mj_lambda2[ii] as usize].linear; SIMD_WIDTH], diff --git a/src/dynamics/solver/joint_constraint/joint_constraint.rs b/src/dynamics/solver/joint_constraint/joint_constraint.rs index 8b1f8bf..ed6d758 100644 --- a/src/dynamics/solver/joint_constraint/joint_constraint.rs +++ b/src/dynamics/solver/joint_constraint/joint_constraint.rs @@ -17,6 +17,7 @@ use crate::dynamics::solver::DeltaVel; use crate::dynamics::{ IntegrationParameters, Joint, JointGraphEdge, JointIndex, JointParams, RigidBodySet, }; +use crate::math::Real; #[cfg(feature = "simd-is-enabled")] use crate::math::SIMD_WIDTH; @@ -220,7 +221,7 @@ impl AnyJointVelocityConstraint { } } - pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { + pub fn warmstart(&self, mj_lambdas: &mut [DeltaVel]) { match self { AnyJointVelocityConstraint::BallConstraint(c) => c.warmstart(mj_lambdas), AnyJointVelocityConstraint::BallGroundConstraint(c) => c.warmstart(mj_lambdas), @@ -254,7 +255,7 @@ impl AnyJointVelocityConstraint { } } - pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { + pub fn solve(&mut self, mj_lambdas: &mut [DeltaVel]) { match self { AnyJointVelocityConstraint::BallConstraint(c) => c.solve(mj_lambdas), AnyJointVelocityConstraint::BallGroundConstraint(c) => c.solve(mj_lambdas), diff --git a/src/dynamics/solver/joint_constraint/joint_position_constraint.rs b/src/dynamics/solver/joint_constraint/joint_position_constraint.rs index 4773687..0ebe88e 100644 --- a/src/dynamics/solver/joint_constraint/joint_position_constraint.rs +++ b/src/dynamics/solver/joint_constraint/joint_position_constraint.rs @@ -7,9 +7,9 @@ use super::{RevolutePositionConstraint, RevolutePositionGroundConstraint}; #[cfg(feature = "simd-is-enabled")] use super::{WBallPositionConstraint, WBallPositionGroundConstraint}; use crate::dynamics::{IntegrationParameters, Joint, JointParams, RigidBodySet}; -use crate::math::Isometry; #[cfg(feature = "simd-is-enabled")] use crate::math::SIMD_WIDTH; +use crate::math::{Isometry, Real}; pub(crate) enum AnyJointPositionConstraint { BallJoint(BallPositionConstraint), @@ -147,7 +147,7 @@ impl AnyJointPositionConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { match self { AnyJointPositionConstraint::BallJoint(c) => c.solve(params, positions), AnyJointPositionConstraint::BallGroundConstraint(c) => c.solve(params, positions), diff --git a/src/dynamics/solver/joint_constraint/prismatic_position_constraint.rs b/src/dynamics/solver/joint_constraint/prismatic_position_constraint.rs index c3e4b98..2616f6b 100644 --- a/src/dynamics/solver/joint_constraint/prismatic_position_constraint.rs +++ b/src/dynamics/solver/joint_constraint/prismatic_position_constraint.rs @@ -1,5 +1,5 @@ use crate::dynamics::{IntegrationParameters, PrismaticJoint, RigidBody}; -use crate::math::{AngularInertia, Isometry, Point, Rotation, Vector}; +use crate::math::{AngularInertia, Isometry, Point, Real, Rotation, Vector}; use crate::utils::WAngularInertia; use na::Unit; @@ -8,22 +8,22 @@ pub(crate) struct PrismaticPositionConstraint { position1: usize, position2: usize, - im1: f32, - im2: f32, + im1: Real, + im2: Real, - ii1: AngularInertia, - ii2: AngularInertia, + ii1: AngularInertia, + ii2: AngularInertia, - lin_inv_lhs: f32, - ang_inv_lhs: AngularInertia, + lin_inv_lhs: Real, + ang_inv_lhs: AngularInertia, - limits: [f32; 2], + limits: [Real; 2], - local_frame1: Isometry, - local_frame2: Isometry, + local_frame1: Isometry, + local_frame2: Isometry, - local_axis1: Unit>, - local_axis2: Unit>, + local_axis1: Unit>, + local_axis2: Unit>, } impl PrismaticPositionConstraint { @@ -52,7 +52,7 @@ impl PrismaticPositionConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position1 = positions[self.position1 as usize]; let mut position2 = positions[self.position2 as usize]; @@ -99,11 +99,11 @@ impl PrismaticPositionConstraint { #[derive(Debug)] pub(crate) struct PrismaticPositionGroundConstraint { position2: usize, - frame1: Isometry, - local_frame2: Isometry, - axis1: Unit>, - local_axis2: Unit>, - limits: [f32; 2], + frame1: Isometry, + local_frame2: Isometry, + axis1: Unit>, + local_axis2: Unit>, + limits: [Real; 2], } impl PrismaticPositionGroundConstraint { @@ -140,7 +140,7 @@ impl PrismaticPositionGroundConstraint { } } - pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { + pub fn solve(&self, params: &IntegrationParameters, positions: &mut [Isometry]) { let mut position2 = positions[self.position2 as usize]; // Angular correction. diff --git a/src/dynamics/solver/joint_constraint/prismatic_velocity_constraint.rs b/src/dynamics/solver/joint_constraint/prismatic_velocity_constraint.rs index 9e39bd6..78dc1b5 100644 --- a/src/dynamics/solver/joint_constraint/prismatic_velocity_constraint.rs +++ b/src/dynamics/solver/joint_constraint/prismatic_velocity_constraint.rs @@ -2,7 +2,7 @@ use crate::dynamics::solver::DeltaVel; use crate::dynamics::{ IntegrationParameters, JointGraphEdge, JointIndex, JointParams, PrismaticJoint, RigidBody, }; -use crate::math::{AngularInertia, Vector}; +use crate::math::{AngularInertia, Real, Vector}; use crate::utils::{WAngularInertia, WCross, WCrossMatrix}; #[cfg(feature = "dim3")] use na::{Cholesky, Matrix3x2, Matrix5, Vector5, U2, U3}; @@ -24,37 +24,37 @@ pub(crate) struct PrismaticVelocityConstraint { joint_id: JointIndex, - r1: Vector, - r2: Vector, + r1: Vector, + r2: Vector, #[cfg(feature = "dim3")] - inv_lhs: Matrix5, + inv_lhs: Matrix5, #[cfg(feature = "dim3")] - rhs: Vector5, + rhs: Vector5, #[cfg(feature = "dim3")] - impulse: Vector5, + impulse: Vector5, #[cfg(feature = "dim2")] - inv_lhs: Matrix2, + inv_lhs: Matrix2, #[cfg(feature = "dim2")] - rhs: Vector2, + rhs: Vector2, #[cfg(feature = "dim2")] - impulse: Vector2