14 return (int32_t)((uint64_t)((int64_t)left_factor * right_factor) >> 14);
20 int32_t from_weight, int32_t to_weight)
26 return (int16_t)(weighted_from_component + weighted_to_component);
32 for (
unsigned i = 0; i < 4; i += 2)
35 memcpy(&pair, &source->
components[i],
sizeof(pair));
36 memcpy(&out->
components[i], &pair,
sizeof(pair));
42 const int32_t dot = a->
w * b->
w + a->
x * b->
x + a->
y * b->
y + a->
z * b->
z;
55 int32_t to_weight = blend_weight_q14;
58 if ((uint32_t)dot + 0x3ff0u < 0x7fe0u)
61 int32_t phase = ((int16_t)angle * blend_weight_q14) >> 14;
68 to_weight = -to_weight;
69 for (
unsigned i = 0; i < 4; ++i)
85 while (sample_time >=
key_time_q6(keys[low].timing.packed))
93 int middle = (low + high) / 2;
94 if (sample_time <
key_time_q6(keys[middle].timing.packed))
128 if ((uintptr_t)keys == UINT32_MAX)
138 uint32_t last_time =
key_time_q6(keys[last].timing.packed);
143 if (sample_time == last_time)
148 if (sample_time < last_time)
154 else if (sample_time >= end_time)
167 int32_t turns = (uint8_t)flags;
169 int32_t tangent_angle = flags >> 20;
172 if (turns && rotation_angle == 0)
178 .w = (int16_t)cosine,
182 if (tangent_angle == 0)
205 int32_t blend_weight_q14, int32_t angle_fp12, int32_t spin_phase)
207 int32_t reciprocal = 0;
208 int32_t from_weight = (int32_t)(0x4000u - (uint32_t)blend_weight_q14);
209 int32_t to_weight = blend_weight_q14;
211 if ((uint16_t)angle_fp12 != 0)
217 reciprocal = 0x10000000 / sine;
219 int32_t phase_sum = (int16_t)((uint32_t)spin_phase << 11) + (int16_t)angle_fp12;
221 int32_t phase_product = (int32_t)((uint32_t)phase_sum * (uint32_t)blend_weight_q14);
222 int32_t phase = phase_product >> 14;
223 int32_t remaining_angle = (int32_t)((uint32_t)angle_fp12 - (uint32_t)phase);
239 if (reciprocal <= 0x50000)
242 int32_t
w = out->
w,
x = out->
x,
y = out->
y,
z = out->
z;
243 uint32_t norm_bits = (uint32_t)(
w *
w) + (uint32_t)(
x *
x) + (uint32_t)(
y *
y) + (uint32_t)(
z *
z);
244 int32_t norm_q14 = (int32_t)norm_bits >> 14;
247 if ((uint32_t)norm_q14 + 0x3ff0u >= 0x7fe0u)
252 uint32_t scale = 0x10000000u / (uint32_t)
Math_SqrtFP14((uint32_t)norm_q14);
268 int32_t
w = sampled_quat.
w,
x = sampled_quat.
x,
y = sampled_quat.
y,
z = sampled_quat.
z;
273 .
m00 = (half_q28 - y * y - z * z) >> 15,
274 .m01 = (x * y + w * z) >> 15,
275 .m02 = (x * z - w * y) >> 15,
276 .m10 = (x * y - w * z) >> 15,
277 .m11 = (half_q28 - x * x - z * z) >> 15,
278 .m12 = (y * z + w * x) >> 15,
279 .m20 = (x * z + w * y) >> 15,
280 .m21 = (y * z - w * x) >> 15,
281 .m22 = (half_q28 - x * x - y * y) >> 15};
#define ANIMATION_QUATERNION_SPIN_ANGLE_MASK
#define ANIMATION_SPLINE_REPEAT_ENDPOINT
#define ANIMATION_SPLINE_TIME_Q6_MASK
#define ANIMATION_TIME_BIAS_MASK
#define ANIMATION_SPLINE_WRAP_SAMPLE_TIME
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)
#define MATH_ANGLE_QUARTER_TURN
#define MATH_ANGLE_HALF_MASK
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP14(uint32_t value)
int32_t Math_AcosRatioFP12(int32_t numerator, int32_t denominator)
static void compose_spin(struct Math_QuaternionI16 *out, const struct Math_QuaternionI16 *base, const struct Math_QuaternionI16 *spin)
void Animation_InterpolateQuat(uint32_t frame_time, struct Animation_SplineChannelQuat *quat_track, struct Math_QuaternionI16 *out_quat)
static int next_rotation_key(const struct Animation_RotationKeyframe *keys, int last, uint32_t sample_time)
static int16_t Quaternion_BlendComponent(int16_t from_component, int16_t to_component, int32_t from_weight, int32_t to_weight)
void Animation_InterpolateKeyframeQuatBlend(uint32_t frame_time, int32_t blend_weight_q14, struct Animation_SplineChannelQuat *quat_track, struct Math_QuaternionI16 *inout_quat)
void Animation_ConvertQuatToRotMatrix(uint32_t frame_time, struct Animation_SplineChannelQuat *quat_track, struct Math_Matrix3x3I16 *out_matrix)
static int32_t quaternion_dot_q14(const struct Math_QuaternionI16 *a, const struct Math_QuaternionI16 *b)
static int32_t Quaternion_MultiplyQ14(int32_t left_factor, int32_t right_factor)
void Animation_InterpolateQuaternionSlerp(struct Math_QuaternionI16 *out_quat, struct Math_QuaternionI16 *from_quat, struct Math_QuaternionI16 *to_quat, int32_t blend_weight_q14, int32_t angle_fp12, int32_t spin_phase)
static void copy_packed_quaternion(struct Math_QuaternionI16 *out, const struct Math_QuaternionI16 *source)
static uint32_t key_time_q6(uint32_t packed_timing)
struct Math_QuaternionI16 tangent_out
union Animation_KeyframeTiming timing
struct Math_QuaternionI16 tangent_in
struct Math_QuaternionI16 rotation
struct Math_QuaternionI16 value_q14
struct Animation_RotationKeyframe * keyframes_or_minus_one_sentinel
int32_t packed_time_bias_and_end_time
Animation_SplineChannelFlags channel_flags