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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use na::{RealField, Unit};
use ncollide::query::ContactKinematic;
use crate::math::Vector;
use crate::object::{BodyPartHandle, BodySet, ColliderHandle};
use crate::solver::IntegrationParameters;
pub struct GenericNonlinearConstraint<N: RealField> {
pub body1: BodyPartHandle,
pub body2: BodyPartHandle,
pub is_angular: bool,
pub dim1: usize,
pub dim2: usize,
pub wj_id1: usize,
pub wj_id2: usize,
pub rhs: N,
pub r: N,
}
impl<N: RealField> GenericNonlinearConstraint<N> {
pub fn new(
body1: BodyPartHandle,
body2: BodyPartHandle,
is_angular: bool,
dim1: usize,
dim2: usize,
wj_id1: usize,
wj_id2: usize,
rhs: N,
r: N,
) -> Self {
GenericNonlinearConstraint {
body1,
body2,
is_angular,
dim1,
dim2,
wj_id1,
wj_id2,
rhs,
r,
}
}
}
pub trait NonlinearConstraintGenerator<N: RealField> {
fn num_position_constraints(&self, bodies: &BodySet<N>) -> usize;
fn position_constraint(
&self,
params: &IntegrationParameters<N>,
i: usize,
bodies: &mut BodySet<N>,
jacobians: &mut [N],
) -> Option<GenericNonlinearConstraint<N>>;
}
#[derive(Debug)]
pub struct NonlinearUnilateralConstraint<N: RealField> {
pub r: N,
pub rhs: N,
pub ndofs1: usize,
pub body1: BodyPartHandle,
pub collider1: ColliderHandle,
pub ndofs2: usize,
pub body2: BodyPartHandle,
pub collider2: ColliderHandle,
pub kinematic: ContactKinematic<N>,
pub normal1: Unit<Vector<N>>,
pub normal2: Unit<Vector<N>>,
}
impl<N: RealField> NonlinearUnilateralConstraint<N> {
pub fn new(
body1: BodyPartHandle,
collider1: ColliderHandle,
ndofs1: usize,
body2: BodyPartHandle,
collider2: ColliderHandle,
ndofs2: usize,
normal1: Unit<Vector<N>>,
normal2: Unit<Vector<N>>,
kinematic: ContactKinematic<N>,
) -> Self {
let r = N::zero();
let rhs = N::zero();
NonlinearUnilateralConstraint {
r,
rhs,
ndofs1,
body1,
collider1,
ndofs2,
body2,
collider2,
kinematic,
normal1,
normal2,
}
}
}
pub struct MultibodyJointLimitsNonlinearConstraintGenerator;
impl MultibodyJointLimitsNonlinearConstraintGenerator {
pub fn new() -> Self {
MultibodyJointLimitsNonlinearConstraintGenerator
}
}
impl<N: RealField> NonlinearConstraintGenerator<N> for MultibodyJointLimitsNonlinearConstraintGenerator {
fn num_position_constraints(&self, _: &BodySet<N>) -> usize {
0
}
fn position_constraint(
&self,
_: &IntegrationParameters<N>,
_: usize,
_: &mut BodySet<N>,
_: &mut [N],
) -> Option<GenericNonlinearConstraint<N>> {
None
}
}