Jo Engine  2023.08.26
Jo Sega Saturn Engine
math.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, 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 (‭131072‬)
364 
365 # define JO_FIXED_4 (‭262144‬)
366 
367 # define JO_FIXED_8 (‭524288‬)
368 
369 # define JO_FIXED_16 (‭1048576‬)
370 
371 # define JO_FIXED_32 (2097152)
372 
373 # define JO_FIXED_120 (7864320)
374 
375 # define JO_FIXED_150 (9830400)
376 
377 # define JO_FIXED_180 (11796480)
378 
379 # define JO_FIXED_360 (23592960)
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 
402 
408 {
409  return JO_MULT_BY_65536(x);
410 }
411 
417 {
418  return JO_DIV_BY_65536(x);
419 }
420 
426 {
427  return ((jo_fixed)(x * (float)JO_FIXED_1));
428 }
429 
435 {
436  return ((float)x * JO_FIXED_1_DIV);
437 }
438 
444 {
445  while (rad > JO_FIXED_PI) rad -= JO_FIXED_PI_2;
446  while (rad <= -JO_FIXED_PI) rad += JO_FIXED_PI_2;
447  return (rad);
448 }
449 
455 {
456  while (deg > JO_FIXED_180) deg -= JO_FIXED_360;
457  while (deg <= -JO_FIXED_PI) deg += JO_FIXED_360;
458  return (deg);
459 }
460 
467 
474 
482 
490 
496 {
498 }
499 
505 {
507 }
508 
514 {
515  return (x & 0xFFFF0000UL) + (x & 0x0000FFFFUL ? JO_FIXED_1 : 0);
516 }
517 
523 {
524  return (x & 0xFFFF0000ul);
525 }
526 
527 /*
528 ██████╗ █████╗ ███╗ ██╗██████╗ ██████╗ ███╗ ███╗
529 ██╔══██╗██╔══██╗████╗ ██║██╔══██╗██╔═══██╗████╗ ████║
530 ██████╔╝███████║██╔██╗ ██║██║ ██║██║ ██║██╔████╔██║
531 ██╔══██╗██╔══██║██║╚██╗██║██║ ██║██║ ██║██║╚██╔╝██║
532 ██║ ██║██║ ██║██║ ╚████║██████╔╝╚██████╔╝██║ ╚═╝ ██║
533 ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
534 */
535 
538 extern int jo_random_seed;
539 
544 int jo_random(int max);
545 
551 static __jo_force_inline int jo_random_using_multiple(int max, int multiple)
552 {
553  return (jo_random(max) / multiple) * multiple;
554 }
555 
556 /*
557 ███████╗ ██████╗ ██████╗ ████████╗
558 ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝
559 ███████╗██║ ██║██████╔╝ ██║
560 ╚════██║██║▄▄ ██║██╔══██╗ ██║
561 ███████║╚██████╔╝██║ ██║ ██║
562 ╚══════╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═╝
563 */
564 
570 
575 unsigned int jo_sqrt(unsigned int value);
576 
582 static __jo_force_inline float jo_sqrtf(float value)
583 {
584  unsigned int i = *(unsigned int*)(void *)&value;
585  i += 127 << 23;
586  i >>= 1;
587  return *(float*)(void *)&i;
588 }
589 
590 /*
591 ██╗███╗ ██╗██╗ ██╗███████╗██████╗ ███████╗███████╗ ███████╗ ██████╗ ██████╗ ████████╗
592 ██║████╗ ██║██║ ██║██╔════╝██╔══██╗██╔════╝██╔════╝ ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝
593 ██║██╔██╗ ██║██║ ██║█████╗ ██████╔╝███████╗█████╗ ███████╗██║ ██║██████╔╝ ██║
594 ██║██║╚██╗██║╚██╗ ██╔╝██╔══╝ ██╔══██╗╚════██║██╔══╝ ╚════██║██║▄▄ ██║██╔══██╗ ██║
595 ██║██║ ╚████║ ╚████╔╝ ███████╗██║ ██║███████║███████╗ ███████║╚██████╔╝██║ ██║ ██║
596 ╚═╝╚═╝ ╚═══╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚══════╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═╝
597 AKA RECIPROCAL SQUARE ROOT
598 */
599 
605 
610 float jo_rsqrt(float value);
611 
612 /*
613 ███████╗ ██████╗ ██╗ ██╗███╗ ██╗████████╗███████╗██████╗ ██████╗ ██████╗
614 ██╔════╝██╔════╝ ██║ ██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗██╔═══██╗██╔══██╗
615 ███████╗██║ ███╗██║ ██║██╔██╗ ██║ ██║ █████╗ ██████╔╝██║ ██║██████╔╝
616 ╚════██║██║ ██║██║ ██║██║╚██╗██║ ██║ ██╔══╝ ██╔══██╗██║ ██║██╔═══╝
617 ███████║╚██████╔╝███████╗ ██║██║ ╚████║ ██║ ███████╗██║ ██║╚██████╔╝██║
618 ╚══════╝ ╚═════╝ ╚══════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝
619 
620 */
621 
623 # define __JO_DEG_TO_ANGLE_MAGIC (182)
624 
629 static __jo_force_inline ANGLE jo_DEGtoANG(const float deg)
630 {
631 #ifdef JO_COMPILE_WITH_FAST_BUT_LESS_ACCURATE_MATH
632  return ((ANGLE)(__JO_DEG_TO_ANGLE_MAGIC * (deg)));
633 #else
634  return ((ANGLE)((65536.0 * (deg)) / 360.0));
635 #endif
636 }
637 
642 static __jo_force_inline ANGLE jo_DEGtoANG_int(const int deg)
643 {
644 #ifdef JO_COMPILE_WITH_FAST_BUT_LESS_ACCURATE_MATH
645  return ((ANGLE)(__JO_DEG_TO_ANGLE_MAGIC * (deg)));
646 #else
647  return ((ANGLE)(JO_MULT_BY_65536(deg) / 360.0));
648 #endif
649 }
650 
651 #if JO_COMPILE_USING_SGL
652 
658 {
659  return (RADtoANG(jo_fixed2float(rad)));
660 }
661 
662 #endif
663 
669 {
670  return (jo_DEGtoANG(jo_fixed2float(deg)));
671 }
672 
673 /*
674 ███████╗██╗███╗ ██╗██╗ ██╗███████╗
675 ██╔════╝██║████╗ ██║██║ ██║██╔════╝
676 ███████╗██║██╔██╗ ██║██║ ██║███████╗
677 ╚════██║██║██║╚██╗██║██║ ██║╚════██║
678 ███████║██║██║ ╚████║╚██████╔╝███████║
679 ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
680 */
681 
687 
692 static __jo_force_inline jo_fixed jo_sin(const int deg)
693 {
695 }
696 
702 static __jo_force_inline float jo_sinf(const int deg)
703 {
704  return (jo_fixed2float(jo_sin(deg)));
705 }
706 
712 static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
713 {
714  return (jo_fixed_sin(jo_float2fixed(rad)));
715 }
716 
722 static __jo_force_inline float jo_sin_radf(const float rad)
723 {
725 }
726 
732 static __jo_force_inline int jo_sin_mult(const int value, const int deg)
733 {
734  return (jo_fixed2int(value * jo_sin(deg)));
735 }
736 
742 static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
743 {
744  return (value * jo_sinf(deg));
745 }
746 
747 /*
748  ██████╗ ██████╗ ███████╗██╗███╗ ██╗██╗ ██╗███████╗
749 ██╔════╝██╔═══██╗██╔════╝██║████╗ ██║██║ ██║██╔════╝
750 ██║ ██║ ██║███████╗██║██╔██╗ ██║██║ ██║███████╗
751 ██║ ██║ ██║╚════██║██║██║╚██╗██║██║ ██║╚════██║
752 ╚██████╗╚██████╔╝███████║██║██║ ╚████║╚██████╔╝███████║
753  ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
754 
755 */
756 
762 
767 static __jo_force_inline jo_fixed jo_cos(const int deg)
768 {
770 }
771 
777 static __jo_force_inline float jo_cosf(const int deg)
778 {
779  return (jo_fixed2float(jo_cos(deg)));
780 }
781 
787 static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
788 {
789  return (jo_fixed_cos(jo_float2fixed(rad)));
790 }
791 
797 static __jo_force_inline float jo_cos_radf(const float rad)
798 {
800 }
801 
807 static __jo_force_inline int jo_cos_mult(const int value, const int deg)
808 {
809  return (jo_fixed2int(value * jo_cos(deg)));
810 }
811 
817 static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
818 {
819  return (value * jo_cosf(deg));
820 }
821 
822 /*
823 ████████╗ █████╗ ███╗ ██╗ ██████╗ ███████╗███╗ ██╗████████╗
824 ╚══██╔══╝██╔══██╗████╗ ██║██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝
825  ██║ ███████║██╔██╗ ██║██║ ███╗█████╗ ██╔██╗ ██║ ██║
826  ██║ ██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██║╚██╗██║ ██║
827  ██║ ██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ╚████║ ██║
828  ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
829 
830 */
831 
836 static __jo_force_inline jo_fixed jo_tan(const int deg)
837 {
838  return jo_fixed_div(jo_sin(deg), jo_cos(deg));
839 }
840 
846 static __jo_force_inline float jo_tanf(const float deg)
847 {
848  return (jo_sinf(deg) / jo_cosf(deg));
849 }
850 
856 static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
857 {
858  return jo_fixed_div(jo_sin_rad(rad), jo_cos_rad(rad));
859 }
860 
866 static __jo_force_inline float jo_tan_radf(const float rad)
867 {
868  return (jo_sin_radf(rad) / jo_cos_radf(rad));
869 }
870 
871 /*
872  █████╗ ██████╗ ██████╗ ███████╗
873 ██╔══██╗██╔════╝██╔═══██╗██╔════╝
874 ███████║██║ ██║ ██║███████╗
875 ██╔══██║██║ ██║ ██║╚════██║
876 ██║ ██║╚██████╗╚██████╔╝███████║
877 ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝
878 */
879 
884 static __jo_force_inline float jo_acos_radf(const float angle)
885 {
886  return (3.14159f - 1.57079f * angle);
887 }
888 
889 /*
890  █████╗ ████████╗ █████╗ ███╗ ██╗██████╗
891 ██╔══██╗╚══██╔══╝██╔══██╗████╗ ██║╚════██╗
892 ███████║ ██║ ███████║██╔██╗ ██║ █████╔╝
893 ██╔══██║ ██║ ██╔══██║██║╚██╗██║██╔═══╝
894 ██║ ██║ ██║ ██║ ██║██║ ╚████║███████╗
895 ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝
896 
897 */
898 
905 float jo_atan2f_rad(const float y, const float x);
906 
913 static __jo_force_inline int jo_atan2f(const float y, const float x)
914 {
915  return (int)JO_RAD_TO_DEG(jo_atan2f_rad(y, x));
916 }
917 
918 /*
919 ██╗ ██╗███████╗ ██████╗████████╗ ██████╗ ██████╗
920 ██║ ██║██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗
921 ██║ ██║█████╗ ██║ ██║ ██║ ██║██████╔╝
922 ╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║ ██║██╔══██╗
923  ╚████╔╝ ███████╗╚██████╗ ██║ ╚██████╔╝██║ ██║
924  ╚═══╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
925 */
926 
927 /*
928  _______ __ _ __ __
929  / ____(_) _____ ____/ / / | / /_ ______ ___ / /_ ___ _____
930  / /_ / / |/_/ _ \/ __ / / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
931  / __/ / /> </ __/ /_/ / / /| / /_/ / / / / / / /_/ / __/ /
932 /_/ /_/_/|_|\___/\__,_/ /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
933 
934 */
935 
945 
952 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)
953 {
954  result->x = a->x + b->x;
955  result->y = a->y + b->y;
956  result->z = a->z + b->z;
957 }
958 
965 static __jo_force_inline void jo_vector_fixed_muls(const jo_vector_fixed * const a, const jo_fixed s, jo_vector_fixed * const result)
966 {
967  result->x = jo_fixed_mult(a->x, s);
968  result->y = jo_fixed_mult(a->y, s);
969  result->z = jo_fixed_mult(a->z, s);
970 }
971 
978 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)
979 {
980  result->x = a->x + b->x;
981  result->y = a->y + b->y;
982  result->z = a->z + b->z;
983  result->w = JO_FIXED_1;
984 }
985 
992 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)
993 {
994  result->x = a->x - b->x;
995  result->y = a->y - b->y;
996  result->z = a->z - b->z;
997  result->w = JO_FIXED_1;
998 }
999 
1005 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)
1006 {
1007  result->x = jo_fixed_mult(a->y, b->z) - jo_fixed_mult(a->z, b->y);
1008  result->y = jo_fixed_mult(a->z, b->x) - jo_fixed_mult(a->x, b->z);
1009  result->z = jo_fixed_mult(a->x, b->y) - jo_fixed_mult(a->y, b->x);
1010  result->w = JO_FIXED_1;
1011 }
1012 
1019 {
1020  return (jo_fixed_mult(a->x, b->x) + jo_fixed_mult(a->y, b->y) + jo_fixed_mult(a->z, b->z));
1021 }
1022 
1029 {
1030  JO_SWAP(a->x, b->x);
1031  JO_SWAP(a->y, b->y);
1032  JO_SWAP(a->z, b->z);
1033  JO_SWAP(a->w, b->w);
1034 }
1035 
1036 /*
1037  ________ __ _ _ __ __
1038  / ____/ /___ ____ _/ /_(_)___ ____ _ / | / /_ ______ ___ / /_ ___ _____
1039  / /_ / / __ \/ __ `/ __/ / __ \/ __ `/ / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
1040  / __/ / / /_/ / /_/ / /_/ / / / / /_/ / / /| / /_/ / / / / / / /_/ / __/ /
1041 /_/ /_/\____/\__,_/\__/_/_/ /_/\__, / /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
1042  /____/
1043 */
1044 
1054 
1061 static __jo_force_inline void jo_vectorf_add(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1062 {
1063  result->x = a->x + b->x;
1064  result->y = a->y + b->y;
1065  result->z = a->z + b->z;
1066 }
1067 
1074 static __jo_force_inline void jo_vectorf_adds(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1075 {
1076  result->x = a->x + s;
1077  result->y = a->y + s;
1078  result->z = a->z + s;
1079 }
1080 
1087 static __jo_force_inline void jo_vectorf_sub(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1088 {
1089  result->x = a->x - b->x;
1090  result->y = a->y - b->y;
1091  result->z = a->z - b->z;
1092 }
1093 
1100 static __jo_force_inline void jo_vectorf_subs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1101 {
1102  result->x = a->x - s;
1103  result->y = a->y - s;
1104  result->z = a->z - s;
1105 }
1106 
1113 static __jo_force_inline void jo_vectorf_mul(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1114 {
1115  result->x = a->x * b->x;
1116  result->y = a->y * b->y;
1117  result->z = a->z * b->z;
1118 }
1119 
1126 static __jo_force_inline void jo_vectorf_muls(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1127 {
1128  result->x = a->x * s;
1129  result->y = a->y * s;
1130  result->z = a->z * s;
1131 }
1132 
1139 static __jo_force_inline void jo_vectorf_div(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1140 {
1141  result->x = a->x / b->x;
1142  result->y = a->y / b->y;
1143  result->z = a->z / b->z;
1144 }
1145 
1152 static __jo_force_inline void jo_vectorf_divs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1153 {
1154  result->x = a->x / s;
1155  result->y = a->y / s;
1156  result->z = a->z / s;
1157 }
1158 
1163 static __jo_force_inline float jo_vectorf_length(const jo_vectorf * const a)
1164 {
1165  return (jo_sqrtf(JO_SQUARE(a->x) + JO_SQUARE(a->y) + JO_SQUARE(a->z)));
1166 }
1167 
1173 static __jo_force_inline float jo_vectorf_dot(const jo_vectorf * const a, const jo_vectorf * const b)
1174 {
1175  return (a->x * b->x + a->y * b->y + a->z * b->z);
1176 }
1177 
1183 static __jo_force_inline void jo_vectorf_normalize(const jo_vectorf * const a, jo_vectorf * const result)
1184 {
1185  float len = jo_vectorf_length(a);
1186  if (len > 0)
1187  {
1188  result->x = a->x / len;
1189  result->y = a->y / len;
1190  result->z = a->z / len;
1191  }
1192  else
1193  {
1194  result->x = 0;
1195  result->y = 0;
1196  result->z = 0;
1197  }
1198 }
1199 
1205 static __jo_force_inline void jo_vectorf_proj(const jo_vectorf * const v, const jo_vectorf * const onto, jo_vectorf * const result)
1206 {
1207  jo_vectorf_muls(onto, jo_vectorf_dot(v, onto) / jo_vectorf_dot(onto, onto), result);
1208 }
1209 
1216 static __jo_force_inline void jo_vectorf_cross(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1217 {
1218  result->x = a->y * b->z - a->z * b->y;
1219  result->y = a->z * b->x - a->x * b->z;
1220  result->z = a->x * b->y - a->y * b->x;
1221 }
1222 
1228 static __jo_force_inline float jo_vectorf_angle_between_radf(const jo_vectorf * const a, const jo_vectorf * const b)
1229 {
1231 }
1232 
1233 /*
1234 ██╗ ██╗██╗ ██╗██╗ ██╗ ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
1235 ██║ ██║╚██╗██╔╝██║ ██║ ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
1236 ███████║ ╚███╔╝ ███████║ ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
1237 ╚════██║ ██╔██╗ ╚════██║ ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
1238  ██║██╔╝ ██╗ ██║ ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
1239  ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
1240 
1241 */
1242 
1247 {
1248  register int i;
1249 
1250  for (i = 1; i < 15; ++i)
1251  JO_ZERO(result->table[i]);
1252  result->m00 = JO_FIXED_1;
1253  result->m11 = JO_FIXED_1;
1254  result->m22 = JO_FIXED_1;
1255  result->m33 = JO_FIXED_1;
1256 }
1257 
1262 {
1263  register int i;
1264 
1265  for (i = 1; i < 15; ++i)
1266  result->table[i] = 0;
1267  result->m00 = 1;
1268  result->m11 = 1;
1269  result->m22 = 1;
1270  result->m33 = 1;
1271 }
1272 
1277 static __jo_force_inline void jo_matrix_translation(const jo_vector_fixed * const offset, jo_matrix * const result)
1278 {
1279  jo_matrix_identity(result);
1280  result->m30 = offset->x;
1281  result->m31 = offset->y;
1282  result->m32 = offset->z;
1283 }
1284 
1289 static __jo_force_inline void jo_matrixf_translation(const jo_vectorf * const offset, jo_matrixf * const result)
1290 {
1291  jo_matrixf_identity(result);
1292  result->m30 = offset->x;
1293  result->m31 = offset->y;
1294  result->m32 = offset->z;
1295 }
1296 
1301 static __jo_force_inline void jo_matrix_scaling(const jo_vector_fixed * const scale, jo_matrix * const result)
1302 {
1303  jo_matrix_identity(result);
1304  result->m00 = scale->x;
1305  result->m11 = scale->y;
1306  result->m22 = scale->z;
1307 }
1308 
1313 static __jo_force_inline void jo_matrixf_scaling(const jo_vectorf * const scale, jo_matrixf * const result)
1314 {
1315  jo_matrixf_identity(result);
1316  result->m00 = scale->x;
1317  result->m11 = scale->y;
1318  result->m22 = scale->z;
1319 }
1320 
1325 static __jo_force_inline void jo_matrix_rotation_x_rad(const float angle_in_rad, jo_matrix * const result)
1326 {
1327  jo_matrix_identity(result);
1328  result->m11 = jo_cos_rad(angle_in_rad);
1329  result->m12 = jo_sin_rad(angle_in_rad);
1330  result->m21 = -result->m12;
1331  result->m22 = result->m11;
1332 }
1333 
1338 static __jo_force_inline void jo_matrixf_rotation_x_rad(const float angle_in_rad, jo_matrixf * const result)
1339 {
1340  jo_matrixf_identity(result);
1341  result->m11 = jo_cos_radf(angle_in_rad);
1342  result->m12 = jo_sin_radf(angle_in_rad);
1343  result->m21 = -result->m12;
1344  result->m22 = result->m11;
1345 }
1346 
1351 static __jo_force_inline void jo_matrix_rotation_y_rad(const float angle_in_rad, jo_matrix * const result)
1352 {
1353  jo_matrix_identity(result);
1354  result->m00 = jo_cos_rad(angle_in_rad);
1355  result->m20 = jo_sin_rad(angle_in_rad);
1356  result->m02 = -result->m20;
1357  result->m22 = result->m00;
1358 }
1359 
1364 static __jo_force_inline void jo_matrixf_rotation_y_rad(const float angle_in_rad, jo_matrixf * const result)
1365 {
1366  jo_matrixf_identity(result);
1367  result->m00 = jo_cos_radf(angle_in_rad);
1368  result->m20 = jo_sin_radf(angle_in_rad);
1369  result->m02 = -result->m20;
1370  result->m22 = result->m00;
1371 }
1372 
1377 static __jo_force_inline void jo_matrix_rotation_z_rad(const float angle_in_rad, jo_matrix * const result)
1378 {
1379  jo_matrix_identity(result);
1380  result->m00 = jo_cos_rad(angle_in_rad);
1381  result->m01 = jo_sin_rad(angle_in_rad);
1382  result->m10 = -result->m01;
1383  result->m11 = result->m00;
1384 }
1385 
1390 static __jo_force_inline void jo_matrixf_rotation_z_rad(const float angle_in_rad, jo_matrixf * const result)
1391 {
1392  jo_matrixf_identity(result);
1393  result->m00 = jo_cos_radf(angle_in_rad);
1394  result->m01 = jo_sin_radf(angle_in_rad);
1395  result->m10 = -result->m01;
1396  result->m11 = result->m00;
1397 }
1398 
1404 static __jo_force_inline void jo_matrix_transpose(const jo_matrix * const matrix, jo_matrix * const result)
1405 {
1406  result->m00 = matrix->m00;
1407  result->m10 = matrix->m01;
1408  result->m20 = matrix->m02;
1409  result->m30 = matrix->m03;
1410  result->m01 = matrix->m10;
1411  result->m11 = matrix->m11;
1412  result->m21 = matrix->m12;
1413  result->m31 = matrix->m13;
1414  result->m02 = matrix->m20;
1415  result->m12 = matrix->m21;
1416  result->m22 = matrix->m22;
1417  result->m32 = matrix->m23;
1418  result->m03 = matrix->m30;
1419  result->m13 = matrix->m31;
1420  result->m23 = matrix->m32;
1421  result->m33 = matrix->m33;
1422 }
1423 
1429 static __jo_force_inline void jo_matrixf_transpose(const jo_matrixf * const matrix, jo_matrixf * const result)
1430 {
1431  result->m00 = matrix->m00;
1432  result->m10 = matrix->m01;
1433  result->m20 = matrix->m02;
1434  result->m30 = matrix->m03;
1435  result->m01 = matrix->m10;
1436  result->m11 = matrix->m11;
1437  result->m21 = matrix->m12;
1438  result->m31 = matrix->m13;
1439  result->m02 = matrix->m20;
1440  result->m12 = matrix->m21;
1441  result->m22 = matrix->m22;
1442  result->m32 = matrix->m23;
1443  result->m03 = matrix->m30;
1444  result->m13 = matrix->m31;
1445  result->m23 = matrix->m32;
1446  result->m33 = matrix->m33;
1447 }
1448 
1455 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)
1456 {
1457  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);
1458  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);
1459  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);
1460  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);
1461 }
1462 
1469 static __jo_force_inline void jo_matrix_mul(const jo_matrix * const a, const jo_matrix * const b, jo_matrix * const result)
1470 {
1471  register int i;
1472  register int j;
1473  register int k;
1474  register float sum;
1475 
1476  for (i = 0; i < 4; ++i)
1477  {
1478  for (j = 0; j < 4; ++j)
1479  {
1480  sum = 0;
1481  for (k = 0; k < 4; ++k)
1482  sum += jo_fixed_mult(a->m[k][j], b->m[i][k]);
1483  result->m[i][j] = sum;
1484  }
1485  }
1486 }
1487 
1494 static __jo_force_inline void jo_matrixf_mul(const jo_matrixf * const a, const jo_matrixf * const b, jo_matrixf * const result)
1495 {
1496  register int i;
1497  register int j;
1498  register int k;
1499  register float sum;
1500 
1501  for (i = 0; i < 4; ++i)
1502  {
1503  for (j = 0; j < 4; ++j)
1504  {
1505  sum = 0;
1506  for (k = 0; k < 4; ++k)
1507  sum += a->m[k][j] * b->m[i][k];
1508  result->m[i][j] = sum;
1509  }
1510  }
1511 }
1512 
1518 static __jo_force_inline void jo_matrixf_rotation(const float angle_in_rad, const jo_vectorf * const axis, jo_matrixf * const result)
1519 {
1520  jo_vectorf normalized_axis;
1521 
1522  jo_vectorf_normalize(axis, &normalized_axis);
1523  float c = jo_cos_radf(angle_in_rad);
1524  float s = jo_sin_radf(angle_in_rad);
1525  float a = 1 - c;
1526  jo_matrixf_identity(result);
1527  result->m00 = c + normalized_axis.x * normalized_axis.x * a;
1528  result->m10 = normalized_axis.x * normalized_axis.y * a - normalized_axis.z * s;
1529  result->m20 = normalized_axis.x * normalized_axis.z * a + normalized_axis.y * s;
1530  result->m01 = normalized_axis.y * normalized_axis.x * a + normalized_axis.z * s;
1531  result->m11 = c + normalized_axis.y * normalized_axis.y * a;
1532  result->m21 = normalized_axis.y * normalized_axis.z * a - normalized_axis.x * s;
1533  result->m02 = normalized_axis.z * normalized_axis.x * a - normalized_axis.y * s;
1534  result->m12 = normalized_axis.z * normalized_axis.y * a + normalized_axis.x * s;
1535  result->m22 = c + normalized_axis.z * normalized_axis.z * a;
1536 }
1537 
1547 static __jo_force_inline void jo_matrixf_ortho(const float left, const float right, const float bottom, const float top,
1548  const float back, const float front, jo_matrixf * const result)
1549 {
1550  jo_matrixf_identity(result);
1551  result->m00 = 2 / (right - left);
1552  result->m11 = 2 / (top - bottom);
1553  result->m22 = 2 / (back - front);
1554  result->m30 = -(right + left) / (right - left);
1555  result->m31 = -(top + bottom) / (top - bottom);
1556  result->m32 = -(back + front) / (back - front);
1557 }
1558 
1567 static __jo_force_inline void jo_matrixf_perspective(const float vertical_field_of_view_in_deg, const float aspect_ratio,
1568  const float near_view_distance, const float far_view_distance, jo_matrixf * const result)
1569 {
1570  jo_matrixf_identity(result);
1571  result->m11 = 1.0f / jo_tan_radf((vertical_field_of_view_in_deg / 180 * JO_PI) / 2.0f);
1572  result->m00 = result->m11 / aspect_ratio;
1573  result->m22 = (far_view_distance + near_view_distance) / (near_view_distance - far_view_distance);
1574  result->m32 = (2 * far_view_distance * near_view_distance) / (near_view_distance - far_view_distance);
1575  result->m23 = -1;
1576  result->m33 = 0;
1577 }
1578 
1585 static __jo_force_inline void jo_matrixf_look_at(const jo_vectorf * const from, const jo_vectorf * const to,
1586  const jo_vectorf * const up, jo_matrixf * const result)
1587 {
1588  jo_vectorf tmp;
1589  jo_vectorf x;
1590  jo_vectorf y;
1591  jo_vectorf z;
1592 
1593  jo_vectorf_sub(to, from, &tmp);
1594  jo_vectorf_normalize(&tmp, &tmp);
1595  jo_vectorf_muls(&tmp, -1, &z);
1596  jo_vectorf_cross(up, &z, &tmp);
1597  jo_vectorf_normalize(&tmp, &x);
1598  jo_vectorf_cross(&z, &x, &y);
1599 
1600  jo_matrixf_identity(result);
1601  result->m00 = x.x;
1602  result->m10 = x.y;
1603  result->m20 = x.z;
1604  result->m30 = -jo_vectorf_dot(from, &x);
1605  result->m01 = y.x;
1606  result->m11 = y.y;
1607  result->m21 = y.z;
1608  result->m31 = -jo_vectorf_dot(from, &y);
1609  result->m02 = z.x;
1610  result->m12 = z.y;
1611  result->m22 = z.z;
1612  result->m33 = -jo_vectorf_dot(from, &z);
1613 }
1614 
1619 static __jo_force_inline void jo_matrixf_invert_affine(const jo_matrixf * const matrix, jo_matrixf * const result)
1620 {
1621  float c00 = matrix->m11 * matrix->m22 - matrix->m12 * matrix->m21;
1622  float c10 = -(matrix->m01 * matrix->m22 - matrix->m02 * matrix->m21);
1623  float c20 = matrix->m01 * matrix->m12 - matrix->m02 * matrix->m11;
1624  float det = matrix->m00 * c00 + matrix->m10 * c10 + matrix->m20 * c20;
1625  jo_matrixf_identity(result);
1626  if (JO_FABS(det) < JO_FLOAT_EPSILON)
1627  return;
1628  float c01 = -(matrix->m10 * matrix->m22 - matrix->m12 * matrix->m20);
1629  float c11 = matrix->m00 * matrix->m22 - matrix->m02 * matrix->m20;
1630  float c21 = -(matrix->m00 * matrix->m12 - matrix->m02 * matrix->m10);
1631  float c02 = matrix->m10 * matrix->m21 - matrix->m11 * matrix->m20;
1632  float c12 = -(matrix->m00 * matrix->m21 - matrix->m01 * matrix->m20);
1633  float c22 = matrix->m00 * matrix->m11 - matrix->m01 * matrix->m10;
1634  float i00 = c00 / det;
1635  float i10 = c01 / det;
1636  float i20 = c02 / det;
1637  float i01 = c10 / det;
1638  float i11 = c11 / det;
1639  float i21 = c12 / det;
1640  float i02 = c20 / det;
1641  float i12 = c21 / det;
1642  float i22 = c22 / det;
1643 
1644  result->m00 = i00;
1645  result->m10 = i10;
1646  result->m20 = i20;
1647  result->m30 = -(i00 * matrix->m30 + i10 * matrix->m31 + i20 * matrix->m32);
1648  result->m01 = i01;
1649  result->m11 = i11;
1650  result->m21 = i21;
1651  result->m31 = -(i01 * matrix->m30 + i11 * matrix->m31 + i21 * matrix->m32);
1652  result->m02 = i02;
1653  result->m12 = i12;
1654  result->m22 = i22;
1655  result->m32 = -(i02 * matrix->m30 + i12 * matrix->m31 + i22 * matrix->m32);
1656 }
1657 
1663 static __jo_force_inline void jo_matrixf_mul_pos(const jo_matrixf * const matrix, const jo_vectorf * const position,
1664  jo_vectorf * const result)
1665 {
1666  float w = matrix->m03 * position->x + matrix->m13 * position->y + matrix->m23 * position->z + matrix->m33;
1667  result->x = matrix->m00 * position->x + matrix->m10 * position->y + matrix->m20 * position->z + matrix->m30;
1668  result->y = matrix->m01 * position->x + matrix->m11 * position->y + matrix->m21 * position->z + matrix->m31;
1669  result->z = matrix->m02 * position->x + matrix->m12 * position->y + matrix->m22 * position->z + matrix->m32;
1670  if (w != 0 && w != 1)
1671  {
1672  result->x /= w;
1673  result->y /= w;
1674  result->z /= w;
1675  }
1676 }
1677 
1683 static __jo_force_inline void jo_matrixf_mul_dir(const jo_matrixf * const matrix, const jo_vectorf * const direction,
1684  jo_vectorf * const result)
1685 {
1686  float w = matrix->m03 * direction->x + matrix->m13 * direction->y + matrix->m23 * direction->z;
1687  result->x = matrix->m00 * direction->x + matrix->m10 * direction->y + matrix->m20 * direction->z;
1688  result->y = matrix->m01 * direction->x + matrix->m11 * direction->y + matrix->m21 * direction->z;
1689  result->z = matrix->m02 * direction->x + matrix->m12 * direction->y + matrix->m22 * direction->z;
1690  if (w != 0 && w != 1)
1691  {
1692  result->x /= w;
1693  result->y /= w;
1694  result->z /= w;
1695  }
1696 }
1697 
1698 /*
1699 ███╗ ███╗██╗███████╗ ██████╗
1700 ████╗ ████║██║██╔════╝██╔════╝
1701 ██╔████╔██║██║███████╗██║
1702 ██║╚██╔╝██║██║╚════██║██║
1703 ██║ ╚═╝ ██║██║███████║╚██████╗
1704 ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝
1705 
1706 */
1707 
1714 static __jo_force_inline jo_fixed jo_lerp(const jo_fixed v0, const jo_fixed v1, const jo_fixed t)
1715 {
1716  return (jo_fixed_mult((JO_FIXED_1 - t), v0) + jo_fixed_mult(t, v1));
1717 }
1718 
1723 static __jo_force_inline bool jo_is_float_equals_zero(const float f)
1724 {
1725  return (JO_ABS(f) < 0.00000001f);
1726 }
1727 
1739 static __jo_force_inline bool jo_square_intersect(const int x1, const int y1, const int w1, const int h1,
1740  const int x2, const int y2, const int w2, const int h2)
1741 {
1742  return ((x1 < x2 + w2) && (x2 < x1 + w1)) && ((y1 < y2 + h2) && (y2 < y1 + h1));
1743 }
1744 
1751 int jo_gcd(int a, int b);
1752 
1760 void jo_planar_rotate(const jo_pos2D * const point, const jo_pos2D * const origin, const int angle, jo_pos2D * const result);
1761 
1767 {
1768  switch (direction)
1769  {
1770  case LEFT:
1771  return (180);
1772  case RIGHT:
1773  return (0);
1774  case UP:
1775  return (270);
1776  case DOWN:
1777  return (90);
1778  case UP_LEFT:
1779  return (225);
1780  case UP_RIGHT:
1781  return (315);
1782  case DOWN_LEFT:
1783  return (135);
1784  case DOWN_RIGHT:
1785  return (45);
1786  default:
1787  return (0);
1788  }
1789 }
1790 
1791 #endif /* !__JO_MATH_H__ */
1792 
1793 /*
1794 ** END OF FILE
1795 */
1796 
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:1494
jo_sin_mult
static __jo_force_inline int jo_sin_mult(const int value, const int deg)
Fast sinus multiplication.
Definition: math.h:732
jo_sin_radf
static __jo_force_inline float jo_sin_radf(const float rad)
Sinus computation.
Definition: math.h:722
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:817
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:495
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:1351
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:978
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_DIV_BY_65536
#define JO_DIV_BY_65536(X)
Devide a variable by 65536.
Definition: math.h:192
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:1100
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:1228
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:1377
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:1313
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:629
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:522
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:692
jo_sin_rad
static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
Sinus computation.
Definition: math.h:712
jo_cos_radf
static __jo_force_inline float jo_cos_radf(const float rad)
Cosinus computation.
Definition: math.h:797
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:952
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:1429
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:1028
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:1005
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:1216
jo_cosf
static __jo_force_inline float jo_cosf(const int deg)
Cosinus computation.
Definition: math.h:777
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:1074
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:884
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:1261
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:1087
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:642
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:582
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:1469
jo_fixed_deg2ANGLE
static __jo_force_inline ANGLE jo_fixed_deg2ANGLE(const jo_fixed deg)
Convert fixed degree to SGL ANGLE.
Definition: math.h:668
__JO_DEG_TO_ANGLE_MAGIC
#define __JO_DEG_TO_ANGLE_MAGIC
See https://github.com/johannes-fetz/joengine/issues/42.
Definition: math.h:623
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:1739
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:513
jo_fixed_rad2ANGLE
static __jo_force_inline ANGLE jo_fixed_rad2ANGLE(const jo_fixed rad)
Convert fixed radian to SGL ANGLE.
Definition: math.h:657
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:1723
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:1518
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:767
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:1766
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:1289
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:1683
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:454
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:1404
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:1113
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:1301
jo_fixed2float
static __jo_force_inline float jo_fixed2float(const jo_fixed x)
Convert jo engine fixed to float.
Definition: math.h:434
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:1338
jo_atan2f
static __jo_force_inline int jo_atan2f(const float y, const float x)
Fast ATAN2 computation in degree.
Definition: math.h:913
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:1585
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:1183
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:1325
__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:866
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:1061
jo_tan
static __jo_force_inline jo_fixed jo_tan(const int deg)
Fast tangent computation.
Definition: math.h:836
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:1619
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:407
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:416
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:1246
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:1163
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:1139
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:1152
jo_cos_mult
static __jo_force_inline int jo_cos_mult(const int value, const int deg)
Fast cosinus multiplication.
Definition: math.h:807
jo_tanf
static __jo_force_inline float jo_tanf(const float deg)
Tangent computation.
Definition: math.h:846
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:1714
jo_sinf_mult
static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
Fast sinus multiplication.
Definition: math.h:742
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:992
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:1364
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:551
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:1277
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:504
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:702
jo_cos_rad
static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
Cosinus computation.
Definition: math.h:787
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:1173
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:443
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:1455
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:1663
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:425
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:1205
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:856
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:1018
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:1567
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:1126
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:1547
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:1390
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:965