102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
spline.h
Go to the documentation of this file.
1
#ifndef PCDOGS_ANIMATION_SPLINE_H
2
#define PCDOGS_ANIMATION_SPLINE_H
3
4
#include "
pcdogs/animation/constants.h
"
5
#include "
pcdogs/animation/functions.h
"
6
#include "
pcdogs/animation/types.h
"
7
#include "
pcdogs/math/constants.h
"
8
9
struct
HermiteWeights
10
{
11
int32_t
start_value
,
end_value
;
12
int32_t
start_tangent
,
end_tangent
;
13
};
14
15
static
inline
uint32_t
spline_key_time
(uint32_t packed)
16
{
17
return
(packed >> 14) &
ANIMATION_SPLINE_TIME_Q6_MASK
;
18
}
19
20
static
inline
int32_t
spline_mul_q12
(int32_t a, int32_t b)
21
{
22
return
(int32_t)(((int64_t)a * b) >>
MATH_Q12_SHIFT
);
23
}
24
25
static
inline
struct
HermiteWeights
spline_weights
(int32_t t)
26
{
27
/* SHRD 12, SHR 8 discards high bits before the Q20 product is reused. */
28
uint32_t square = (uint32_t)
spline_mul_q12
(t, t) >> 8;
29
uint32_t cube = (uint32_t)
spline_mul_q12
(t, square) >> 8;
30
int32_t
end_value
= (int32_t)(3 * square - 2 * cube) >> 8;
31
struct
HermiteWeights
weights = {
32
MATH_Q12_ONE
-
end_value
,
end_value
,
33
(int32_t)(cube - 2 * square + (uint32_t)t) >> 8,
34
(int32_t)(cube - square) >> 8};
35
return
weights;
36
}
37
38
/* Skin weight samplers treat a negative time as preceding every key in the
39
endpoint and linear scans. All three samplers use unsigned binary search. */
40
static
inline
int32_t
sample_scalar_keys
(uint32_t frame_time,
struct
Animation_SplineChannelScalar
*channel,
41
bool
signed_time)
42
{
43
struct
Animation_ScalarKeyframe
*keys = channel->
keyframes_or_minus_one_sentinel
;
44
int
last = channel->
keyframe_count
- 1;
45
struct
Animation_ScalarKeyframe
*start = &keys[last];
46
struct
Animation_ScalarKeyframe
*end = keys;
47
uint32_t time = frame_time + ((uint32_t)(uint16_t)channel->
packed_time_bias_and_end_time
<< 6);
48
bool
before_zero = signed_time && (int32_t)time < 0;
49
uint32_t end_time =
spline_key_time
(start->
timing
.
packed
);
50
if
(before_zero || time < end_time)
51
{
52
int
next = 1;
53
if
(last <= 3)
54
{
55
while
(!before_zero && time >=
spline_key_time
(keys[next].
timing
.
packed
))
56
++next;
57
}
58
else
59
{
60
int
high = last;
61
while
(next <= high)
62
{
63
int
mid = (next + high) / 2;
64
if
(time <
spline_key_time
(keys[mid].
timing
.
packed
))
65
high = mid - 1;
66
else
67
next = mid + 1;
68
}
69
}
70
start = &keys[next - 1];
71
end = &keys[next];
72
end_time =
spline_key_time
(end->
timing
.
packed
);
73
}
74
else
75
{
76
if
(time == end_time)
77
return
start->
value
;
78
end_time =
spline_key_time
(channel->
packed_time_bias_and_end_time
);
79
if
(time >= end_time)
80
{
81
const
unsigned
wrap =
ANIMATION_SPLINE_REPEAT_ENDPOINT
|
ANIMATION_SPLINE_WRAP_SAMPLE_TIME
;
82
return
(channel->
channel_flags
& wrap) == wrap ? end->
value
: start->
value
;
83
}
84
}
85
86
int32_t t =
Animation_CalculateSplineParameter
(time, end_time, start->
timing
.
packed
,
87
(uint8_t)end->
timing
.
packed
, (uint8_t *)keys);
88
struct
HermiteWeights
w =
spline_weights
(t);
89
return
(int32_t)((uint32_t)
spline_mul_q12
(w.
start_value
, start->
value
) +
90
(uint32_t)
spline_mul_q12
(w.
end_value
, end->
value
) +
91
(uint32_t)
spline_mul_q12
(w.
start_tangent
, start->
tangent_out
) +
92
(uint32_t)
spline_mul_q12
(w.
end_tangent
, end->
tangent_in
));
93
}
94
95
#endif
constants.h
ANIMATION_SPLINE_REPEAT_ENDPOINT
#define ANIMATION_SPLINE_REPEAT_ENDPOINT
Definition
constants.h:31
ANIMATION_SPLINE_TIME_Q6_MASK
#define ANIMATION_SPLINE_TIME_Q6_MASK
Definition
constants.h:37
ANIMATION_SPLINE_WRAP_SAMPLE_TIME
#define ANIMATION_SPLINE_WRAP_SAMPLE_TIME
Definition
enums.h:55
functions.h
Animation_CalculateSplineParameter
int32_t Animation_CalculateSplineParameter(uint32_t sample_time, uint32_t next_key_time, uint32_t prev_key_packed, uint8_t next_ease_index, uint8_t *keyframe_data)
Definition
interpolation.c:121
types.h
constants.h
MATH_Q12_SHIFT
#define MATH_Q12_SHIFT
Definition
constants.h:8
MATH_Q12_ONE
#define MATH_Q12_ONE
Definition
constants.h:9
sample_scalar_keys
static int32_t sample_scalar_keys(uint32_t frame_time, struct Animation_SplineChannelScalar *channel, bool signed_time)
Definition
spline.h:40
spline_key_time
static uint32_t spline_key_time(uint32_t packed)
Definition
spline.h:15
spline_weights
static struct HermiteWeights spline_weights(int32_t t)
Definition
spline.h:25
spline_mul_q12
static int32_t spline_mul_q12(int32_t a, int32_t b)
Definition
spline.h:20
Animation_ScalarKeyframe
Definition
types.h:1175
Animation_ScalarKeyframe::tangent_out
int32_t tangent_out
Definition
types.h:1178
Animation_ScalarKeyframe::tangent_in
int32_t tangent_in
Definition
types.h:1179
Animation_ScalarKeyframe::timing
union Animation_KeyframeTiming timing
Definition
types.h:1176
Animation_ScalarKeyframe::value
int32_t value
Definition
types.h:1177
Animation_SplineChannelScalar
Definition
types.h:352
Animation_SplineChannelScalar::keyframe_count
uint8_t keyframe_count
Definition
types.h:355
Animation_SplineChannelScalar::keyframes_or_minus_one_sentinel
struct Animation_ScalarKeyframe * keyframes_or_minus_one_sentinel
Definition
types.h:353
Animation_SplineChannelScalar::packed_time_bias_and_end_time
int32_t packed_time_bias_and_end_time
Definition
types.h:354
Animation_SplineChannelScalar::channel_flags
Animation_SplineChannelFlags channel_flags
Definition
types.h:358
HermiteWeights
Definition
spline.h:10
HermiteWeights::end_tangent
int32_t end_tangent
Definition
spline.h:12
HermiteWeights::start_tangent
int32_t start_tangent
Definition
spline.h:12
HermiteWeights::end_value
int32_t end_value
Definition
spline.h:11
HermiteWeights::start_value
int32_t start_value
Definition
spline.h:11
Animation_KeyframeTiming::packed
uint32_t packed
Definition
types.h:807
src
animation
spline.h
Generated by
1.17.0