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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
use std::ops::{Deref, DerefMut};
use crate::{
nalgebra::{self as na, RealField, Scalar, Vector3},
nphysics::solver::IntegrationParameters,
};
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct TimeStep<N: RealField>(pub N);
impl<N: RealField> Deref for TimeStep<N> {
type Target = N;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<N: RealField> DerefMut for TimeStep<N> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<N: RealField> Default for TimeStep<N> {
fn default() -> Self {
Self(na::convert(1.0 / 60.0))
}
}
#[derive(Debug, PartialEq)]
pub struct Gravity<N: RealField + Scalar>(pub Vector3<N>);
impl<N: RealField + Scalar> Deref for Gravity<N> {
type Target = Vector3<N>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<N: RealField + Scalar> DerefMut for Gravity<N> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<N: RealField + Scalar> Default for Gravity<N> {
fn default() -> Self {
Self(Vector3::<N>::zeros())
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct PhysicsProfilingEnabled(pub bool);
impl Deref for PhysicsProfilingEnabled {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for PhysicsProfilingEnabled {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl Default for PhysicsProfilingEnabled {
fn default() -> Self {
Self(false)
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct PhysicsIntegrationParameters<N: RealField> {
pub error_reduction_parameter: N,
pub warmstart_coefficient: N,
pub restitution_velocity_threshold: N,
pub allowed_linear_error: N,
pub allowed_angular_error: N,
pub max_linear_correction: N,
pub max_angular_correction: N,
pub max_stabilization_multiplier: N,
pub max_velocity_iterations: usize,
pub max_position_iterations: usize,
}
impl<N: RealField> PhysicsIntegrationParameters<N> {
pub(crate) fn apply(&self, to: &mut IntegrationParameters<N>) {
to.erp = self.error_reduction_parameter;
to.warmstart_coeff = self.warmstart_coefficient;
to.restitution_velocity_threshold = self.restitution_velocity_threshold;
to.allowed_linear_error = self.allowed_linear_error;
to.allowed_angular_error = self.allowed_angular_error;
to.max_linear_correction = self.max_linear_correction;
to.max_angular_correction = self.max_angular_correction;
to.max_stabilization_multiplier = self.max_stabilization_multiplier;
to.max_velocity_iterations = self.max_velocity_iterations;
to.max_position_iterations = self.max_position_iterations;
}
}
impl<N: RealField> PartialEq<IntegrationParameters<N>> for PhysicsIntegrationParameters<N> {
fn eq(&self, other: &IntegrationParameters<N>) -> bool {
self.error_reduction_parameter == other.erp
&& self.warmstart_coefficient == other.warmstart_coeff
&& self.restitution_velocity_threshold == other.restitution_velocity_threshold
&& self.allowed_linear_error == other.allowed_linear_error
&& self.allowed_angular_error == other.allowed_angular_error
&& self.max_linear_correction == other.max_linear_correction
&& self.max_angular_correction == other.max_angular_correction
&& self.max_stabilization_multiplier == other.max_stabilization_multiplier
&& self.max_velocity_iterations == other.max_velocity_iterations
&& self.max_position_iterations == other.max_position_iterations
}
}
impl<N: RealField> Default for PhysicsIntegrationParameters<N> {
fn default() -> Self {
PhysicsIntegrationParameters {
error_reduction_parameter: na::convert(0.2),
warmstart_coefficient: na::convert(1.0),
restitution_velocity_threshold: na::convert(1.0),
allowed_linear_error: na::convert(0.001),
allowed_angular_error: na::convert(0.001),
max_linear_correction: na::convert(100.0),
max_angular_correction: na::convert(0.2),
max_stabilization_multiplier: na::convert(0.2),
max_velocity_iterations: 8,
max_position_iterations: 3,
}
}
}