51# define JO_PI (3.1415927f)
54# define JO_PI_2 (1.5707963f)
69# define JO_MULT_BY_2(X) ((X) << 1)
75# define JO_MULT_BY_4(X) ((X) << 2)
81# define JO_MULT_BY_8(X) ((X) << 3)
87# define JO_MULT_BY_16(X) ((X) << 4)
93# define JO_MULT_BY_32(X) ((X) << 5)
99# define JO_MULT_BY_64(X) ((X) << 6)
105# define JO_MULT_BY_128(X) ((X) << 7)
111# define JO_MULT_BY_256(X) ((X) << 8)
117# define JO_MULT_BY_512(X) ((X) << 9)
123# define JO_MULT_BY_1024(X) ((X) << 10)
129# define JO_MULT_BY_2048(X) ((X) << 11)
135# define JO_MULT_BY_4096(X) ((X) << 12)
141# define JO_MULT_BY_32768(X) ((X) << 15)
147# define JO_MULT_BY_65536(X) ((X) << 16)
153# define JO_DIV_BY_2(X) ((X) >> 1)
159# define JO_DIV_BY_4(X) ((X) >> 2)
165# define JO_DIV_BY_8(X) ((X) >> 3)
171# define JO_DIV_BY_16(X) ((X) >> 4)
177# define JO_DIV_BY_32(X) ((X) >> 5)
183# define JO_DIV_BY_64(X) ((X) >> 6)
189# define JO_DIV_BY_128(X) ((X) >> 7)
195# define JO_DIV_BY_256(X) ((X) >> 8)
201# define JO_DIV_BY_512(X) ((X) >> 9)
207# define JO_DIV_BY_1024(X) ((X) >> 10)
213# define JO_DIV_BY_32768(X) ((X) >> 15)
219# define JO_DIV_BY_65536(X) ((X) >> 16)
225# define JO_DIV_BY_2147483648(X) ((X) >> 31)
240# define JO_ZERO(X) X ^= X
247# define JO_MOD_POW2(N, M) ((N) & ((M) - 1))
252# define JO_IS_POW2(N) ((N) != 0 && (((N) & ((N) - 1)) == 0))
257# define JO_ABS(X) ((X) < 0 ? -(X) : (X))
262# define JO_FABS(X) ((X) < 0.0f ? -(X) : (X))
268# define JO_MIN(A, B) (((A) < (B)) ? (A) : (B))
274# define JO_MAX(A, B) (((A) > (B)) ? (A) : (B))
279# define JO_CHANGE_SIGN(X) (-(X))
282# define JO_FLOAT_EPSILON (0.00001f)
288# define JO_FLOAT_NEARLY_EQUALS(A, B) ((A) <= ((B) + JO_FLOAT_EPSILON) && (A) >= ((B) - JO_FLOAT_EPSILON))
293# define JO_IS_FLOAT_NULL(A) ((A) <= JO_FLOAT_EPSILON && (A) >= (-JO_FLOAT_EPSILON))
298# define JO_RAD_TO_DEG(A) ((A) * 57.295780f)
303# define JO_DEG_TO_RAD(A) ((A) * 0.017453292f)
308# define JO_IS_ODD(A) ((A) & 1)
315# define JO_SWAP(A, B) { __typeof__((A) + 0) __jo_swap_tmp = (A); (A) = (B); (B) = __jo_swap_tmp; }
323# define JO_OPAQUE(VAR) __asm__ ("" : "+r" (VAR))
330# define JO_PERCENT_USED(TOTAL, FREE) ((TOTAL) == 0 ? 0 : (int)((unsigned int)((TOTAL) - (FREE)) * 100u / (unsigned int)(TOTAL)))
335# define JO_SQUARE(A) ((A) * (A))
340# define JO_BCD_INT(BCD) (((BCD & 0xF0) >> 4) * 10 + (BCD & 0x0F))
355# define JO_SET_FLAGS(BYTEFIELD, FLAGS) BYTEFIELD = (FLAGS)
360# define JO_SET_ALL_FLAGS(BYTEFIELD) BYTEFIELD = (~0)
366# define JO_ADD_FLAG(BYTEFIELD, FLAG) BYTEFIELD |= (FLAG)
372# define JO_REMOVE_FLAG(BYTEFIELD, FLAG) BYTEFIELD &= ~(FLAG)
377# define JO_REMOVE_ALL_FLAGS(BYTEFIELD) BYTEFIELD = 0
383# define JO_HAS_FLAG(BYTEFIELD, FLAG) ((BYTEFIELD & FLAG) == FLAG)
399# define JO_FIXED_0 (0)
401# define JO_FIXED_1_DIV_2 (32768)
403# define JO_FIXED_ALMOST_1 (65470)
405# define JO_FIXED_1 (65536)
407# define JO_FIXED_2 JO_INT_TO_FIXED(2)
409# define JO_FIXED_3 JO_INT_TO_FIXED(3)
411# define JO_FIXED_4 JO_INT_TO_FIXED(4)
413# define JO_FIXED_8 JO_INT_TO_FIXED(8)
415# define JO_FIXED_16 JO_INT_TO_FIXED(16)
417# define JO_FIXED_32 JO_INT_TO_FIXED(32)
419# define JO_FIXED_120 JO_INT_TO_FIXED(120)
421# define JO_FIXED_150 JO_INT_TO_FIXED(150)
423# define JO_FIXED_180 JO_INT_TO_FIXED(180)
425# define JO_FIXED_360 JO_INT_TO_FIXED(360)
428# define JO_FIXED_MIN (-2147483647)
430# define JO_FIXED_MAX (2147483647)
432# define JO_FIXED_EPSILON (1)
434# define JO_FIXED_OVERFLOW (0x80000000)
436# define JO_FIXED_PI (205887)
438# define JO_FIXED_PI_2 (411775)
440# define JO_FIXED_180_DIV_PI (3754936)
442# define JO_FIXED_PI_DIV_180 (1144)
444# define JO_FIXED_PI_DIV_2 (102944)
446# define JO_FIXED_PI_OVER_2 JO_FIXED_PI_DIV_2
448# define JO_FIXED_3_PI_OVER_2 (308331)
450# define JO_FIXED_1_DIV (1.0f / 65536.0f)
455# define JO_INT_TO_FIXED(X) JO_MULT_BY_65536(X)
459# define JO_FIXED_TO_INT(X) JO_DIV_BY_65536(X)
461# define JO_FIXED_DECIMAL_MASK (0xFFFF)
465# define JO_FLOAT_TO_FIXED(X) ((jo_fixed)(65536.0f * (X)))
469# define JO_DEG_TO_ANGLE(X) ((jo_angle)((65536.0 * (X)) / 360.0))
473# define JO_RAD_TO_ANGLE(X) ((jo_angle)((65536.0 * (X)) / (2.0 * 3.14159265358979)))
548 return ((
jo_fixed)(((
long long)x * y) >> 16));
561 __asm__ (
"dmuls.l %1, %2\n\t"
585 __asm__ (
"clrmac\n\t"
586 "mac.l @%2+, @%3+\n\t"
587 "mac.l @%2+, @%3+\n\t"
588 "mac.l @%2+, @%3+\n\t"
592 :
"=&r" (high),
"=&r" (low),
"+r" (a),
"+r" (b)
640 return (x < 0 ? (
int)~(~(
unsigned int)x >> 8) : (
int)((
unsigned int)x >> 8));
651 return ((
int)(((
unsigned int)x + (1u << 23)) >> 8) - (1 << 15));
700 return (x & 0xFFFF0000UL) + (x & 0x0000FFFFUL ?
JO_FIXED_1 : 0);
709 return (x & 0xFFFF0000ul);
741 return (
jo_random(max) / multiple) * multiple;
855# define __JO_DEG_TO_ANGLE_MAGIC (182)
864 return ((
jo_angle)(deg * (65536.0f / 360.0f)));
878 n = deg < 0 ? -deg : deg;
879 a = (int)(((
long long)(n * 8192) * 95443718LL) >> 32);
880 return ((
jo_angle)(deg < 0 ? -a : a));
891 return ((
jo_angle)(((
long long)rad * 683565276LL) >> 32));
919 return (((((
unsigned short)angle) + 8) >> 4) & 0xfff);
963 return ((
jo_angle)(((
long long)deg * 11930465LL) >> 32));
1043 return (value *
jo_sinf(deg));
1135 return (value *
jo_cosf(deg));
1211 return (1.5707963f - 1.5707963f * angle);
1286 if (d >= 360 || d <= -360)
1294 else if (d < -max_step)
1297 if (d >= 360 || d <= -360)
1299 return (d < 0 ? d + 360 : d);
1338 result->x = a->x + b->x;
1339 result->y = a->y + b->y;
1340 result->z = a->z + b->z;
1364 result->x = a->x + b->x;
1365 result->y = a->y + b->y;
1366 result->z = a->z + b->z;
1378 result->x = a->x - b->x;
1379 result->y = a->y - b->y;
1380 result->z = a->z - b->z;
1447 result->
x = a->
x + b->
x;
1448 result->
y = a->
y + b->
y;
1449 result->
z = a->
z + b->
z;
1460 result->
x = a->
x + s;
1461 result->
y = a->
y + s;
1462 result->
z = a->
z + s;
1473 result->
x = a->
x - b->
x;
1474 result->
y = a->
y - b->
y;
1475 result->
z = a->
z - b->
z;
1486 result->
x = a->
x - s;
1487 result->
y = a->
y - s;
1488 result->
z = a->
z - s;
1499 result->
x = a->
x * b->
x;
1500 result->
y = a->
y * b->
y;
1501 result->
z = a->
z * b->
z;
1512 result->
x = a->
x * s;
1513 result->
y = a->
y * s;
1514 result->
z = a->
z * s;
1525 result->
x = a->
x / b->
x;
1526 result->
y = a->
y / b->
y;
1527 result->
z = a->
z / b->
z;
1542 result->
x = a->
x * inv;
1543 result->
y = a->
y * inv;
1544 result->
z = a->
z * inv;
1563 return (a->
x * b->
x + a->
y * b->
y + a->
z * b->
z);
1577 float inv = 1.0f / len;
1578 result->
x = a->
x * inv;
1579 result->
y = a->
y * inv;
1580 result->
z = a->
z * inv;
1608 result->
x = a->
y * b->
z - a->
z * b->
y;
1609 result->
y = a->
z * b->
x - a->
x * b->
z;
1610 result->
z = a->
x * b->
y - a->
y * b->
x;
1641 for (i = 1; i < 15; ++i)
1656 for (i = 1; i < 15; ++i)
1657 result->
table[i] = 0;
1671 result->m30 = offset->x;
1672 result->m31 = offset->y;
1673 result->m32 = offset->z;
1683 result->m30 = offset->
x;
1684 result->m31 = offset->
y;
1685 result->m32 = offset->
z;
1695 result->m00 = scale->x;
1696 result->m11 = scale->y;
1697 result->m22 = scale->z;
1707 result->m00 = scale->
x;
1708 result->m11 = scale->
y;
1709 result->m22 = scale->
z;
1721 result->m21 = -result->m12;
1722 result->m22 = result->m11;
1734 result->m21 = -result->m12;
1735 result->m22 = result->m11;
1747 result->m02 = -result->m20;
1748 result->m22 = result->m00;
1760 result->m02 = -result->m20;
1761 result->m22 = result->m00;
1773 result->m10 = -result->m01;
1774 result->m11 = result->m00;
1786 result->m10 = -result->m01;
1787 result->m11 = result->m00;
1797 result->m00 = matrix->m00;
1798 result->m10 = matrix->m01;
1799 result->m20 = matrix->m02;
1800 result->m30 = matrix->m03;
1801 result->m01 = matrix->m10;
1802 result->m11 = matrix->m11;
1803 result->m21 = matrix->m12;
1804 result->m31 = matrix->m13;
1805 result->m02 = matrix->m20;
1806 result->m12 = matrix->m21;
1807 result->m22 = matrix->m22;
1808 result->m32 = matrix->m23;
1809 result->m03 = matrix->m30;
1810 result->m13 = matrix->m31;
1811 result->m23 = matrix->m32;
1812 result->m33 = matrix->m33;
1822 result->m00 = matrix->m00;
1823 result->m10 = matrix->m01;
1824 result->m20 = matrix->m02;
1825 result->m30 = matrix->m03;
1826 result->m01 = matrix->m10;
1827 result->m11 = matrix->m11;
1828 result->m21 = matrix->m12;
1829 result->m31 = matrix->m13;
1830 result->m02 = matrix->m20;
1831 result->m12 = matrix->m21;
1832 result->m22 = matrix->m22;
1833 result->m32 = matrix->m23;
1834 result->m03 = matrix->m30;
1835 result->m13 = matrix->m31;
1836 result->m23 = matrix->m32;
1837 result->m33 = matrix->m33;
1869 __asm__ (
"clrmac\n\t"
1870 "mac.l @%2+, @%3+\n\t"
1871 "mac.l @%2+, @%3+\n\t"
1872 "mac.l @%2+, @%3+\n\t"
1873 "mac.l @%2+, @%3+\n\t"
1877 :
"=&r" (high),
"=&r" (low),
"+r" (a),
"+r" (b)
1899 for (i = 0; i < 4; ++i)
1900 for (j = 0; j < 4; ++j)
1917 for (i = 0; i < 4; ++i)
1919 for (j = 0; j < 4; ++j)
1922 for (k = 0; k < 4; ++k)
1923 sum += a->
m[k][j] * b->
m[i][k];
1924 result->
m[i][j] = sum;
1943 result->m00 = c + normalized_axis.
x * normalized_axis.
x * a;
1944 result->m10 = normalized_axis.
x * normalized_axis.
y * a - normalized_axis.
z * s;
1945 result->m20 = normalized_axis.
x * normalized_axis.
z * a + normalized_axis.
y * s;
1946 result->m01 = normalized_axis.
y * normalized_axis.
x * a + normalized_axis.
z * s;
1947 result->m11 = c + normalized_axis.
y * normalized_axis.
y * a;
1948 result->m21 = normalized_axis.
y * normalized_axis.
z * a - normalized_axis.
x * s;
1949 result->m02 = normalized_axis.
z * normalized_axis.
x * a - normalized_axis.
y * s;
1950 result->m12 = normalized_axis.
z * normalized_axis.
y * a + normalized_axis.
x * s;
1951 result->m22 = c + normalized_axis.
z * normalized_axis.
z * a;
1964 const float back,
const float front,
jo_matrixf *
const result)
1967 result->m00 = 2 / (right - left);
1968 result->m11 = 2 / (top - bottom);
1969 result->m22 = 2 / (back - front);
1970 result->m30 = -(right + left) / (right - left);
1971 result->m31 = -(top + bottom) / (top - bottom);
1972 result->m32 = -(back + front) / (back - front);
1984 const float near_view_distance,
const float far_view_distance,
jo_matrixf *
const result)
1987 result->m11 = 1.0f /
jo_tan_radf(vertical_field_of_view_in_deg * (
JO_PI / 360.0f));
1988 result->m00 = result->m11 / aspect_ratio;
1989 result->m22 = (far_view_distance + near_view_distance) / (near_view_distance - far_view_distance);
1990 result->m32 = (2 * far_view_distance * near_view_distance) / (near_view_distance - far_view_distance);
2037 float c00 = matrix->m11 * matrix->m22 - matrix->m12 * matrix->m21;
2038 float c10 = -(matrix->m01 * matrix->m22 - matrix->m02 * matrix->m21);
2039 float c20 = matrix->m01 * matrix->m12 - matrix->m02 * matrix->m11;
2040 float det = matrix->m00 * c00 + matrix->m10 * c10 + matrix->m20 * c20;
2044 float c01 = -(matrix->m10 * matrix->m22 - matrix->m12 * matrix->m20);
2045 float c11 = matrix->m00 * matrix->m22 - matrix->m02 * matrix->m20;
2046 float c21 = -(matrix->m00 * matrix->m12 - matrix->m02 * matrix->m10);
2047 float c02 = matrix->m10 * matrix->m21 - matrix->m11 * matrix->m20;
2048 float c12 = -(matrix->m00 * matrix->m21 - matrix->m01 * matrix->m20);
2049 float c22 = matrix->m00 * matrix->m11 - matrix->m01 * matrix->m10;
2051 float inv_det = 1.0f / det;
2052 float i00 = c00 * inv_det;
2053 float i10 = c01 * inv_det;
2054 float i20 = c02 * inv_det;
2055 float i01 = c10 * inv_det;
2056 float i11 = c11 * inv_det;
2057 float i21 = c12 * inv_det;
2058 float i02 = c20 * inv_det;
2059 float i12 = c21 * inv_det;
2060 float i22 = c22 * inv_det;
2065 result->m30 = -(i00 * matrix->m30 + i10 * matrix->m31 + i20 * matrix->m32);
2069 result->m31 = -(i01 * matrix->m30 + i11 * matrix->m31 + i21 * matrix->m32);
2073 result->m32 = -(i02 * matrix->m30 + i12 * matrix->m31 + i22 * matrix->m32);
2084 float w = matrix->m03 * position->
x + matrix->m13 * position->
y + matrix->m23 * position->
z + matrix->m33;
2085 result->
x = matrix->m00 * position->
x + matrix->m10 * position->
y + matrix->m20 * position->
z + matrix->m30;
2086 result->
y = matrix->m01 * position->
x + matrix->m11 * position->
y + matrix->m21 * position->
z + matrix->m31;
2087 result->
z = matrix->m02 * position->
x + matrix->m12 * position->
y + matrix->m22 * position->
z + matrix->m32;
2088 if (w != 0 && w != 1)
2091 float inv_w = 1.0f / w;
2106 float w = matrix->m03 * direction->
x + matrix->m13 * direction->
y + matrix->m23 * direction->
z;
2107 result->
x = matrix->m00 * direction->
x + matrix->m10 * direction->
y + matrix->m20 * direction->
z;
2108 result->
y = matrix->m01 * direction->
x + matrix->m11 * direction->
y + matrix->m21 * direction->
z;
2109 result->
z = matrix->m02 * direction->
x + matrix->m12 * direction->
y + matrix->m22 * direction->
z;
2110 if (w != 0 && w != 1)
2113 float inv_w = 1.0f / w;
2147 return (
JO_ABS(f) < 0.00000001f);
2162 const int x2,
const int y2,
const int w2,
const int h2)
2164 return ((x1 < x2 + w2) && (x2 < x1 + w1)) && ((y1 < y2 + h2) && (y2 < y1 + h1));
static __jo_force_inline void jo_matrixf_transpose(const jo_matrixf *const matrix, jo_matrixf *const result)
Creates transpose matrix (using floating numbers).
Definition math.h:1820
static __jo_force_inline jo_fixed jo_int2fixed(const int x)
Convert int to jo engine fixed.
Definition math.h:479
static __jo_force_inline void jo_matrix_rotation_y_rad(const float angle_in_rad, jo_matrix *const result)
Creates rotating matrix (Y axis) (using fixed numbers).
Definition math.h:1742
static __jo_force_inline jo_angle jo_DEGtoANG(const float deg)
Convert a degree to jo_angle using floating number.
Definition math.h:861
#define JO_PI
PI value.
Definition math.h:51
static __jo_force_inline void jo_matrix_mul(const jo_matrix *const a, const jo_matrix *const b, jo_matrix *const result)
Multiply 2 matrix (using fixed numbers).
Definition math.h:1891
static __jo_force_inline void jo_matrixf_rotation_z_rad(const float angle_in_rad, jo_matrixf *const result)
Creates rotating matrix (Z axis) (using floating numbers).
Definition math.h:1781
static __jo_force_inline void jo_vector4_fixed_cross(const jo_vector4_fixed *const a, const jo_vector4_fixed *const b, jo_vector4_fixed *const result)
Cross product of 2 vectors4 (using fixed numbers).
Definition math.h:1389
static __jo_force_inline void jo_matrix_rotation_z_rad(const float angle_in_rad, jo_matrix *const result)
Creates rotating matrix (Z axis) (using fixed numbers).
Definition math.h:1768
void jo_planar_rotate(const jo_pos2D *const point, const jo_pos2D *const origin, const int angle, jo_pos2D *const result)
Rotate a point on the plan with a specific origin.
static __jo_force_inline jo_angle jo_DEGtoANG_int(const int deg)
Convert a degree to jo_angle using interger.
Definition math.h:871
void jo_vector_fixed_compute_bezier_point(const jo_fixed t, jo_vector_fixed p0, jo_vector_fixed p1, jo_vector_fixed p2, jo_vector_fixed p3, jo_vector_fixed *result)
Compute cubic bezier curve point for vectors (using fixed numbers).
static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
Sinus computation.
Definition math.h:1010
static __jo_force_inline jo_fixed __jo_sin_index(const unsigned int index)
Sinus of a table index (Internal usage).
Definition math.h:902
static __jo_force_inline void jo_vectorf_add(const jo_vectorf *const a, const jo_vectorf *const b, jo_vectorf *const result)
Add 2 vectors (using floating numbers).
Definition math.h:1445
unsigned int jo_sqrt(unsigned int value)
Fast square root.
jo_angle jo_atan2_fixed(const jo_fixed y, const jo_fixed x)
ATAN2 as a jo_angle without floating point (fixed numbers).
static __jo_force_inline jo_fixed jo_fixed_div_result(void)
Get the result of the division started by jo_fixed_div_start().
Definition math.h:671
static __jo_force_inline void jo_matrixf_look_at(const jo_vectorf *const from, const jo_vectorf *const to, const jo_vectorf *const up, jo_matrixf *const result)
Builds a transformation matrix for a camera (using floating numbers).
Definition math.h:2001
static __jo_force_inline void jo_matrixf_translation(const jo_vectorf *const offset, jo_matrixf *const result)
Creates translation matrix (using floating numbers).
Definition math.h:1680
static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
Fast cosinus multiplication.
Definition math.h:1133
void jo_vectorf_compute_bezier_point(const float t, jo_vectorf p0, jo_vectorf p1, jo_vectorf p2, jo_vectorf p3, jo_vectorf *result)
Compute cubic bezier curve point for vectors (using floating numbers).
float jo_rsqrt(float value)
Fast Reciprocal Square root using floating number.
static __jo_force_inline void jo_matrixf_perspective(const float vertical_field_of_view_in_deg, const float aspect_ratio, const float near_view_distance, const float far_view_distance, jo_matrixf *const result)
Creates a perspective projection matrix for a camera (using floating numbers).
Definition math.h:1983
#define JO_FIXED_PI_DIV_180
Fixed value of PI/180.
Definition math.h:442
static __jo_force_inline jo_fixed __jo_fixed_dot4(const jo_fixed ptA[4], const jo_fixed ptB[4])
Dot product of 2 vectors of 4 fixed numbers (Internal usage).
Definition math.h:1860
static __jo_force_inline float jo_vectorf_angle_between_radf(const jo_vectorf *const a, const jo_vectorf *const b)
Get the angle between 2 vectors (using floating numbers).
Definition math.h:1618
static __jo_force_inline float jo_sin_radf(const float rad)
Sinus computation.
Definition math.h:1020
static __jo_force_inline void jo_matrixf_rotation_y_rad(const float angle_in_rad, jo_matrixf *const result)
Creates rotating matrix (Y axis) (using floating numbers).
Definition math.h:1755
#define JO_RAD_TO_DEG(A)
Convert radians to degrees.
Definition math.h:298
static __jo_force_inline void jo_matrixf_ortho(const float left, const float right, const float bottom, const float top, const float back, const float front, jo_matrixf *const result)
Creates an orthographic projection matrix (using floating numbers).
Definition math.h:1963
static __jo_force_inline float jo_sinf(const int deg)
Sinus computation.
Definition math.h:1000
static __jo_force_inline void jo_vectorf_proj(const jo_vectorf *const v, const jo_vectorf *const onto, jo_vectorf *const result)
Compute projection vector (using floating numbers).
Definition math.h:1595
int jo_random(int max)
Get a random number.
static __jo_force_inline void jo_vectorf_cross(const jo_vectorf *const a, const jo_vectorf *const b, jo_vectorf *const result)
Cross 2 vectors (using floating numbers).
Definition math.h:1606
static __jo_force_inline int jo_atan2f(const float y, const float x)
Fast ATAN2 computation in degree.
Definition math.h:1238
static __jo_force_inline void jo_matrix_mul_vector4(const jo_matrix *const m, const jo_vector4_fixed *const v, jo_vector4_fixed *const result)
Multiply a matrix by a vector4 (using fixed numbers).
Definition math.h:1846
static __jo_force_inline jo_fixed jo_fixed_floor(const jo_fixed x)
Returns the largest (fixed) integer value less than or equal to x.
Definition math.h:707
static __jo_force_inline void jo_matrix_translation(const jo_vector_fixed *const offset, jo_matrix *const result)
Creates translation matrix (using fixed numbers).
Definition math.h:1668
static __jo_force_inline jo_fixed jo_fixed_dot(const jo_fixed ptA[3], const jo_fixed ptB[3])
Dot product two fixed 3D points.
Definition math.h:576
int jo_gcd(int a, int b)
Get the greatest common divisor.
static __jo_force_inline unsigned int jo_highest_bit(unsigned int x)
Index of the highest bit set in a value (31 - number of leading zeros).
Definition math.h:758
static __jo_force_inline void jo_sincos(const int deg, jo_fixed *const sin_value, jo_fixed *const cos_value)
Sinus and cosinus of the same angle in degree (table lookup, fast).
Definition math.h:1082
static __jo_force_inline void jo_sincos_angle(const jo_angle angle, jo_fixed *const sin_value, jo_fixed *const cos_value)
Sinus and cosinus of the same angle (table lookup, fast).
Definition math.h:947
static __jo_force_inline void jo_matrixf_scaling(const jo_vectorf *const scale, jo_matrixf *const result)
Creates scaling matrix (using floating numbers).
Definition math.h:1704
const jo_fixed __jo_sin_table[1025]
Sinus table: sin(x) for x in [0, pi/2] (1024 steps, Q16.16) (Internal usage, see math....
static __jo_force_inline jo_fixed jo_cos_angle(const jo_angle angle)
Cosinus of an angle (table lookup, fast).
Definition math.h:936
static __jo_force_inline int jo_turn_toward(const int angle, const int target, const int max_step)
Turn an angle toward another angle, by the shortest way.
Definition math.h:1280
static __jo_force_inline int jo_fixed_mult_to_int(const jo_fixed x, const jo_fixed y)
Multiply to fixed number and keep the integer part: jo_fixed2int(jo_fixed_mult(x, y)),...
Definition math.h:557
static __jo_force_inline jo_angle jo_atan2_angle(const float y, const float x)
ATAN2 as a jo_angle (65536 per turn, like jo_sin_angle() and the rotations of the 3D).
Definition math.h:1249
#define JO_SQUARE(A)
Square computation (x²).
Definition math.h:335
static __jo_force_inline float jo_tan_radf(const float rad)
Tangent computation.
Definition math.h:1190
static __jo_force_inline jo_fixed jo_sin_angle(const jo_angle angle)
Sinus of an angle (table lookup, fast).
Definition math.h:927
static __jo_force_inline jo_fixed jo_tan(const int deg)
Fast tangent computation.
Definition math.h:1152
static __jo_force_inline void jo_vector4_fixed_sub(const jo_vector4_fixed *const a, const jo_vector4_fixed *const b, jo_vector4_fixed *const result)
Substract 2 vectors4 (using fixed numbers).
Definition math.h:1376
static __jo_force_inline void jo_matrixf_rotation(const float angle_in_rad, const jo_vectorf *const axis, jo_matrixf *const result)
Creates a matrix to rotate around an axis by a given angle in radiant (using floating numbers).
Definition math.h:1934
static __jo_force_inline void jo_vector4_fixed_add(const jo_vector4_fixed *const a, const jo_vector4_fixed *const b, jo_vector4_fixed *const result)
Add 2 vectors4 (using fixed numbers).
Definition math.h:1362
static __jo_force_inline jo_angle jo_fixed_deg2ANGLE(const jo_fixed deg)
Convert fixed degree to jo_angle.
Definition math.h:960
#define JO_SWAP(A, B)
Swap A and B values.
Definition math.h:315
#define JO_FIXED_TO_INT(X)
Convert jo_fixed to int.
Definition math.h:459
static __jo_force_inline bool jo_square_intersect(const int x1, const int y1, const int w1, const int h1, const int x2, const int y2, const int w2, const int h2)
Fast method to get if two square intersects (HitBox processing).
Definition math.h:2161
int jo_random_seed
Get or set current random seed.
static __jo_force_inline float jo_fixed2float(const jo_fixed x)
Convert jo engine fixed to float.
Definition math.h:506
static __jo_force_inline float jo_acos_radf(const float angle)
Fast Arc Cosinus computation (linear approximation).
Definition math.h:1209
static __jo_force_inline void jo_vectorf_mul(const jo_vectorf *const a, const jo_vectorf *const b, jo_vectorf *const result)
Multiply 2 vectors (using floating numbers).
Definition math.h:1497
static __jo_force_inline void jo_vector_fixed_add(const jo_vector_fixed *const a, const jo_vector_fixed *const b, jo_vector_fixed *const result)
Add 2 vectors (using fixed numbers).
Definition math.h:1336
static __jo_force_inline int jo_shift_right8_small(const int x)
Arithmetic right shift by 8 bits (x >> 8) of a value in [-2^23, 2^23) (a 16 bits value x 0 to 256 for...
Definition math.h:649
static __jo_force_inline jo_fixed jo_lerp(const jo_fixed v0, const jo_fixed v1, const jo_fixed t)
Linear interpolation which guarantees v = v1 when t = 1.
Definition math.h:2136
static __jo_force_inline void jo_vector_fixed_muls(const jo_vector_fixed *const a, const jo_fixed s, jo_vector_fixed *const result)
Multiply value to vector (using fixed numbers).
Definition math.h:1349
#define JO_FLOAT_EPSILON
Float minimum positive value.
Definition math.h:282
static __jo_force_inline int jo_shift_right8(const int x)
Arithmetic right shift by 8 bits (x >> 8, rounded toward minus infinity) of any value.
Definition math.h:638
static __jo_force_inline void jo_vectorf_adds(const jo_vectorf *const a, const float s, jo_vectorf *const result)
Add value to vector (using floating numbers).
Definition math.h:1458
static __jo_force_inline void jo_vectorf_subs(const jo_vectorf *const a, const float s, jo_vectorf *const result)
Subtract value to vector (using floating numbers).
Definition math.h:1484
static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
Fast sinus multiplication.
Definition math.h:1041
static __jo_force_inline short jo_direction_to_angle(const jo_8_directions direction)
Convert jo_8_directions to angle in degree.
Definition math.h:2188
jo_fixed jo_fixed_rsqrt(jo_fixed value)
Fast Reciprocal Square root using fixed number.
static __jo_force_inline float jo_cos_radf(const float rad)
Cosinus computation.
Definition math.h:1112
jo_fixed jo_fixed_pow(jo_fixed x, jo_fixed y)
x raised to the power of the integer part of y
static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
Tangent computation.
Definition math.h:1176
static __jo_force_inline jo_fixed jo_fixed_rad2deg(const jo_fixed rad)
Convert fixed radian to fixed degree.
Definition math.h:689
#define JO_FABS(X)
Get the absolute value of X.
Definition math.h:262
static __jo_force_inline jo_fixed jo_float2fixed(const float x)
Convert float to jo engine fixed (avoid usage of GCC Soft Float).
Definition math.h:497
static __jo_force_inline int jo_random_using_multiple(int max, int multiple)
Get a random number with a specific multiple.
Definition math.h:739
static __jo_force_inline void jo_vector4_swap(jo_vector4_fixed *const a, jo_vector4_fixed *const b)
Swap 2 vectors4 (using fixed numbers).
Definition math.h:1412
static __jo_force_inline int jo_fixed2int(const jo_fixed x)
Convert jo engine fixed to int.
Definition math.h:488
static __jo_force_inline void jo_matrixf_mul_dir(const jo_matrixf *const matrix, const jo_vectorf *const direction, jo_vectorf *const result)
Multiplies a 4x4 matrix with a 3D vector representing a direction in 3D space (using floating numbers...
Definition math.h:2103
static __jo_force_inline void jo_vectorf_divs(const jo_vectorf *const a, const float s, jo_vectorf *const result)
Divide value to vector (using floating numbers).
Definition math.h:1536
jo_fixed jo_fixed_sqrt(jo_fixed value)
Fast Square root using fixed number.
#define JO_ABS(X)
Get the absolute value of X.
Definition math.h:257
static __jo_force_inline float jo_cosf(const int deg)
Cosinus computation.
Definition math.h:1092
#define JO_FIXED_360
Fixed floating point value for 360.
Definition math.h:425
static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
Cosinus computation.
Definition math.h:1102
static __jo_force_inline void jo_matrixf_mul_pos(const jo_matrixf *const matrix, const jo_vectorf *const position, jo_vectorf *const result)
Multiplies a 4x4 matrix with a 3D vector representing a point in 3D space (using floating numbers).
Definition math.h:2081
static __jo_force_inline void jo_matrix_scaling(const jo_vector_fixed *const scale, jo_matrix *const result)
Creates scaling matrix (using fixed numbers).
Definition math.h:1692
static __jo_force_inline jo_fixed jo_fixed_wrap_to_180(jo_fixed deg)
Wrap deg in [-180 180].
Definition math.h:526
static __jo_force_inline float jo_vectorf_dot(const jo_vectorf *const a, const jo_vectorf *const b)
Get the dot product of 2 vectors (using floating numbers).
Definition math.h:1561
static __jo_force_inline void jo_matrix_transpose(const jo_matrix *const matrix, jo_matrix *const result)
Creates transpose matrix (using fixed numbers).
Definition math.h:1795
static __jo_force_inline void jo_fixed_div_start(const jo_fixed dividend, const jo_fixed divisor)
Start a fixed-point division in the background (see jo_fixed_div_result()).
Definition math.h:660
static __jo_force_inline jo_fixed jo_fixed_cos(const jo_fixed rad)
Fast cosinus computation using fixed number.
Definition math.h:1061
int jo_atan2_degrees(const jo_fixed y, const jo_fixed x)
ATAN2 in degree without floating point (fixed numbers).
static __jo_force_inline void jo_vectorf_muls(const jo_vectorf *const a, const float s, jo_vectorf *const result)
Multiply value to vector (using floating numbers).
Definition math.h:1510
#define JO_INT_TO_FIXED(X)
Convert int to jo_fixed.
Definition math.h:455
static __jo_force_inline jo_fixed jo_fixed_sin(const jo_fixed rad)
Fast sinus computation using fixed number.
Definition math.h:980
static __jo_force_inline void jo_vectorf_div(const jo_vectorf *const a, const jo_vectorf *const b, jo_vectorf *const result)
Divide 2 vectors (using floating numbers).
Definition math.h:1523
static __jo_force_inline jo_fixed jo_fixed_mult(const jo_fixed x, const jo_fixed y)
Multiply to fixed number.
Definition math.h:546
#define JO_FIXED_180
Fixed floating point value for 180.
Definition math.h:423
static __jo_force_inline void jo_matrixf_mul(const jo_matrixf *const a, const jo_matrixf *const b, jo_matrixf *const result)
Multiply 2 matrix (using floating numbers).
Definition math.h:1910
static __jo_force_inline float jo_vectorf_length(const jo_vectorf *const a)
Get the length of a vector (using floating numbers).
Definition math.h:1551
static __jo_force_inline int jo_int_div(const int dividend, const int divisor)
Divide 2 integers (dividend / divisor, rounded toward 0 as in C).
Definition math.h:623
static __jo_force_inline void jo_matrixf_rotation_x_rad(const float angle_in_rad, jo_matrixf *const result)
Creates rotating matrix (X axis) (using floating numbers).
Definition math.h:1729
#define JO_FIXED_180_DIV_PI
Fixed value of 180/PI.
Definition math.h:440
static __jo_force_inline void jo_matrixf_identity(jo_matrixf *const result)
Creates the identity matrix (using floating numbers).
Definition math.h:1652
static __jo_force_inline unsigned int __jo_angle_to_sin_index(const jo_angle angle)
Table index of an angle (Internal usage).
Definition math.h:917
static __jo_force_inline jo_fixed jo_vector4_fixed_dot(const jo_vector4_fixed *const a, const jo_vector4_fixed *const b)
Dot product of 2 vectors4 (using fixed numbers).
Definition math.h:1402
static __jo_force_inline jo_angle jo_fixed_rad2ANGLE(const jo_fixed rad)
Convert fixed radian to jo_angle.
Definition math.h:888
#define JO_FIXED_PI
Fixed value of PI.
Definition math.h:436
static __jo_force_inline jo_fixed jo_fixed_ceil(const jo_fixed x)
Returns the smallest (fixed) integer value greater than or equal to x.
Definition math.h:698
static __jo_force_inline jo_fixed jo_fixed_deg2rad(const jo_fixed deg)
Convert fixed degree to fixed radian.
Definition math.h:680
static __jo_force_inline void jo_vectorf_normalize(const jo_vectorf *const a, jo_vectorf *const result)
Normalize a vector (using floating numbers).
Definition math.h:1571
float jo_atan2f_rad(const float y, const float x)
Fast ATAN2 computation in radian.
static __jo_force_inline jo_fixed jo_fixed_wrap_to_pi(jo_fixed rad)
Wrap rad in [−pi pi].
Definition math.h:515
static __jo_force_inline bool jo_is_float_equals_zero(const float f)
Check if float almost equals 0.
Definition math.h:2145
#define JO_FIXED_PI_2
Fixed value of 2 PI.
Definition math.h:438
static __jo_force_inline void jo_vectorf_sub(const jo_vectorf *const a, const jo_vectorf *const b, jo_vectorf *const result)
Subtract 2 vectors (using floating numbers).
Definition math.h:1471
static __jo_force_inline jo_fixed jo_sin(const int deg)
Fast sinus computation.
Definition math.h:989
static __jo_force_inline int jo_cos_mult(const int value, const int deg)
Fast cosinus multiplication.
Definition math.h:1123
static __jo_force_inline jo_fixed jo_cos(const int deg)
Fast cosinus computation.
Definition math.h:1070
static __jo_force_inline void jo_matrixf_invert_affine(const jo_matrixf *const matrix, jo_matrixf *const result)
Inverts an affine transformation matrix (using floating numbers).
Definition math.h:2035
static __jo_force_inline void jo_matrix_rotation_x_rad(const float angle_in_rad, jo_matrix *const result)
Creates rotating matrix (X axis) (using fixed numbers).
Definition math.h:1716
static __jo_force_inline int jo_sin_mult(const int value, const int deg)
Fast sinus multiplication.
Definition math.h:1031
#define JO_FIXED_1_DIV
Fixed value of 1/65536.
Definition math.h:450
static __jo_force_inline float jo_sqrtf(float value)
Fast Square root using floating number.
Definition math.h:807
static __jo_force_inline void jo_matrix_identity(jo_matrix *const result)
Creates the identity matrix (using fixed numbers).
Definition math.h:1637
#define JO_FIXED_1
Fixed floating point value for 1.
Definition math.h:405
static __jo_force_inline float jo_tanf(const float deg)
Tangent computation.
Definition math.h:1166
static __jo_force_inline jo_fixed jo_fixed_div(const jo_fixed dividend, const jo_fixed divisor)
Divide fixed-point numbers (expresses dividend / divisor).
Definition math.h:605
#define JO_ZERO(X)
Set a variable to zero.
Definition math.h:240
#define JO_SH2_DVDNTL
Division unit: dividend register low (64 bits division, writing starts the division,...
Definition sega_saturn.h:587
#define JO_SH2_DVDNT
Division unit: dividend register (32 bits division).
Definition sega_saturn.h:583
#define JO_SH2_DVSR
Division unit: divisor register.
Definition sega_saturn.h:581
#define JO_SH2_DVDNTH
Division unit: dividend register high (64 bits division).
Definition sega_saturn.h:585
float y
Definition types.h:139
jo_fixed w
Definition types.h:172
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
short jo_angle
Angle.
Definition types.h:54
float x
Definition types.h:138
float z
Definition types.h:140
int jo_fixed
Fixed point Q16.16 number.
Definition types.h:48
jo_8_directions
8 directions definition
Definition types.h:308
@ DOWN_LEFT
Definition types.h:316
@ DOWN_RIGHT
Definition types.h:317
@ UP_RIGHT
Definition types.h:315
@ DOWN
Definition types.h:313
@ UP_LEFT
Definition types.h:314
@ UP
Definition types.h:312
@ LEFT
Definition types.h:310
@ RIGHT
Definition types.h:311
2D position
Definition types.h:58
Vector4 for 3D computation using fixed number.
Definition types.h:170
Vector for 3D computation using fixed number.
Definition types.h:155
Vector for 3D computation using floating numbers.
Definition types.h:137
4x4 MATRIX for 3D computation using fixed number
Definition types.h:191
jo_fixed table[16]
Definition types.h:193
jo_fixed m[4][4]
Definition types.h:192
4x4 MATRIX for 3D computation using floating numbers
Definition types.h:177
float table[16]
Definition types.h:179
float m[4][4]
Definition types.h:178