12static int32_t
divide_q12(int32_t numerator, int32_t divisor)
15 uint32_t low = (uint32_t)dividend;
16 int32_t high = (int32_t)(dividend >> 32);
18 __asm__
volatile(
"idivl %[divisor]" :
"+a"(low),
"+d"(high) : [divisor]
"rm"(divisor) :
"cc");
27 int32_t square_q12 = (int32_t)(((int64_t)x * x) >>
MATH_Q12_SHIFT);
39 long double ax = (
long double)point1->
x - point0->
x;
40 long double ay = (
long double)point1->
y - point0->
y;
41 long double az = (
long double)point1->
z - point0->
z;
42 volatile float bx = (float)((
long double)point2->
x - point1->
x);
43 volatile float by = (float)((
long double)point2->
y - point1->
y);
44 long double bz = (
long double)point2->
z - point1->
z;
45 volatile float nx = (float)(ay * bz - az * by);
46 volatile float ny = (float)(az * bx - ax * bz);
47 long double nz = ax * by - ay * bx;
48 long double scale = 1.0L / sqrtl(nz * nz + (
long double)ny * ny + (
long double)nx * nx);
50 out_normal->
x = (float)(nx * scale);
51 out_normal->
y = (float)(ny * scale);
52 out_normal->
z = (float)(nz * scale);
76 int32_t min_component;
80 min_component = abs_dx;
84 min_component = abs_dy;
86 int32_t mid_component;
90 mid_component = abs_dx;
93 else if (abs_dz >= min_component)
94 mid_component = abs_dz;
97 mid_component = min_component;
98 min_component = abs_dz;
115 uint32_t remainder = 0, root = 0;
119 remainder = (remainder << 2) | (value >> 30);
123 if (remainder >= root * 2 + 1)
125 remainder -= root * 2 + 1;
130 return (int32_t)root;
137 uint32_t remainder = 0;
143 remainder = (remainder << 2) | (value >> 30);
146 if (remainder >= root * 2 + 1)
148 remainder -= root * 2 + 1;
170 const long double determinant = bc_z * ab_x - bc_x * ab_z;
171 volatile float divisor = (float)determinant;
176 __asm__
volatile(
"ftst\n\tfnstsw %%ax" :
"=a"(status) :
"t"(determinant));
179 const long double ab_weight = (
long double)
x * bc_z -
z * bc_x;
180 const long double bc_weight =
z * ab_x -
x * ab_z;
186 int32_t
y = tri_b->
pos.
y;
191 return tri_a->
pos.
y * 64;
195 else if (tri_b->
pos.
y > tri_c->
pos.
y)
206 int16_t half_step = max_delta >> 1;
209 return (uint16_t)target_angle;
213 if ((int16_t)delta <= max_delta)
214 return (uint16_t)target_angle;
238 return ((seed >> 15) * range) >> 16;
253 return previous_seed;
266 return -(negative_half_magnitude);
276 int32_t abs_y_div64 =
y >> 6;
277 int32_t abs_x_div64 =
x >> 6;
279 if (!abs_y_div64 && !abs_x_div64)
283 abs_y_div64 = -abs_y_div64;
286 abs_x_div64 = -abs_x_div64;
290 if (abs_y_div64 <= abs_x_div64)
293 uint32_t ratio_q12 = ((uint32_t)abs_x_div64 / 2 + (uint32_t)abs_y_div64 *
MATH_Q12_HALF) * x_reciprocal_q12;
300 uint32_t ratio_q12 = ((uint32_t)abs_y_div64 / 2 + (uint32_t)abs_x_div64 *
MATH_Q12_HALF) * y_reciprocal_q12;
317 uint32_t rounded = (uint32_t)minor *
MATH_Q12_HALF + (uint32_t)(major >> 1);
318 return rounded / (uint32_t)major;
328 if (!abs_y && !abs_x)
357 int32_t cos_input = denominator;
358 int32_t sin_input = numerator;
359 int32_t abs_sin = sin_input;
360 int32_t abs_cos = cos_input;
366 abs_sin = -(sin_input);
370 abs_cos = -(cos_input);
371 sin_input = -(sin_input);
376 if (abs_sin < abs_cos)
381 if (sin_input < 0 && angle > 0)
394 if (cos_phase_angle < 0)
398 return cos_phase_angle;
407 int32_t ease_duration_sum = ease_in_q12 + ease_out_q12;
409 if (!ease_duration_sum)
414 ease_in_q12 =
divide_q12(ease_in_q12, ease_duration_sum);
415 ease_out_q12 =
divide_q12(ease_out_q12, ease_duration_sum);
420 if (t_q12 < ease_in_q12)
422 int32_t square_q12 = (int32_t)(((int64_t)t_q12 * t_q12) >>
MATH_Q12_SHIFT);
423 int32_t product_q12 = (int32_t)(((int64_t)square_q12 * velocity_scale_q12) >>
MATH_Q12_SHIFT);
430 int32_t linear_term = t_q12 * 2 - ease_in_q12;
432 return (int32_t)(((int64_t)linear_term * velocity_scale_q12) >>
MATH_Q12_SHIFT);
436 int32_t square_q12 = (int32_t)(((int64_t)remaining_q12 * remaining_q12) >>
MATH_Q12_SHIFT);
437 int32_t product_q12 = (int32_t)(((int64_t)square_q12 * velocity_scale_q12) >>
MATH_Q12_SHIFT);
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP14(uint32_t value)
int32_t Math_CalculateTriangleHeight(int32_t local_xq6, int32_t local_zq6, struct Collision_Vertex const *tri_a, struct Collision_Vertex const *tri_b, struct Collision_Vertex const *tri_c)
int32_t Math_SqrtFP12(uint32_t value)
int32_t Math_EaseInOut(int32_t t_q12, int32_t ease_in_q12, int32_t ease_out_q12)
static int32_t divide_q12(int32_t numerator, int32_t divisor)
uint16_t Math_ClampAngleDelta(int16_t target_angle, int16_t current_angle, int16_t max_delta)
static uint32_t angle_ratio_index(int32_t minor, int32_t major)
int32_t Math_AcosRatioFP12(int32_t numerator, int32_t denominator)
uint32_t Math_SetRandomSeed(uint32_t seed)
struct Math_Vec3F * Math_CalculateFaceNormal(struct Math_Vec3F *out_normal, struct Math_Vec3F const *point0, struct Math_Vec3F const *point1, struct Math_Vec3F const *point2)
int32_t Math_ApproxDistance3DWeighted(int32_t dx, int32_t dy, int32_t dz)
int32_t Math_EaseInOutQuadraticQ12(int32_t input_q12)
int16_t Math_CalculateAtan2FP12(int32_t y, int32_t x)
uint32_t Math_GenerateRandom(uint32_t range)
int32_t Math_AsinRatioFP12(int32_t numerator, int32_t denominator)
int32_t Math_CalculateAtan2Fast(int32_t y, int32_t x)
#define MATH_ANGLE_QUARTER_TURN
#define MATH_RANDOM_MULTIPLIER
#define MATH_Q6_SCALE_LONG_DOUBLE
#define MATH_ANGLE_HALF_MASK
#define MATH_RANDOM_QUOTIENT
#define MATH_DISTANCE_3D_MIDDLE_WEIGHT
#define MATH_ANGLE_WRAP_MASK
#define MATH_SQRT_Q14_PAIR_COUNT
#define MATH_ANGLE_HALF_TURN
#define MATH_RANDOM_REMAINDER
#define MATH_Q12_SQUARED_ONE
#define MATH_DISTANCE_3D_MIN_WEIGHT
#define MATH_SQRT_Q12_PAIR_COUNT
#define MATH_Q12_SCALE_LONG_DOUBLE
#define MATH_DISTANCE_2D_MAX_WEIGHT
#define MATH_DISTANCE_3D_MAX_WEIGHT
#define MATH_ANGLE_FULL_TURN
#define MATH_DISTANCE_2D_MIN_WEIGHT
#define MATH_RANDOM_MODULUS
int64_t __ftol_msvc(long double value)
uint16_t image_read_table_word(const void *table, uint32_t index)
struct Collision_Vertex::@111126275124057154070202104324102117233165176236::@061322026074334072070347216127267241215241121036 pos
#define g_atanRatioAngleTableQ12
#define g_asinRatioAngleTableQ12
#define g_atanReciprocalQ12