-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
notes.txt
183 lines (152 loc) · 5.57 KB
/
notes.txt
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
https://montreal.ubisoft.com/en/introducing-learned-motion-matching/
https://theorangeduck.com/page/inertialization-transition-cost
interesting information on blending animations using damped springs
https://rapier.rs/docs/user_guides/rust/joints
//https://en.wikipedia.org/wiki/Semi-implicit_Euler_method
https://www.youtube.com/watch?v=KPoeNZZ6H4s
Second Order Dynamics, Way to control springs
INTERESTING Springs from a long time ago
https://gist.github.com/sketchpunk/3568150a04b973430dfe8fd29bf470c8
class SecondOrderDynamics{
xp = 0; // Previous Input
y = 0; // State Vars
yd = 0;
k1, k2, k3; // Dynamic constants
// freq,
// resp: damp like value on how accel begins, 0 takes time to accel from rest
// if resp 0 < r <= 1, it responds right away
// if resp > 1, overshoots before settling
// if resp < 0, will undershoot at the start
// Freq < 10 else it goes to infinity
constructor( freq, damp, resp, initV ){
k1 = damp / ( PI * freq );
k2 = 1 / ( ( 2 * PI * freq ) * ( 2 * PI * Freq ) );
k3 = resp * damp / ( 2 * PI * freq );
xp = initV;
y = initV;
yd = 0;
}
// t can be delta time i think
update( t, x, xd=null ){
if( xd == null ){ // Estimate velocity
xd = ( x - xp ) / T;
xp = x;
}
y = y + T * yd; // Itergrate position by velocity
yd = yd * T * ( x + k3 *xd - y - k1 * yd ) / k2; // intergrate velocity by acceleration
return y;
}
}
class SecondOrderDynamics2{
xp = 0; // Previous Input
y = 0; // State Vars
yd = 0;
k1, k2, k3; // Dynamic constants
T_crit: // critical stable timestamp
// freq,
// resp: damp like value on how accel begins, 0 takes time to accel from rest
// if resp 0 < r <= 1, it responds right away
// if resp > 1, overshoots before settling
// if resp < 0, will undershoot at the start
// Freq < 10 else it goes to infinity
constructor( freq, damp, resp, initV ){
k1 = damp / ( PI * freq );
k2 = 1 / ( ( 2 * PI * freq ) * ( 2 * PI * Freq ) );
k3 = resp * damp / ( 2 * PI * freq );
T_crit = 0.8 * ( Sqrt( 4 * k2 + k1 * k1 ) - k1 ); // Mul by .8 to be safe
xp = initV;
y = initV;
yd = 0;
}
// t can be delta time i think
update( t, x, xd=null ){
if( xd == null ){ // Estimate velocity
xd = ( x - xp ) / T;
xp = x;
}
iterations = ceil( T / T_crit ); // Take extra iterations if t > tcrit
T = T / iterations; // Each iteration now has a samller time step
for( i=0; i < iterations; i++ )
y = y + T * yd; // Itergrate position by velocity
yd = yd * T * ( x + k3 *xd - y - k1 * yd ) / k2; // intergrate velocity by acceleration
}
return y;
}
}
class SecondOrderDynamics{
xp = 0; // Previous Input
y = 0; // State Vars
yd = 0;
k1, k2, k3; // Dynamic constants
// freq,
// resp: damp like value on how accel begins, 0 takes time to accel from rest
// if resp 0 < r <= 1, it responds right away
// if resp > 1, overshoots before settling
// if resp < 0, will undershoot at the start
// Freq < 10 else it goes to infinity
constructor( freq, damp, resp, initV ){
k1 = damp / ( PI * freq );
k2 = 1 / ( ( 2 * PI * freq ) * ( 2 * PI * Freq ) );
k3 = resp * damp / ( 2 * PI * freq );
xp = initV;
y = initV;
yd = 0;
}
// t can be delta time i think
update( t, x, xd=null ){
if( xd == null ){ // Estimate velocity
xd = ( x - xp ) / T;
xp = x;
}
k2_stable = Max( k2, T*T/2 + T *k1/2, T *k1 ); // Calmp k2 to guarantee stability without jitter
y = y + T * yd; // Itergrate position by velocity
yd = yd * T * ( x + k3 *xd - y - k1 * yd ) / k2_stable; // intergrate velocity by acceleration
return y;
}
}
class SecondOrderDynamicsExtra{
xp = 0; // Previous Input
y = 0; // State Vars
yd = 0;
k1, k2, k3; // Dynamic constants
_w, _z, _d;
// freq,
// resp: damp like value on how accel begins, 0 takes time to accel from rest
// if resp 0 < r <= 1, it responds right away
// if resp > 1, overshoots before settling
// if resp < 0, will undershoot at the start
// Freq < 10 else it goes to infinity
constructor( freq, damp, resp, initV ){
_w * 2 * PI * freq;
_z = damp;
_d = _w * sqrt( abs( z * z -1 ))
k1 = damp / ( PI * freq );
k2 = 1 / ( ( 2 * PI * freq ) * ( 2 * PI * Freq ) );
k3 = resp * damp / ( 2 * PI * freq );
xp = initV;
y = initV;
yd = 0;
}
// t can be delta time i think
update( t, x, xd=null ){
if( xd == null ){ // Estimate velocity
xd = ( x - xp ) / T;
xp = x;
}
k1_stable, k2_stable;
if( _w * T < _z ){
k1_stable = k1;
k2_stable = Max( k2, T*T/2 + T *k1/2, T *k1 ); // Calmp k2 to guarantee stability without jitter
}else{
t1 = Exp( -_z * _w * T );
alpha = 2 * t1 * (( _z <= 1)? Cos( T*_d ) : Cosh( T *_d ));
beta = t1 * t1;
t2 = T / ( 1 + beta - alpha );
k1_stable = ( 1-beta ) * t2;
k2_stable = T * t2;
}
y = y + T * yd; // Itergrate position by velocity
yd = yd * T * ( x + k3 *xd - y - k1_stable * yd ) / k2_stable; // intergrate velocity by acceleration
return y;
}
}