rapier3d/dynamics/solver/joint_constraint/
any_joint_constraint.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::dynamics::solver::joint_constraint::joint_generic_constraint::{
    JointGenericOneBodyConstraint, JointGenericTwoBodyConstraint,
};
use crate::dynamics::solver::joint_constraint::joint_velocity_constraint::{
    JointOneBodyConstraint, JointTwoBodyConstraint,
};
use crate::dynamics::solver::{AnyConstraintMut, ConstraintTypes};
use crate::dynamics::JointGraphEdge;
use crate::math::Real;
use na::DVector;

use crate::dynamics::solver::joint_constraint::joint_generic_constraint_builder::{
    JointGenericOneBodyConstraintBuilder, JointGenericTwoBodyConstraintBuilder,
};
use crate::dynamics::solver::solver_vel::SolverVel;
#[cfg(feature = "simd-is-enabled")]
use crate::{
    dynamics::solver::joint_constraint::joint_constraint_builder::{
        JointOneBodyConstraintBuilderSimd, JointTwoBodyConstraintBuilderSimd,
    },
    math::{SimdReal, SIMD_WIDTH},
};

use crate::dynamics::solver::joint_constraint::joint_constraint_builder::{
    JointOneBodyConstraintBuilder, JointTwoBodyConstraintBuilder,
};

pub struct JointConstraintTypes;

impl AnyConstraintMut<'_, JointConstraintTypes> {
    pub fn remove_bias(&mut self) {
        match self {
            Self::OneBody(c) => c.remove_bias_from_rhs(),
            Self::TwoBodies(c) => c.remove_bias_from_rhs(),
            Self::GenericOneBody(c) => c.remove_bias_from_rhs(),
            Self::GenericTwoBodies(c) => c.remove_bias_from_rhs(),
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdOneBody(c) => c.remove_bias_from_rhs(),
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdTwoBodies(c) => c.remove_bias_from_rhs(),
        }
    }

    pub fn solve(
        &mut self,
        generic_jacobians: &DVector<Real>,
        solver_vels: &mut [SolverVel<Real>],
        generic_solver_vels: &mut DVector<Real>,
    ) {
        match self {
            Self::OneBody(c) => c.solve(solver_vels),
            Self::TwoBodies(c) => c.solve(solver_vels),
            Self::GenericOneBody(c) => c.solve(generic_jacobians, solver_vels, generic_solver_vels),
            Self::GenericTwoBodies(c) => {
                c.solve(generic_jacobians, solver_vels, generic_solver_vels)
            }
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdOneBody(c) => c.solve(solver_vels),
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdTwoBodies(c) => c.solve(solver_vels),
        }
    }

    pub fn writeback_impulses(&mut self, joints_all: &mut [JointGraphEdge]) {
        match self {
            Self::OneBody(c) => c.writeback_impulses(joints_all),
            Self::TwoBodies(c) => c.writeback_impulses(joints_all),
            Self::GenericOneBody(c) => c.writeback_impulses(joints_all),
            Self::GenericTwoBodies(c) => c.writeback_impulses(joints_all),
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdOneBody(c) => c.writeback_impulses(joints_all),
            #[cfg(feature = "simd-is-enabled")]
            Self::SimdTwoBodies(c) => c.writeback_impulses(joints_all),
        }
    }
}

impl ConstraintTypes for JointConstraintTypes {
    type OneBody = JointOneBodyConstraint<Real, 1>;
    type TwoBodies = JointTwoBodyConstraint<Real, 1>;
    type GenericOneBody = JointGenericOneBodyConstraint;
    type GenericTwoBodies = JointGenericTwoBodyConstraint;

    #[cfg(feature = "simd-is-enabled")]
    type SimdOneBody = JointOneBodyConstraint<SimdReal, SIMD_WIDTH>;
    #[cfg(feature = "simd-is-enabled")]
    type SimdTwoBodies = JointTwoBodyConstraint<SimdReal, SIMD_WIDTH>;

    type BuilderOneBody = JointOneBodyConstraintBuilder;
    type BuilderTwoBodies = JointTwoBodyConstraintBuilder;
    type GenericBuilderOneBody = JointGenericOneBodyConstraintBuilder;
    type GenericBuilderTwoBodies = JointGenericTwoBodyConstraintBuilder;
    #[cfg(feature = "simd-is-enabled")]
    type SimdBuilderOneBody = JointOneBodyConstraintBuilderSimd;
    #[cfg(feature = "simd-is-enabled")]
    type SimdBuilderTwoBodies = JointTwoBodyConstraintBuilderSimd;
}