Jo Engine  2024.04.28
Jo Sega Saturn Engine
math.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2024, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
35 #ifndef __JO_MATH_H__
36 # define __JO_MATH_H__
37 
38 /*
39 ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██████╗ ██████╗ ███╗ ██╗███████╗████████╗███████╗
40 ████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██╔════╝██╔═══██╗████╗ ██║██╔════╝╚══██╔══╝██╔════╝
41 ██╔████╔██║███████║ ██║ ███████║ ██║ ██║ ██║██╔██╗ ██║███████╗ ██║ ███████╗
42 ██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██║╚██╗██║╚════██║ ██║ ╚════██║
43 ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚██████╗╚██████╔╝██║ ╚████║███████║ ██║ ███████║
44 ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══════╝
45 */
46 
48 # define JO_PI (3.1415927)
49 
51 # define JO_PI_2 (1.5707963)
52 
53 /*
54 ███╗ ███╗██╗ ██╗██╗ ████████╗ ██╗██████╗ ██╗██╗ ██╗
55 ████╗ ████║██║ ██║██║ ╚══██╔══╝██╔╝██╔══██╗██║██║ ██║
56 ██╔████╔██║██║ ██║██║ ██║ ██╔╝ ██║ ██║██║██║ ██║
57 ██║╚██╔╝██║██║ ██║██║ ██║ ██╔╝ ██║ ██║██║╚██╗ ██╔╝
58 ██║ ╚═╝ ██║╚██████╔╝███████╗██║██╔╝ ██████╔╝██║ ╚████╔╝
59 ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝
60 */
61 
66 # define JO_MULT_BY_2(X) ((X) << 1)
67 
72 # define JO_MULT_BY_4(X) ((X) << 2)
73 
78 # define JO_MULT_BY_8(X) ((X) << 3)
79 
84 # define JO_MULT_BY_16(X) ((X) << 4)
85 
90 # define JO_MULT_BY_32(X) ((X) << 5)
91 
96 # define JO_MULT_BY_64(X) ((X) << 6)
97 
102 # define JO_MULT_BY_128(X) ((X) << 7)
103 
108 # define JO_MULT_BY_256(X) ((X) << 8)
109 
114 # define JO_MULT_BY_1024(X) ((X) << 10)
115 
120 # define JO_MULT_BY_2048(X) ((X) << 11)
121 
126 # define JO_MULT_BY_4096(X) ((X) << 12)
127 
132 # define JO_MULT_BY_32768(X) ((X) << 15)
133 
138 # define JO_MULT_BY_65536(X) ((X) << 16)
139 
144 # define JO_DIV_BY_2(X) ((X) >> 1)
145 
150 # define JO_DIV_BY_4(X) ((X) >> 2)
151 
156 # define JO_DIV_BY_8(X) ((X) >> 3)
157 
162 # define JO_DIV_BY_16(X) ((X) >> 4)
163 
168 # define JO_DIV_BY_32(X) ((X) >> 5)
169 
174 # define JO_DIV_BY_64(X) ((X) >> 6)
175 
180 # define JO_DIV_BY_1024(X) ((X) >> 10)
181 
186 # define JO_DIV_BY_32768(X) ((X) >> 15)
187 
192 # define JO_DIV_BY_65536(X) ((X) >> 16)
193 
198 # define JO_DIV_BY_2147483648(X) ((X) >> 31)
199 
200 /*
201 ████████╗ ██████╗ ██████╗ ██╗ ███████╗
202 ╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔════╝
203  ██║ ██║ ██║██║ ██║██║ ███████╗
204  ██║ ██║ ██║██║ ██║██║ ╚════██║
205  ██║ ╚██████╔╝╚██████╔╝███████╗███████║
206  ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
207 */
208 
213 # define JO_ZERO(X) X ^= X
214 
220 # define JO_MOD_POW2(N, M) ((N) & ((M) - 1))
221 
225 # define JO_ABS(X) ((X) < 0 ? -(X) : (X))
226 
230 # define JO_FABS(X) ((X) < 0.0f ? -(X) : (X))
231 
236 # define JO_MIN(A, B) (((A) < (B)) ? (A) : (B))
237 
242 # define JO_MAX(A, B) (((A) > (B)) ? (A) : (B))
243 
247 # define JO_CHANGE_SIGN(X) (-(X))
248 
250 # define JO_FLOAT_EPSILON (0.00001f)
251 
256 # define JO_FLOAT_NEARLY_EQUALS(A, B) ((A) <= ((B) + JO_FLOAT_EPSILON) && (A) >= ((B) - JO_FLOAT_EPSILON))
257 
261 # define JO_IS_FLOAT_NULL(A) ((A) <= JO_FLOAT_EPSILON && (A) >= (-JO_FLOAT_EPSILON))
262 
266 # define JO_RAD_TO_DEG(A) (180.0 * (A) / JO_PI)
267 
271 # define JO_DEG_TO_RAD(A) (JO_PI * (A) / 180.0)
272 
276 # define JO_IS_ODD(A) ((A) & 1)
277 
282 # define JO_SWAP(A, B) { (A) = (A) ^ (B); (B) = (A) ^ (B); (A) = (A) ^ (B); }
283 
288 # define JO_PERCENT_USED(TOTAL, FREE) (int)(100.0f / (float)(TOTAL) * (float)((TOTAL) - (FREE)))
289 
293 # define JO_SQUARE(A) ((A) * (A))
294 
298 # define JO_BCD_INT(BCD) (((BCD & 0xF0) >> 4) * 10 + (BCD & 0x0F))
299 
300 /*
301 ██████╗ ██╗ ██╗████████╗███████╗███████╗██╗███████╗██╗ ██████╗
302 ██╔══██╗╚██╗ ██╔╝╚══██╔══╝██╔════╝██╔════╝██║██╔════╝██║ ██╔══██╗
303 ██████╔╝ ╚████╔╝ ██║ █████╗ █████╗ ██║█████╗ ██║ ██║ ██║
304 ██╔══██╗ ╚██╔╝ ██║ ██╔══╝ ██╔══╝ ██║██╔══╝ ██║ ██║ ██║
305 ██████╔╝ ██║ ██║ ███████╗██║ ██║███████╗███████╗██████╔╝
306 ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
307 */
308 
313 # define JO_SET_FLAGS(BYTEFIELD, FLAGS) BYTEFIELD = (FLAGS)
314 
318 # define JO_SET_ALL_FLAGS(BYTEFIELD) BYTEFIELD = (~0)
319 
324 # define JO_ADD_FLAG(BYTEFIELD, FLAG) BYTEFIELD |= (FLAG)
325 
330 # define JO_REMOVE_FLAG(BYTEFIELD, FLAG) BYTEFIELD &= ~(FLAG)
331 
335 # define JO_REMOVE_ALL_FLAGS(BYTEFIELD) BYTEFIELD = 0
336 
341 # define JO_HAS_FLAG(BYTEFIELD, FLAG) ((BYTEFIELD & FLAG) == FLAG)
342 
343 /*
344 ███████╗██╗██╗ ██╗███████╗██████╗ ██████╗ ██████╗ ███╗ ██╗██╗ ██╗███████╗██████╗ ████████╗██╗ ██████╗ ███╗ ██╗
345 ██╔════╝██║╚██╗██╔╝██╔════╝██╔══██╗ ██╔════╝██╔═══██╗████╗ ██║██║ ██║██╔════╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║
346 █████╗ ██║ ╚███╔╝ █████╗ ██║ ██║ ██║ ██║ ██║██╔██╗ ██║██║ ██║█████╗ ██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║
347 ██╔══╝ ██║ ██╔██╗ ██╔══╝ ██║ ██║ ██║ ██║ ██║██║╚██╗██║╚██╗ ██╔╝██╔══╝ ██╔══██╗ ██║ ██║██║ ██║██║╚██╗██║
348 ██║ ██║██╔╝ ██╗███████╗██████╔╝ ╚██████╗╚██████╔╝██║ ╚████║ ╚████╔╝ ███████╗██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
349 ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
350 
351  ▲ NOTE ABOUT FIXED NUMBER ▲
352  Only values between -32767.99998 and 32767.99998 can be converted to fixed number.
353 
354 */
355 
357 # define JO_FIXED_0 (0)
358 
359 # define JO_FIXED_1_DIV_2 (32768)
360 
361 # define JO_FIXED_1 (65536)
362 
363 # define JO_FIXED_2 JO_INT_TO_FIXED(2)
364 
365 # define JO_FIXED_4 JO_INT_TO_FIXED(4)
366 
367 # define JO_FIXED_8 JO_INT_TO_FIXED(8)
368 
369 # define JO_FIXED_16 JO_INT_TO_FIXED(16)
370 
371 # define JO_FIXED_32 JO_INT_TO_FIXED(32)
372 
373 # define JO_FIXED_120 JO_INT_TO_FIXED(120)
374 
375 # define JO_FIXED_150 JO_INT_TO_FIXED(150)
376 
377 # define JO_FIXED_180 JO_INT_TO_FIXED(180)
378 
379 # define JO_FIXED_360 JO_INT_TO_FIXED(360)
380 
382 # define JO_FIXED_MIN (-2147483647)
383 
384 # define JO_FIXED_MAX (2147483647)
385 
386 # define JO_FIXED_EPSILON (1)
387 
388 # define JO_FIXED_OVERFLOW (0x80000000)
389 
390 # define JO_FIXED_PI (205887)
391 
392 # define JO_FIXED_PI_2 (411775)
393 
394 # define JO_FIXED_180_DIV_PI (3754936)
395 
396 # define JO_FIXED_PI_DIV_180 (1144)
397 
398 # define JO_FIXED_PI_DIV_2 (102944)
399 
400 # define JO_FIXED_1_DIV (1.0f / 65536.0f)
401 
405 # define JO_INT_TO_FIXED(X) JO_MULT_BY_65536(X)
406 
409 # define JO_FIXED_TO_INT(X) JO_DIV_BY_65536(X)
410 
416 {
417  return JO_INT_TO_FIXED(x);
418 }
419 
425 {
426  return JO_FIXED_TO_INT(x);
427 }
428 
434 {
435  return ((jo_fixed)(x * (float)JO_FIXED_1));
436 }
437 
443 {
444  return ((float)x * JO_FIXED_1_DIV);
445 }
446 
452 {
453  while (rad > JO_FIXED_PI) rad -= JO_FIXED_PI_2;
454  while (rad <= -JO_FIXED_PI) rad += JO_FIXED_PI_2;
455  return (rad);
456 }
457 
463 {
464  while (deg > JO_FIXED_180) deg -= JO_FIXED_360;
465  while (deg <= -JO_FIXED_PI) deg += JO_FIXED_360;
466  return (deg);
467 }
468 
475 
482 
490 
498 
504 {
506 }
507 
513 {
515 }
516 
522 {
523  return (x & 0xFFFF0000UL) + (x & 0x0000FFFFUL ? JO_FIXED_1 : 0);
524 }
525 
531 {
532  return (x & 0xFFFF0000ul);
533 }
534 
535 /*
536 ██████╗ █████╗ ███╗ ██╗██████╗ ██████╗ ███╗ ███╗
537 ██╔══██╗██╔══██╗████╗ ██║██╔══██╗██╔═══██╗████╗ ████║
538 ██████╔╝███████║██╔██╗ ██║██║ ██║██║ ██║██╔████╔██║
539 ██╔══██╗██╔══██║██║╚██╗██║██║ ██║██║ ██║██║╚██╔╝██║
540 ██║ ██║██║ ██║██║ ╚████║██████╔╝╚██████╔╝██║ ╚═╝ ██║
541 ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
542 */
543 
546 extern int jo_random_seed;
547 
552 int jo_random(int max);
553 
559 static __jo_force_inline int jo_random_using_multiple(int max, int multiple)
560 {
561  return (jo_random(max) / multiple) * multiple;
562 }
563 
564 /*
565 ███████╗ ██████╗ ██████╗ ████████╗
566 ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝
567 ███████╗██║ ██║██████╔╝ ██║
568 ╚════██║██║▄▄ ██║██╔══██╗ ██║
569 ███████║╚██████╔╝██║ ██║ ██║
570 ╚══════╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═╝
571 */
572 
578 
583 unsigned int jo_sqrt(unsigned int value);
584 
590 static __jo_force_inline float jo_sqrtf(float value)
591 {
592  unsigned int i = *(unsigned int*)(void *)&value;
593  i += 127 << 23;
594  i >>= 1;
595  return *(float*)(void *)&i;
596 }
597 
598 /*
599 ██╗███╗ ██╗██╗ ██╗███████╗██████╗ ███████╗███████╗ ███████╗ ██████╗ ██████╗ ████████╗
600 ██║████╗ ██║██║ ██║██╔════╝██╔══██╗██╔════╝██╔════╝ ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝
601 ██║██╔██╗ ██║██║ ██║█████╗ ██████╔╝███████╗█████╗ ███████╗██║ ██║██████╔╝ ██║
602 ██║██║╚██╗██║╚██╗ ██╔╝██╔══╝ ██╔══██╗╚════██║██╔══╝ ╚════██║██║▄▄ ██║██╔══██╗ ██║
603 ██║██║ ╚████║ ╚████╔╝ ███████╗██║ ██║███████║███████╗ ███████║╚██████╔╝██║ ██║ ██║
604 ╚═╝╚═╝ ╚═══╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚══════╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═╝
605 AKA RECIPROCAL SQUARE ROOT
606 */
607 
613 
618 float jo_rsqrt(float value);
619 
620 /*
621 ███████╗ ██████╗ ██╗ ██╗███╗ ██╗████████╗███████╗██████╗ ██████╗ ██████╗
622 ██╔════╝██╔════╝ ██║ ██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗██╔═══██╗██╔══██╗
623 ███████╗██║ ███╗██║ ██║██╔██╗ ██║ ██║ █████╗ ██████╔╝██║ ██║██████╔╝
624 ╚════██║██║ ██║██║ ██║██║╚██╗██║ ██║ ██╔══╝ ██╔══██╗██║ ██║██╔═══╝
625 ███████║╚██████╔╝███████╗ ██║██║ ╚████║ ██║ ███████╗██║ ██║╚██████╔╝██║
626 ╚══════╝ ╚═════╝ ╚══════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝
627 
628 */
629 
631 # define __JO_DEG_TO_ANGLE_MAGIC (182)
632 
637 static __jo_force_inline ANGLE jo_DEGtoANG(const float deg)
638 {
639 #ifdef JO_COMPILE_WITH_FAST_BUT_LESS_ACCURATE_MATH
640  return ((ANGLE)(__JO_DEG_TO_ANGLE_MAGIC * (deg)));
641 #else
642  return ((ANGLE)((65536.0 * (deg)) / 360.0));
643 #endif
644 }
645 
650 static __jo_force_inline ANGLE jo_DEGtoANG_int(const int deg)
651 {
652 #ifdef JO_COMPILE_WITH_FAST_BUT_LESS_ACCURATE_MATH
653  return ((ANGLE)(__JO_DEG_TO_ANGLE_MAGIC * (deg)));
654 #else
655  return ((ANGLE)(JO_MULT_BY_65536(deg) / 360.0));
656 #endif
657 }
658 
659 #if JO_COMPILE_USING_SGL
660 
666 {
667  return (RADtoANG(jo_fixed2float(rad)));
668 }
669 
670 #endif
671 
677 {
678  return (jo_DEGtoANG(jo_fixed2float(deg)));
679 }
680 
681 /*
682 ███████╗██╗███╗ ██╗██╗ ██╗███████╗
683 ██╔════╝██║████╗ ██║██║ ██║██╔════╝
684 ███████╗██║██╔██╗ ██║██║ ██║███████╗
685 ╚════██║██║██║╚██╗██║██║ ██║╚════██║
686 ███████║██║██║ ╚████║╚██████╔╝███████║
687 ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
688 */
689 
695 
700 static __jo_force_inline jo_fixed jo_sin(const int deg)
701 {
703 }
704 
710 static __jo_force_inline float jo_sinf(const int deg)
711 {
712  return (jo_fixed2float(jo_sin(deg)));
713 }
714 
720 static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
721 {
722  return (jo_fixed_sin(jo_float2fixed(rad)));
723 }
724 
730 static __jo_force_inline float jo_sin_radf(const float rad)
731 {
733 }
734 
740 static __jo_force_inline int jo_sin_mult(const int value, const int deg)
741 {
742  return (jo_fixed2int(value * jo_sin(deg)));
743 }
744 
750 static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
751 {
752  return (value * jo_sinf(deg));
753 }
754 
755 /*
756  ██████╗ ██████╗ ███████╗██╗███╗ ██╗██╗ ██╗███████╗
757 ██╔════╝██╔═══██╗██╔════╝██║████╗ ██║██║ ██║██╔════╝
758 ██║ ██║ ██║███████╗██║██╔██╗ ██║██║ ██║███████╗
759 ██║ ██║ ██║╚════██║██║██║╚██╗██║██║ ██║╚════██║
760 ╚██████╗╚██████╔╝███████║██║██║ ╚████║╚██████╔╝███████║
761  ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
762 
763 */
764 
770 
775 static __jo_force_inline jo_fixed jo_cos(const int deg)
776 {
778 }
779 
785 static __jo_force_inline float jo_cosf(const int deg)
786 {
787  return (jo_fixed2float(jo_cos(deg)));
788 }
789 
795 static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
796 {
797  return (jo_fixed_cos(jo_float2fixed(rad)));
798 }
799 
805 static __jo_force_inline float jo_cos_radf(const float rad)
806 {
808 }
809 
815 static __jo_force_inline int jo_cos_mult(const int value, const int deg)
816 {
817  return (jo_fixed2int(value * jo_cos(deg)));
818 }
819 
825 static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
826 {
827  return (value * jo_cosf(deg));
828 }
829 
830 /*
831 ████████╗ █████╗ ███╗ ██╗ ██████╗ ███████╗███╗ ██╗████████╗
832 ╚══██╔══╝██╔══██╗████╗ ██║██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝
833  ██║ ███████║██╔██╗ ██║██║ ███╗█████╗ ██╔██╗ ██║ ██║
834  ██║ ██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██║╚██╗██║ ██║
835  ██║ ██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ╚████║ ██║
836  ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
837 
838 */
839 
844 static __jo_force_inline jo_fixed jo_tan(const int deg)
845 {
846  return jo_fixed_div(jo_sin(deg), jo_cos(deg));
847 }
848 
854 static __jo_force_inline float jo_tanf(const float deg)
855 {
856  return (jo_sinf(deg) / jo_cosf(deg));
857 }
858 
864 static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
865 {
866  return jo_fixed_div(jo_sin_rad(rad), jo_cos_rad(rad));
867 }
868 
874 static __jo_force_inline float jo_tan_radf(const float rad)
875 {
876  return (jo_sin_radf(rad) / jo_cos_radf(rad));
877 }
878 
879 /*
880  █████╗ ██████╗ ██████╗ ███████╗
881 ██╔══██╗██╔════╝██╔═══██╗██╔════╝
882 ███████║██║ ██║ ██║███████╗
883 ██╔══██║██║ ██║ ██║╚════██║
884 ██║ ██║╚██████╗╚██████╔╝███████║
885 ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝
886 */
887 
892 static __jo_force_inline float jo_acos_radf(const float angle)
893 {
894  return (3.14159f - 1.57079f * angle);
895 }
896 
897 /*
898  █████╗ ████████╗ █████╗ ███╗ ██╗██████╗
899 ██╔══██╗╚══██╔══╝██╔══██╗████╗ ██║╚════██╗
900 ███████║ ██║ ███████║██╔██╗ ██║ █████╔╝
901 ██╔══██║ ██║ ██╔══██║██║╚██╗██║██╔═══╝
902 ██║ ██║ ██║ ██║ ██║██║ ╚████║███████╗
903 ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝
904 
905 */
906 
913 float jo_atan2f_rad(const float y, const float x);
914 
921 static __jo_force_inline int jo_atan2f(const float y, const float x)
922 {
923  return (int)JO_RAD_TO_DEG(jo_atan2f_rad(y, x));
924 }
925 
926 /*
927 ██╗ ██╗███████╗ ██████╗████████╗ ██████╗ ██████╗
928 ██║ ██║██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗
929 ██║ ██║█████╗ ██║ ██║ ██║ ██║██████╔╝
930 ╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║ ██║██╔══██╗
931  ╚████╔╝ ███████╗╚██████╗ ██║ ╚██████╔╝██║ ██║
932  ╚═══╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
933 */
934 
935 /*
936  _______ __ _ __ __
937  / ____(_) _____ ____/ / / | / /_ ______ ___ / /_ ___ _____
938  / /_ / / |/_/ _ \/ __ / / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
939  / __/ / /> </ __/ /_/ / / /| / /_/ / / / / / / /_/ / __/ /
940 /_/ /_/_/|_|\___/\__,_/ /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
941 
942 */
943 
953 
960 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)
961 {
962  result->x = a->x + b->x;
963  result->y = a->y + b->y;
964  result->z = a->z + b->z;
965 }
966 
973 static __jo_force_inline void jo_vector_fixed_muls(const jo_vector_fixed * const a, const jo_fixed s, jo_vector_fixed * const result)
974 {
975  result->x = jo_fixed_mult(a->x, s);
976  result->y = jo_fixed_mult(a->y, s);
977  result->z = jo_fixed_mult(a->z, s);
978 }
979 
986 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)
987 {
988  result->x = a->x + b->x;
989  result->y = a->y + b->y;
990  result->z = a->z + b->z;
991  result->w = JO_FIXED_1;
992 }
993 
1000 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)
1001 {
1002  result->x = a->x - b->x;
1003  result->y = a->y - b->y;
1004  result->z = a->z - b->z;
1005  result->w = JO_FIXED_1;
1006 }
1007 
1013 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)
1014 {
1015  result->x = jo_fixed_mult(a->y, b->z) - jo_fixed_mult(a->z, b->y);
1016  result->y = jo_fixed_mult(a->z, b->x) - jo_fixed_mult(a->x, b->z);
1017  result->z = jo_fixed_mult(a->x, b->y) - jo_fixed_mult(a->y, b->x);
1018  result->w = JO_FIXED_1;
1019 }
1020 
1027 {
1028  return (jo_fixed_mult(a->x, b->x) + jo_fixed_mult(a->y, b->y) + jo_fixed_mult(a->z, b->z));
1029 }
1030 
1037 {
1038  JO_SWAP(a->x, b->x);
1039  JO_SWAP(a->y, b->y);
1040  JO_SWAP(a->z, b->z);
1041  JO_SWAP(a->w, b->w);
1042 }
1043 
1044 /*
1045  ________ __ _ _ __ __
1046  / ____/ /___ ____ _/ /_(_)___ ____ _ / | / /_ ______ ___ / /_ ___ _____
1047  / /_ / / __ \/ __ `/ __/ / __ \/ __ `/ / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
1048  / __/ / / /_/ / /_/ / /_/ / / / / /_/ / / /| / /_/ / / / / / / /_/ / __/ /
1049 /_/ /_/\____/\__,_/\__/_/_/ /_/\__, / /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
1050  /____/
1051 */
1052 
1062 
1069 static __jo_force_inline void jo_vectorf_add(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1070 {
1071  result->x = a->x + b->x;
1072  result->y = a->y + b->y;
1073  result->z = a->z + b->z;
1074 }
1075 
1082 static __jo_force_inline void jo_vectorf_adds(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1083 {
1084  result->x = a->x + s;
1085  result->y = a->y + s;
1086  result->z = a->z + s;
1087 }
1088 
1095 static __jo_force_inline void jo_vectorf_sub(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1096 {
1097  result->x = a->x - b->x;
1098  result->y = a->y - b->y;
1099  result->z = a->z - b->z;
1100 }
1101 
1108 static __jo_force_inline void jo_vectorf_subs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1109 {
1110  result->x = a->x - s;
1111  result->y = a->y - s;
1112  result->z = a->z - s;
1113 }
1114 
1121 static __jo_force_inline void jo_vectorf_mul(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1122 {
1123  result->x = a->x * b->x;
1124  result->y = a->y * b->y;
1125  result->z = a->z * b->z;
1126 }
1127 
1134 static __jo_force_inline void jo_vectorf_muls(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1135 {
1136  result->x = a->x * s;
1137  result->y = a->y * s;
1138  result->z = a->z * s;
1139 }
1140 
1147 static __jo_force_inline void jo_vectorf_div(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1148 {
1149  result->x = a->x / b->x;
1150  result->y = a->y / b->y;
1151  result->z = a->z / b->z;
1152 }
1153 
1160 static __jo_force_inline void jo_vectorf_divs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1161 {
1162  result->x = a->x / s;
1163  result->y = a->y / s;
1164  result->z = a->z / s;
1165 }
1166 
1171 static __jo_force_inline float jo_vectorf_length(const jo_vectorf * const a)
1172 {
1173  return (jo_sqrtf(JO_SQUARE(a->x) + JO_SQUARE(a->y) + JO_SQUARE(a->z)));
1174 }
1175 
1181 static __jo_force_inline float jo_vectorf_dot(const jo_vectorf * const a, const jo_vectorf * const b)
1182 {
1183  return (a->x * b->x + a->y * b->y + a->z * b->z);
1184 }
1185 
1191 static __jo_force_inline void jo_vectorf_normalize(const jo_vectorf * const a, jo_vectorf * const result)
1192 {
1193  float len = jo_vectorf_length(a);
1194  if (len > 0)
1195  {
1196  result->x = a->x / len;
1197  result->y = a->y / len;
1198  result->z = a->z / len;
1199  }
1200  else
1201  {
1202  result->x = 0;
1203  result->y = 0;
1204  result->z = 0;
1205  }
1206 }
1207 
1213 static __jo_force_inline void jo_vectorf_proj(const jo_vectorf * const v, const jo_vectorf * const onto, jo_vectorf * const result)
1214 {
1215  jo_vectorf_muls(onto, jo_vectorf_dot(v, onto) / jo_vectorf_dot(onto, onto), result);
1216 }
1217 
1224 static __jo_force_inline void jo_vectorf_cross(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1225 {
1226  result->x = a->y * b->z - a->z * b->y;
1227  result->y = a->z * b->x - a->x * b->z;
1228  result->z = a->x * b->y - a->y * b->x;
1229 }
1230 
1236 static __jo_force_inline float jo_vectorf_angle_between_radf(const jo_vectorf * const a, const jo_vectorf * const b)
1237 {
1239 }
1240 
1241 /*
1242 ██╗ ██╗██╗ ██╗██╗ ██╗ ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
1243 ██║ ██║╚██╗██╔╝██║ ██║ ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
1244 ███████║ ╚███╔╝ ███████║ ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
1245 ╚════██║ ██╔██╗ ╚════██║ ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
1246  ██║██╔╝ ██╗ ██║ ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
1247  ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
1248 
1249 */
1250 
1255 {
1256  register int i;
1257 
1258  for (i = 1; i < 15; ++i)
1259  JO_ZERO(result->table[i]);
1260  result->m00 = JO_FIXED_1;
1261  result->m11 = JO_FIXED_1;
1262  result->m22 = JO_FIXED_1;
1263  result->m33 = JO_FIXED_1;
1264 }
1265 
1270 {
1271  register int i;
1272 
1273  for (i = 1; i < 15; ++i)
1274  result->table[i] = 0;
1275  result->m00 = 1;
1276  result->m11 = 1;
1277  result->m22 = 1;
1278  result->m33 = 1;
1279 }
1280 
1285 static __jo_force_inline void jo_matrix_translation(const jo_vector_fixed * const offset, jo_matrix * const result)
1286 {
1287  jo_matrix_identity(result);
1288  result->m30 = offset->x;
1289  result->m31 = offset->y;
1290  result->m32 = offset->z;
1291 }
1292 
1297 static __jo_force_inline void jo_matrixf_translation(const jo_vectorf * const offset, jo_matrixf * const result)
1298 {
1299  jo_matrixf_identity(result);
1300  result->m30 = offset->x;
1301  result->m31 = offset->y;
1302  result->m32 = offset->z;
1303 }
1304 
1309 static __jo_force_inline void jo_matrix_scaling(const jo_vector_fixed * const scale, jo_matrix * const result)
1310 {
1311  jo_matrix_identity(result);
1312  result->m00 = scale->x;
1313  result->m11 = scale->y;
1314  result->m22 = scale->z;
1315 }
1316 
1321 static __jo_force_inline void jo_matrixf_scaling(const jo_vectorf * const scale, jo_matrixf * const result)
1322 {
1323  jo_matrixf_identity(result);
1324  result->m00 = scale->x;
1325  result->m11 = scale->y;
1326  result->m22 = scale->z;
1327 }
1328 
1333 static __jo_force_inline void jo_matrix_rotation_x_rad(const float angle_in_rad, jo_matrix * const result)
1334 {
1335  jo_matrix_identity(result);
1336  result->m11 = jo_cos_rad(angle_in_rad);
1337  result->m12 = jo_sin_rad(angle_in_rad);
1338  result->m21 = -result->m12;
1339  result->m22 = result->m11;
1340 }
1341 
1346 static __jo_force_inline void jo_matrixf_rotation_x_rad(const float angle_in_rad, jo_matrixf * const result)
1347 {
1348  jo_matrixf_identity(result);
1349  result->m11 = jo_cos_radf(angle_in_rad);
1350  result->m12 = jo_sin_radf(angle_in_rad);
1351  result->m21 = -result->m12;
1352  result->m22 = result->m11;
1353 }
1354 
1359 static __jo_force_inline void jo_matrix_rotation_y_rad(const float angle_in_rad, jo_matrix * const result)
1360 {
1361  jo_matrix_identity(result);
1362  result->m00 = jo_cos_rad(angle_in_rad);
1363  result->m20 = jo_sin_rad(angle_in_rad);
1364  result->m02 = -result->m20;
1365  result->m22 = result->m00;
1366 }
1367 
1372 static __jo_force_inline void jo_matrixf_rotation_y_rad(const float angle_in_rad, jo_matrixf * const result)
1373 {
1374  jo_matrixf_identity(result);
1375  result->m00 = jo_cos_radf(angle_in_rad);
1376  result->m20 = jo_sin_radf(angle_in_rad);
1377  result->m02 = -result->m20;
1378  result->m22 = result->m00;
1379 }
1380 
1385 static __jo_force_inline void jo_matrix_rotation_z_rad(const float angle_in_rad, jo_matrix * const result)
1386 {
1387  jo_matrix_identity(result);
1388  result->m00 = jo_cos_rad(angle_in_rad);
1389  result->m01 = jo_sin_rad(angle_in_rad);
1390  result->m10 = -result->m01;
1391  result->m11 = result->m00;
1392 }
1393 
1398 static __jo_force_inline void jo_matrixf_rotation_z_rad(const float angle_in_rad, jo_matrixf * const result)
1399 {
1400  jo_matrixf_identity(result);
1401  result->m00 = jo_cos_radf(angle_in_rad);
1402  result->m01 = jo_sin_radf(angle_in_rad);
1403  result->m10 = -result->m01;
1404  result->m11 = result->m00;
1405 }
1406 
1412 static __jo_force_inline void jo_matrix_transpose(const jo_matrix * const matrix, jo_matrix * const result)
1413 {
1414  result->m00 = matrix->m00;
1415  result->m10 = matrix->m01;
1416  result->m20 = matrix->m02;
1417  result->m30 = matrix->m03;
1418  result->m01 = matrix->m10;
1419  result->m11 = matrix->m11;
1420  result->m21 = matrix->m12;
1421  result->m31 = matrix->m13;
1422  result->m02 = matrix->m20;
1423  result->m12 = matrix->m21;
1424  result->m22 = matrix->m22;
1425  result->m32 = matrix->m23;
1426  result->m03 = matrix->m30;
1427  result->m13 = matrix->m31;
1428  result->m23 = matrix->m32;
1429  result->m33 = matrix->m33;
1430 }
1431 
1437 static __jo_force_inline void jo_matrixf_transpose(const jo_matrixf * const matrix, jo_matrixf * const result)
1438 {
1439  result->m00 = matrix->m00;
1440  result->m10 = matrix->m01;
1441  result->m20 = matrix->m02;
1442  result->m30 = matrix->m03;
1443  result->m01 = matrix->m10;
1444  result->m11 = matrix->m11;
1445  result->m21 = matrix->m12;
1446  result->m31 = matrix->m13;
1447  result->m02 = matrix->m20;
1448  result->m12 = matrix->m21;
1449  result->m22 = matrix->m22;
1450  result->m32 = matrix->m23;
1451  result->m03 = matrix->m30;
1452  result->m13 = matrix->m31;
1453  result->m23 = matrix->m32;
1454  result->m33 = matrix->m33;
1455 }
1456 
1463 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)
1464 {
1465  result->x = jo_fixed_mult(m->m00, v->x) + jo_fixed_mult(m->m10, v->y) + jo_fixed_mult(m->m20, v->z) + jo_fixed_mult(m->m30, v->w);
1466  result->y = jo_fixed_mult(m->m01, v->x) + jo_fixed_mult(m->m11, v->y) + jo_fixed_mult(m->m21, v->z) + jo_fixed_mult(m->m31, v->w);
1467  result->z = jo_fixed_mult(m->m02, v->x) + jo_fixed_mult(m->m12, v->y) + jo_fixed_mult(m->m22, v->z) + jo_fixed_mult(m->m32, v->w);
1468  result->w = jo_fixed_mult(m->m03, v->x) + jo_fixed_mult(m->m13, v->y) + jo_fixed_mult(m->m23, v->z) + jo_fixed_mult(m->m33, v->w);
1469 }
1470 
1477 static __jo_force_inline void jo_matrix_mul(const jo_matrix * const a, const jo_matrix * const b, jo_matrix * const result)
1478 {
1479  register int i;
1480  register int j;
1481  register int k;
1482  register float sum;
1483 
1484  for (i = 0; i < 4; ++i)
1485  {
1486  for (j = 0; j < 4; ++j)
1487  {
1488  sum = 0;
1489  for (k = 0; k < 4; ++k)
1490  sum += jo_fixed_mult(a->m[k][j], b->m[i][k]);
1491  result->m[i][j] = sum;
1492  }
1493  }
1494 }
1495 
1502 static __jo_force_inline void jo_matrixf_mul(const jo_matrixf * const a, const jo_matrixf * const b, jo_matrixf * const result)
1503 {
1504  register int i;
1505  register int j;
1506  register int k;
1507  register float sum;
1508 
1509  for (i = 0; i < 4; ++i)
1510  {
1511  for (j = 0; j < 4; ++j)
1512  {
1513  sum = 0;
1514  for (k = 0; k < 4; ++k)
1515  sum += a->m[k][j] * b->m[i][k];
1516  result->m[i][j] = sum;
1517  }
1518  }
1519 }
1520 
1526 static __jo_force_inline void jo_matrixf_rotation(const float angle_in_rad, const jo_vectorf * const axis, jo_matrixf * const result)
1527 {
1528  jo_vectorf normalized_axis;
1529 
1530  jo_vectorf_normalize(axis, &normalized_axis);
1531  float c = jo_cos_radf(angle_in_rad);
1532  float s = jo_sin_radf(angle_in_rad);
1533  float a = 1 - c;
1534  jo_matrixf_identity(result);
1535  result->m00 = c + normalized_axis.x * normalized_axis.x * a;
1536  result->m10 = normalized_axis.x * normalized_axis.y * a - normalized_axis.z * s;
1537  result->m20 = normalized_axis.x * normalized_axis.z * a + normalized_axis.y * s;
1538  result->m01 = normalized_axis.y * normalized_axis.x * a + normalized_axis.z * s;
1539  result->m11 = c + normalized_axis.y * normalized_axis.y * a;
1540  result->m21 = normalized_axis.y * normalized_axis.z * a - normalized_axis.x * s;
1541  result->m02 = normalized_axis.z * normalized_axis.x * a - normalized_axis.y * s;
1542  result->m12 = normalized_axis.z * normalized_axis.y * a + normalized_axis.x * s;
1543  result->m22 = c + normalized_axis.z * normalized_axis.z * a;
1544 }
1545 
1555 static __jo_force_inline void jo_matrixf_ortho(const float left, const float right, const float bottom, const float top,
1556  const float back, const float front, jo_matrixf * const result)
1557 {
1558  jo_matrixf_identity(result);
1559  result->m00 = 2 / (right - left);
1560  result->m11 = 2 / (top - bottom);
1561  result->m22 = 2 / (back - front);
1562  result->m30 = -(right + left) / (right - left);
1563  result->m31 = -(top + bottom) / (top - bottom);
1564  result->m32 = -(back + front) / (back - front);
1565 }
1566 
1575 static __jo_force_inline void jo_matrixf_perspective(const float vertical_field_of_view_in_deg, const float aspect_ratio,
1576  const float near_view_distance, const float far_view_distance, jo_matrixf * const result)
1577 {
1578  jo_matrixf_identity(result);
1579  result->m11 = 1.0f / jo_tan_radf((vertical_field_of_view_in_deg / 180 * JO_PI) / 2.0f);
1580  result->m00 = result->m11 / aspect_ratio;
1581  result->m22 = (far_view_distance + near_view_distance) / (near_view_distance - far_view_distance);
1582  result->m32 = (2 * far_view_distance * near_view_distance) / (near_view_distance - far_view_distance);
1583  result->m23 = -1;
1584  result->m33 = 0;
1585 }
1586 
1593 static __jo_force_inline void jo_matrixf_look_at(const jo_vectorf * const from, const jo_vectorf * const to,
1594  const jo_vectorf * const up, jo_matrixf * const result)
1595 {
1596  jo_vectorf tmp;
1597  jo_vectorf x;
1598  jo_vectorf y;
1599  jo_vectorf z;
1600 
1601  jo_vectorf_sub(to, from, &tmp);
1602  jo_vectorf_normalize(&tmp, &tmp);
1603  jo_vectorf_muls(&tmp, -1, &z);
1604  jo_vectorf_cross(up, &z, &tmp);
1605  jo_vectorf_normalize(&tmp, &x);
1606  jo_vectorf_cross(&z, &x, &y);
1607 
1608  jo_matrixf_identity(result);
1609  result->m00 = x.x;
1610  result->m10 = x.y;
1611  result->m20 = x.z;
1612  result->m30 = -jo_vectorf_dot(from, &x);
1613  result->m01 = y.x;
1614  result->m11 = y.y;
1615  result->m21 = y.z;
1616  result->m31 = -jo_vectorf_dot(from, &y);
1617  result->m02 = z.x;
1618  result->m12 = z.y;
1619  result->m22 = z.z;
1620  result->m33 = -jo_vectorf_dot(from, &z);
1621 }
1622 
1627 static __jo_force_inline void jo_matrixf_invert_affine(const jo_matrixf * const matrix, jo_matrixf * const result)
1628 {
1629  float c00 = matrix->m11 * matrix->m22 - matrix->m12 * matrix->m21;
1630  float c10 = -(matrix->m01 * matrix->m22 - matrix->m02 * matrix->m21);
1631  float c20 = matrix->m01 * matrix->m12 - matrix->m02 * matrix->m11;
1632  float det = matrix->m00 * c00 + matrix->m10 * c10 + matrix->m20 * c20;
1633  jo_matrixf_identity(result);
1634  if (JO_FABS(det) < JO_FLOAT_EPSILON)
1635  return;
1636  float c01 = -(matrix->m10 * matrix->m22 - matrix->m12 * matrix->m20);
1637  float c11 = matrix->m00 * matrix->m22 - matrix->m02 * matrix->m20;
1638  float c21 = -(matrix->m00 * matrix->m12 - matrix->m02 * matrix->m10);
1639  float c02 = matrix->m10 * matrix->m21 - matrix->m11 * matrix->m20;
1640  float c12 = -(matrix->m00 * matrix->m21 - matrix->m01 * matrix->m20);
1641  float c22 = matrix->m00 * matrix->m11 - matrix->m01 * matrix->m10;
1642  float i00 = c00 / det;
1643  float i10 = c01 / det;
1644  float i20 = c02 / det;
1645  float i01 = c10 / det;
1646  float i11 = c11 / det;
1647  float i21 = c12 / det;
1648  float i02 = c20 / det;
1649  float i12 = c21 / det;
1650  float i22 = c22 / det;
1651 
1652  result->m00 = i00;
1653  result->m10 = i10;
1654  result->m20 = i20;
1655  result->m30 = -(i00 * matrix->m30 + i10 * matrix->m31 + i20 * matrix->m32);
1656  result->m01 = i01;
1657  result->m11 = i11;
1658  result->m21 = i21;
1659  result->m31 = -(i01 * matrix->m30 + i11 * matrix->m31 + i21 * matrix->m32);
1660  result->m02 = i02;
1661  result->m12 = i12;
1662  result->m22 = i22;
1663  result->m32 = -(i02 * matrix->m30 + i12 * matrix->m31 + i22 * matrix->m32);
1664 }
1665 
1671 static __jo_force_inline void jo_matrixf_mul_pos(const jo_matrixf * const matrix, const jo_vectorf * const position,
1672  jo_vectorf * const result)
1673 {
1674  float w = matrix->m03 * position->x + matrix->m13 * position->y + matrix->m23 * position->z + matrix->m33;
1675  result->x = matrix->m00 * position->x + matrix->m10 * position->y + matrix->m20 * position->z + matrix->m30;
1676  result->y = matrix->m01 * position->x + matrix->m11 * position->y + matrix->m21 * position->z + matrix->m31;
1677  result->z = matrix->m02 * position->x + matrix->m12 * position->y + matrix->m22 * position->z + matrix->m32;
1678  if (w != 0 && w != 1)
1679  {
1680  result->x /= w;
1681  result->y /= w;
1682  result->z /= w;
1683  }
1684 }
1685 
1691 static __jo_force_inline void jo_matrixf_mul_dir(const jo_matrixf * const matrix, const jo_vectorf * const direction,
1692  jo_vectorf * const result)
1693 {
1694  float w = matrix->m03 * direction->x + matrix->m13 * direction->y + matrix->m23 * direction->z;
1695  result->x = matrix->m00 * direction->x + matrix->m10 * direction->y + matrix->m20 * direction->z;
1696  result->y = matrix->m01 * direction->x + matrix->m11 * direction->y + matrix->m21 * direction->z;
1697  result->z = matrix->m02 * direction->x + matrix->m12 * direction->y + matrix->m22 * direction->z;
1698  if (w != 0 && w != 1)
1699  {
1700  result->x /= w;
1701  result->y /= w;
1702  result->z /= w;
1703  }
1704 }
1705 
1706 /*
1707 ███╗ ███╗██╗███████╗ ██████╗
1708 ████╗ ████║██║██╔════╝██╔════╝
1709 ██╔████╔██║██║███████╗██║
1710 ██║╚██╔╝██║██║╚════██║██║
1711 ██║ ╚═╝ ██║██║███████║╚██████╗
1712 ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝
1713 
1714 */
1715 
1722 static __jo_force_inline jo_fixed jo_lerp(const jo_fixed v0, const jo_fixed v1, const jo_fixed t)
1723 {
1724  return (jo_fixed_mult((JO_FIXED_1 - t), v0) + jo_fixed_mult(t, v1));
1725 }
1726 
1731 static __jo_force_inline bool jo_is_float_equals_zero(const float f)
1732 {
1733  return (JO_ABS(f) < 0.00000001f);
1734 }
1735 
1747 static __jo_force_inline bool jo_square_intersect(const int x1, const int y1, const int w1, const int h1,
1748  const int x2, const int y2, const int w2, const int h2)
1749 {
1750  return ((x1 < x2 + w2) && (x2 < x1 + w1)) && ((y1 < y2 + h2) && (y2 < y1 + h1));
1751 }
1752 
1759 int jo_gcd(int a, int b);
1760 
1768 void jo_planar_rotate(const jo_pos2D * const point, const jo_pos2D * const origin, const int angle, jo_pos2D * const result);
1769 
1775 {
1776  switch (direction)
1777  {
1778  case LEFT:
1779  return (180);
1780  case RIGHT:
1781  return (0);
1782  case UP:
1783  return (270);
1784  case DOWN:
1785  return (90);
1786  case UP_LEFT:
1787  return (225);
1788  case UP_RIGHT:
1789  return (315);
1790  case DOWN_LEFT:
1791  return (135);
1792  case DOWN_RIGHT:
1793  return (45);
1794  default:
1795  return (0);
1796  }
1797 }
1798 
1799 #endif /* !__JO_MATH_H__ */
1800 
1801 /*
1802 ** END OF FILE
1803 */
1804 
jo_matrixf_mul
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:1502
jo_sin_mult
static __jo_force_inline int jo_sin_mult(const int value, const int deg)
Fast sinus multiplication.
Definition: math.h:740
jo_sin_radf
static __jo_force_inline float jo_sin_radf(const float rad)
Sinus computation.
Definition: math.h:730
jo_rsqrt
float jo_rsqrt(float value)
Fast Reciprocal Square root using floating number.
jo_cosf_mult
static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
Fast cosinus multiplication.
Definition: math.h:825
jo_gcd
int jo_gcd(int a, int b)
Get the greatest common divisor.
RIGHT
@ RIGHT
Definition: types.h:305
JO_FIXED_360
#define JO_FIXED_360
Fixed floating point value for 360.
Definition: math.h:379
jo_fixed_deg2rad
static __jo_force_inline jo_fixed jo_fixed_deg2rad(const jo_fixed deg)
Convert fixed degree to fixed radian.
Definition: math.h:503
jo_matrix_rotation_y_rad
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:1359
jo_vector4_fixed_add
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:986
UP_RIGHT
@ UP_RIGHT
Definition: types.h:309
jo_vectorf::y
float y
Definition: types.h:134
JO_RAD_TO_DEG
#define JO_RAD_TO_DEG(A)
Convert radians to degrees.
Definition: math.h:266
jo_vectorf_subs
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:1108
JO_FIXED_180
#define JO_FIXED_180
Fixed floating point value for 180.
Definition: math.h:377
jo_random
int jo_random(int max)
Get a random number.
jo_vectorf_angle_between_radf
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:1236
jo_matrix_rotation_z_rad
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:1385
jo_matrixf_scaling
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:1321
UP_LEFT
@ UP_LEFT
Definition: types.h:308
jo_DEGtoANG
static __jo_force_inline ANGLE jo_DEGtoANG(const float deg)
Replacement for DEGtoANG using floating number.
Definition: math.h:637
jo_fixed_floor
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:530
jo_vectorf::z
float z
Definition: types.h:135
jo_sin
static __jo_force_inline jo_fixed jo_sin(const int deg)
Fast sinus computation.
Definition: math.h:700
JO_INT_TO_FIXED
#define JO_INT_TO_FIXED(X)
Convert int to jo_fixed.
Definition: math.h:405
jo_sin_rad
static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
Sinus computation.
Definition: math.h:720
jo_cos_radf
static __jo_force_inline float jo_cos_radf(const float rad)
Cosinus computation.
Definition: math.h:805
DOWN_RIGHT
@ DOWN_RIGHT
Definition: types.h:311
jo_vector_fixed_add
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:960
jo_matrixf_transpose
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:1437
jo_vector4_swap
static __jo_force_inline void jo_vector4_swap(jo_vector4_fixed *const a, jo_vector4_fixed *const b)
Dot product of 2 vectors4 (using fixed numbers)
Definition: math.h:1036
jo_vector4_fixed_cross
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:1013
jo_vectorf_cross
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:1224
jo_cosf
static __jo_force_inline float jo_cosf(const int deg)
Cosinus computation.
Definition: math.h:785
jo_vectorf_adds
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:1082
jo_vector4_fixed
Vector4 for 3D computation using fixed number.
Definition: types.h:165
jo_acos_radf
static __jo_force_inline float jo_acos_radf(const float angle)
Fast Arc Cosinus computation.
Definition: math.h:892
jo_matrixf_identity
static __jo_force_inline void jo_matrixf_identity(jo_matrixf *const result)
Creates the identity matrix (using floating numbers)
Definition: math.h:1269
jo_vectorf_sub
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:1095
UP
@ UP
Definition: types.h:306
jo_DEGtoANG_int
static __jo_force_inline ANGLE jo_DEGtoANG_int(const int deg)
Replacement for DEGtoANG using interger.
Definition: math.h:650
JO_MULT_BY_65536
#define JO_MULT_BY_65536(X)
Multiply a variable by 65536.
Definition: math.h:138
jo_sqrtf
static __jo_force_inline float jo_sqrtf(float value)
Fast Square root using floating number.
Definition: math.h:590
jo_matrix_mul
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:1477
jo_fixed_deg2ANGLE
static __jo_force_inline ANGLE jo_fixed_deg2ANGLE(const jo_fixed deg)
Convert fixed degree to SGL ANGLE.
Definition: math.h:676
__JO_DEG_TO_ANGLE_MAGIC
#define __JO_DEG_TO_ANGLE_MAGIC
See https://github.com/johannes-fetz/joengine/issues/42.
Definition: math.h:631
JO_FIXED_TO_INT
#define JO_FIXED_TO_INT(X)
Convert jo_fixed to int.
Definition: math.h:409
jo_square_intersect
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:1747
jo_vector_fixed_compute_bezier_point
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)
jo_fixed_ceil
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:521
jo_fixed_rad2ANGLE
static __jo_force_inline ANGLE jo_fixed_rad2ANGLE(const jo_fixed rad)
Convert fixed radian to SGL ANGLE.
Definition: math.h:665
jo_matrix::m
jo_fixed m[4][4]
Definition: types.h:187
jo_is_float_equals_zero
static __jo_force_inline bool jo_is_float_equals_zero(const float f)
Check if float almost equals 0.
Definition: math.h:1731
jo_matrixf_rotation
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:1526
jo_fixed_cos
jo_fixed jo_fixed_cos(jo_fixed rad)
Fast cosinus computation using fixed number.
jo_matrixf::table
float table[16]
Definition: types.h:174
jo_cos
static __jo_force_inline jo_fixed jo_cos(const int deg)
Fast cosinus computation.
Definition: math.h:775
jo_direction_to_angle
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:1774
jo_matrixf_translation
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:1297
jo_matrixf_mul_dir
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:1691
jo_matrix::table
jo_fixed table[16]
Definition: types.h:188
jo_fixed_wrap_to_180
static __jo_force_inline jo_fixed jo_fixed_wrap_to_180(jo_fixed deg)
Wrap deg in [-180 180].
Definition: math.h:462
jo_matrix_transpose
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:1412
jo_vectorf_mul
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:1121
JO_ZERO
#define JO_ZERO(X)
Set a variable to zero.
Definition: math.h:213
jo_matrix_scaling
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:1309
jo_fixed2float
static __jo_force_inline float jo_fixed2float(const jo_fixed x)
Convert jo engine fixed to float.
Definition: math.h:442
jo_fixed_dot
jo_fixed jo_fixed_dot(jo_fixed ptA[3], jo_fixed ptB[3])
Dot product two fixed 3D points.
JO_ABS
#define JO_ABS(X)
Get the absolute value of X.
Definition: math.h:225
jo_matrixf_rotation_x_rad
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:1346
jo_atan2f
static __jo_force_inline int jo_atan2f(const float y, const float x)
Fast ATAN2 computation in degree.
Definition: math.h:921
jo_atan2f_rad
float jo_atan2f_rad(const float y, const float x)
Fast ATAN2 computation in radian.
jo_matrixf_look_at
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:1593
jo_vectorf_normalize
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:1191
jo_matrix_rotation_x_rad
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:1333
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
jo_tan_radf
static __jo_force_inline float jo_tan_radf(const float rad)
Tangent computation.
Definition: math.h:874
jo_vectorf_add
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:1069
jo_tan
static __jo_force_inline jo_fixed jo_tan(const int deg)
Fast tangent computation.
Definition: math.h:844
jo_fixed
int jo_fixed
Fixed point Q16.16 number.
Definition: types.h:49
JO_FLOAT_EPSILON
#define JO_FLOAT_EPSILON
Float minimum positive value.
Definition: math.h:250
jo_matrixf_invert_affine
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:1627
JO_FIXED_PI_2
#define JO_FIXED_PI_2
Fixed value of 2 PI.
Definition: math.h:392
jo_random_seed
int jo_random_seed
Get or set current random seed.
jo_int2fixed
static __jo_force_inline jo_fixed jo_int2fixed(const int x)
Convert int to jo engine fixed.
Definition: math.h:415
jo_matrix
4x4 MATRIX for 3D computation using fixed number
Definition: types.h:186
JO_FIXED_PI
#define JO_FIXED_PI
Fixed value of PI.
Definition: math.h:390
jo_sqrt
unsigned int jo_sqrt(unsigned int value)
Fast square root.
jo_planar_rotate
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.
jo_vector_fixed
Vector for 3D computation using fixed number.
Definition: types.h:150
jo_fixed2int
static __jo_force_inline int jo_fixed2int(const jo_fixed x)
Convert jo engine fixed to int.
Definition: math.h:424
jo_vectorf::x
float x
Definition: types.h:133
JO_FIXED_PI_DIV_180
#define JO_FIXED_PI_DIV_180
Fixed value of PI/180.
Definition: math.h:396
jo_matrix_identity
static __jo_force_inline void jo_matrix_identity(jo_matrix *const result)
Creates the identity matrix (using fixed numbers)
Definition: math.h:1254
jo_vector4_fixed::w
jo_fixed w
Definition: types.h:167
jo_vectorf_length
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:1171
jo_vectorf_div
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:1147
jo_vectorf_divs
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:1160
jo_cos_mult
static __jo_force_inline int jo_cos_mult(const int value, const int deg)
Fast cosinus multiplication.
Definition: math.h:815
jo_tanf
static __jo_force_inline float jo_tanf(const float deg)
Tangent computation.
Definition: math.h:854
JO_SWAP
#define JO_SWAP(A, B)
Swap A and B values.
Definition: math.h:282
jo_vectorf_compute_bezier_point
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)
jo_lerp
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:1722
jo_sinf_mult
static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
Fast sinus multiplication.
Definition: math.h:750
DOWN
@ DOWN
Definition: types.h:307
jo_vector4_fixed_sub
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:1000
jo_matrixf_rotation_y_rad
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:1372
JO_PI
#define JO_PI
PI value.
Definition: math.h:48
jo_random_using_multiple
static __jo_force_inline int jo_random_using_multiple(int max, int multiple)
Get a random number with a specific multiple.
Definition: math.h:559
jo_matrix_translation
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:1285
jo_fixed_rad2deg
static __jo_force_inline jo_fixed jo_fixed_rad2deg(const jo_fixed rad)
Convert fixed radian to fixed degree.
Definition: math.h:512
JO_SQUARE
#define JO_SQUARE(A)
Square computation (x²)
Definition: math.h:293
jo_matrixf
4x4 MATRIX for 3D computation using floating numbers
Definition: types.h:172
jo_matrixf::m
float m[4][4]
Definition: types.h:173
jo_sinf
static __jo_force_inline float jo_sinf(const int deg)
Sinus computation.
Definition: math.h:710
jo_cos_rad
static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
Cosinus computation.
Definition: math.h:795
jo_vectorf_dot
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:1181
jo_8_directions
jo_8_directions
8 directions definition
Definition: types.h:302
jo_fixed_wrap_to_pi
static __jo_force_inline jo_fixed jo_fixed_wrap_to_pi(jo_fixed rad)
Wrap rad in [−pi pi].
Definition: math.h:451
jo_fixed_sqrt
jo_fixed jo_fixed_sqrt(jo_fixed value)
Fast Square root using fixed number.
jo_pos2D
2D position
Definition: types.h:53
jo_matrix_mul_vector4
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:1463
jo_fixed_mult
jo_fixed jo_fixed_mult(jo_fixed x, jo_fixed y)
Multiply to fixed number.
DOWN_LEFT
@ DOWN_LEFT
Definition: types.h:310
jo_fixed_sin
jo_fixed jo_fixed_sin(jo_fixed rad)
Fast sinus computation using fixed number.
jo_matrixf_mul_pos
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:1671
JO_FIXED_1_DIV
#define JO_FIXED_1_DIV
Fixed value of 1/65536.
Definition: math.h:400
JO_FIXED_1
#define JO_FIXED_1
Fixed floating point value for 1.
Definition: math.h:361
jo_float2fixed
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:433
JO_FABS
#define JO_FABS(X)
Get the absolute value of X.
Definition: math.h:230
jo_vectorf_proj
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:1213
jo_fixed_rsqrt
jo_fixed jo_fixed_rsqrt(jo_fixed value)
Fast Reciprocal Square root using fixed number.
jo_fixed_pow
jo_fixed jo_fixed_pow(jo_fixed x, jo_fixed y)
x raised to the power of the integer part of y
jo_vectorf
Vector for 3D computation using floating numbers.
Definition: types.h:132
jo_tan_rad
static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
Tangent computation.
Definition: math.h:864
jo_vector4_fixed_dot
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:1026
jo_matrixf_perspective
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:1575
JO_FIXED_180_DIV_PI
#define JO_FIXED_180_DIV_PI
Fixed value of 180/PI.
Definition: math.h:394
LEFT
@ LEFT
Definition: types.h:304
jo_vectorf_muls
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:1134
jo_matrixf_ortho
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:1555
jo_fixed_div
jo_fixed jo_fixed_div(jo_fixed dividend, jo_fixed divisor)
Divide fixed-point numbers (expresses dividend / divisor)
jo_matrixf_rotation_z_rad
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:1398
jo_vector_fixed_muls
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:973