-
Notifications
You must be signed in to change notification settings - Fork 0
/
fx.h
56 lines (44 loc) · 748 Bytes
/
fx.h
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
struct fx_pull {
/* Config */
float damp;
const enum _time_type type;
/* Internal */
float t;
};
static void pullf(struct fx_pull *pull, const float target)
{
pull->t = lerpf_clamp(
pull->t,
target,
_time_dt(pull->type) * pull->damp
);
}
static void decayf(float *s, float amt)
{
float f = *s;
float mag = fabsf(f);
if (mag < amt) {
*s = 0.f;
return;
}
*s = f > 0.f ? f - amt : f + amt;
}
static void decay_v2(v2 *v, float amt)
{
if (!amt) return;
v2 f = *v;
float mag = v2_mag(f);
if (mag < amt) {
*v = V2_ZERO;
return;
}
v2 dir = v2_norm(f);
*v = v2_add(f, v2_mul(dir, -amt));
}
static void decay_v2xz(v3 *v, float amt)
{
ff prox = v3_xz(*v);
decay_v2(&prox, amt);
v->x = prox.x;
v->z = prox.y;
}