Jo Engine  2020.06.22
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 (65536)
360 
361 # define JO_FIXED_2 (‭131072‬)
362 
363 # define JO_FIXED_4 (‭262144‬)
364 
365 # define JO_FIXED_8 (‭524288‬)
366 
367 # define JO_FIXED_16 (‭1048576‬)
368 
369 # define JO_FIXED_32 (2097152)
370 
371 # define JO_FIXED_120 (7864320)
372 
373 # define JO_FIXED_150 (9830400)
374 
375 # define JO_FIXED_180 (11796480)
376 
377 # define JO_FIXED_360 (23592960)
378 
380 # define JO_FIXED_MIN (-2147483647)
381 
382 # define JO_FIXED_MAX (2147483647)
383 
384 # define JO_FIXED_EPSILON (1)
385 
386 # define JO_FIXED_OVERFLOW (0x80000000)
387 
388 # define JO_FIXED_PI (205887)
389 
390 # define JO_FIXED_PI_2 (411775)
391 
392 # define JO_FIXED_180_DIV_PI (3754936)
393 
394 # define JO_FIXED_PI_DIV_180 (1144)
395 
396 # define JO_FIXED_PI_DIV_2 (102944)
397 
398 # define JO_FIXED_1_DIV (1.0f / 65536.0f)
399 
400 
406 {
407  return JO_MULT_BY_65536(x);
408 }
409 
415 {
416  return JO_DIV_BY_65536(x);
417 }
418 
424 {
425  return ((jo_fixed)(x * (float)JO_FIXED_1));
426 }
427 
433 {
434  return ((float)x * JO_FIXED_1_DIV);
435 }
436 
442 {
443  while (rad > JO_FIXED_PI) rad -= JO_FIXED_PI_2;
444  while (rad <= -JO_FIXED_PI) rad += JO_FIXED_PI_2;
445  return (rad);
446 }
447 
453 {
454  while (deg > JO_FIXED_180) deg -= JO_FIXED_360;
455  while (deg <= -JO_FIXED_PI) deg += JO_FIXED_360;
456  return (deg);
457 }
458 
465 
472 
480 
488 
494 {
496 }
497 
503 {
505 }
506 
507 /*
508 ██████╗ █████╗ ███╗ ██╗██████╗ ██████╗ ███╗ ███╗
509 ██╔══██╗██╔══██╗████╗ ██║██╔══██╗██╔═══██╗████╗ ████║
510 ██████╔╝███████║██╔██╗ ██║██║ ██║██║ ██║██╔████╔██║
511 ██╔══██╗██╔══██║██║╚██╗██║██║ ██║██║ ██║██║╚██╔╝██║
512 ██║ ██║██║ ██║██║ ╚████║██████╔╝╚██████╔╝██║ ╚═╝ ██║
513 ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝
514 */
515 
518 extern int jo_random_seed;
519 
524 int jo_random(int max);
525 
531 static __jo_force_inline int jo_random_using_multiple(int max, int multiple)
532 {
533  return (jo_random(max) / multiple) * multiple;
534 }
535 
536 /*
537 ███████╗ ██████╗ ██████╗ ████████╗
538 ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝
539 ███████╗██║ ██║██████╔╝ ██║
540 ╚════██║██║▄▄ ██║██╔══██╗ ██║
541 ███████║╚██████╔╝██║ ██║ ██║
542 ╚══════╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═╝
543 
544 */
545 
550 unsigned int jo_sqrt(unsigned int value);
551 
557 static __jo_force_inline float jo_sqrtf(float value)
558 {
559  unsigned int i = *(unsigned int*)(void *)&value;
560  i += 127 << 23;
561  i >>= 1;
562  return *(float*)(void *)&i;
563 }
564 
565 /*
566 ███████╗ ██████╗ ██╗ ██╗███╗ ██╗████████╗███████╗██████╗ ██████╗ ██████╗
567 ██╔════╝██╔════╝ ██║ ██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗██╔═══██╗██╔══██╗
568 ███████╗██║ ███╗██║ ██║██╔██╗ ██║ ██║ █████╗ ██████╔╝██║ ██║██████╔╝
569 ╚════██║██║ ██║██║ ██║██║╚██╗██║ ██║ ██╔══╝ ██╔══██╗██║ ██║██╔═══╝
570 ███████║╚██████╔╝███████╗ ██║██║ ╚████║ ██║ ███████╗██║ ██║╚██████╔╝██║
571 ╚══════╝ ╚═════╝ ╚══════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝
572 
573 */
574 
580 {
581  return (RADtoANG(jo_fixed2float(rad)));
582 }
583 
589 {
590  return (DEGtoANG(jo_fixed2float(deg)));
591 }
592 
593 /*
594 ███████╗██╗███╗ ██╗██╗ ██╗███████╗
595 ██╔════╝██║████╗ ██║██║ ██║██╔════╝
596 ███████╗██║██╔██╗ ██║██║ ██║███████╗
597 ╚════██║██║██║╚██╗██║██║ ██║╚════██║
598 ███████║██║██║ ╚████║╚██████╔╝███████║
599 ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
600 
601 */
602 
608 
613 static __jo_force_inline jo_fixed jo_sin(const int deg)
614 {
616 }
617 
623 static __jo_force_inline float jo_sinf(const int deg)
624 {
625  return (jo_fixed2float(jo_sin(deg)));
626 }
627 
633 static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
634 {
635  return (jo_fixed_sin(jo_float2fixed(rad)));
636 }
637 
643 static __jo_force_inline float jo_sin_radf(const float rad)
644 {
646 }
647 
653 static __jo_force_inline int jo_sin_mult(const int value, const int deg)
654 {
655  return (jo_fixed2int(value * jo_sin(deg)));
656 }
657 
663 static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
664 {
665  return (value * jo_sinf(deg));
666 }
667 
668 /*
669  ██████╗ ██████╗ ███████╗██╗███╗ ██╗██╗ ██╗███████╗
670 ██╔════╝██╔═══██╗██╔════╝██║████╗ ██║██║ ██║██╔════╝
671 ██║ ██║ ██║███████╗██║██╔██╗ ██║██║ ██║███████╗
672 ██║ ██║ ██║╚════██║██║██║╚██╗██║██║ ██║╚════██║
673 ╚██████╗╚██████╔╝███████║██║██║ ╚████║╚██████╔╝███████║
674  ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
675 
676 */
677 
683 {
684  return (jo_fixed_sin(rad + JO_FIXED_PI_DIV_2));
685 }
686 
691 static __jo_force_inline jo_fixed jo_cos(const int deg)
692 {
694 }
695 
701 static __jo_force_inline float jo_cosf(const int deg)
702 {
703  return (jo_fixed2float(jo_cos(deg)));
704 }
705 
711 static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
712 {
713  return (jo_fixed_cos(jo_float2fixed(rad)));
714 }
715 
721 static __jo_force_inline float jo_cos_radf(const float rad)
722 {
724 }
725 
731 static __jo_force_inline int jo_cos_mult(const int value, const int deg)
732 {
733  return (jo_fixed2int(value * jo_cos(deg)));
734 }
735 
741 static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
742 {
743  return (value * jo_cosf(deg));
744 }
745 
746 /*
747 ████████╗ █████╗ ███╗ ██╗ ██████╗ ███████╗███╗ ██╗████████╗
748 ╚══██╔══╝██╔══██╗████╗ ██║██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝
749  ██║ ███████║██╔██╗ ██║██║ ███╗█████╗ ██╔██╗ ██║ ██║
750  ██║ ██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██║╚██╗██║ ██║
751  ██║ ██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ╚████║ ██║
752  ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
753 
754 */
755 
760 static __jo_force_inline jo_fixed jo_tan(const int deg)
761 {
762  return (jo_sin(deg) / jo_cos(deg));
763 }
764 
770 static __jo_force_inline float jo_tanf(const float deg)
771 {
772  return (jo_sinf(deg) / jo_cosf(deg));
773 }
774 
780 static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
781 {
782  return (jo_sin_rad(rad) / jo_cos_rad(rad));
783 }
784 
790 static __jo_force_inline float jo_tan_radf(const float rad)
791 {
792  return (jo_sin_radf(rad) / jo_cos_radf(rad));
793 }
794 
795 /*
796  █████╗ ██████╗ ██████╗ ███████╗
797 ██╔══██╗██╔════╝██╔═══██╗██╔════╝
798 ███████║██║ ██║ ██║███████╗
799 ██╔══██║██║ ██║ ██║╚════██║
800 ██║ ██║╚██████╗╚██████╔╝███████║
801 ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝
802 */
803 
808 static __jo_force_inline float jo_acos_radf(const float angle)
809 {
810  return (3.14159f - 1.57079f * angle);
811 }
812 
813 /*
814  █████╗ ████████╗ █████╗ ███╗ ██╗██████╗
815 ██╔══██╗╚══██╔══╝██╔══██╗████╗ ██║╚════██╗
816 ███████║ ██║ ███████║██╔██╗ ██║ █████╔╝
817 ██╔══██║ ██║ ██╔══██║██║╚██╗██║██╔═══╝
818 ██║ ██║ ██║ ██║ ██║██║ ╚████║███████╗
819 ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝
820 
821 */
822 
829 float jo_atan2f_rad(const float y, const float x);
830 
837 static __jo_force_inline int jo_atan2f(const float y, const float x)
838 {
839  return (int)JO_RAD_TO_DEG(jo_atan2f_rad(y, x));
840 }
841 
842 /*
843 ██╗ ██╗███████╗ ██████╗████████╗ ██████╗ ██████╗
844 ██║ ██║██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗
845 ██║ ██║█████╗ ██║ ██║ ██║ ██║██████╔╝
846 ╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║ ██║██╔══██╗
847  ╚████╔╝ ███████╗╚██████╗ ██║ ╚██████╔╝██║ ██║
848  ╚═══╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
849 */
850 
851 /*
852  _______ __ _ __ __
853  / ____(_) _____ ____/ / / | / /_ ______ ___ / /_ ___ _____
854  / /_ / / |/_/ _ \/ __ / / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
855  / __/ / /> </ __/ /_/ / / /| / /_/ / / / / / / /_/ / __/ /
856 /_/ /_/_/|_|\___/\__,_/ /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
857 
858 */
859 
869 
876 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)
877 {
878  result->x = a->x + b->x;
879  result->y = a->y + b->y;
880  result->z = a->z + b->z;
881 }
882 
889 static __jo_force_inline void jo_vector_fixed_muls(const jo_vector_fixed * const a, const jo_fixed s, jo_vector_fixed * const result)
890 {
891  result->x = jo_fixed_mult(a->x, s);
892  result->y = jo_fixed_mult(a->y, s);
893  result->z = jo_fixed_mult(a->z, s);
894 }
895 
896 /*
897  ________ __ _ _ __ __
898  / ____/ /___ ____ _/ /_(_)___ ____ _ / | / /_ ______ ___ / /_ ___ _____
899  / /_ / / __ \/ __ `/ __/ / __ \/ __ `/ / |/ / / / / __ `__ \/ __ \/ _ \/ ___/
900  / __/ / / /_/ / /_/ / /_/ / / / / /_/ / / /| / /_/ / / / / / / /_/ / __/ /
901 /_/ /_/\____/\__,_/\__/_/_/ /_/\__, / /_/ |_/\__,_/_/ /_/ /_/_.___/\___/_/
902  /____/
903 */
904 
914 
921 static __jo_force_inline void jo_vectorf_add(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
922 {
923  result->x = a->x + b->x;
924  result->y = a->y + b->y;
925  result->z = a->z + b->z;
926 }
927 
934 static __jo_force_inline void jo_vectorf_adds(const jo_vectorf * const a, const float s, jo_vectorf * const result)
935 {
936  result->x = a->x + s;
937  result->y = a->y + s;
938  result->z = a->z + s;
939 }
940 
947 static __jo_force_inline void jo_vectorf_sub(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
948 {
949  result->x = a->x - b->x;
950  result->y = a->y - b->y;
951  result->z = a->z - b->z;
952 }
953 
960 static __jo_force_inline void jo_vectorf_subs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
961 {
962  result->x = a->x - s;
963  result->y = a->y - s;
964  result->z = a->z - s;
965 }
966 
973 static __jo_force_inline void jo_vectorf_mul(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
974 {
975  result->x = a->x * b->x;
976  result->y = a->y * b->y;
977  result->z = a->z * b->z;
978 }
979 
986 static __jo_force_inline void jo_vectorf_muls(const jo_vectorf * const a, const float s, jo_vectorf * const result)
987 {
988  result->x = a->x * s;
989  result->y = a->y * s;
990  result->z = a->z * s;
991 }
992 
999 static __jo_force_inline void jo_vectorf_div(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1000 {
1001  result->x = a->x / b->x;
1002  result->y = a->y / b->y;
1003  result->z = a->z / b->z;
1004 }
1005 
1012 static __jo_force_inline void jo_vectorf_divs(const jo_vectorf * const a, const float s, jo_vectorf * const result)
1013 {
1014  result->x = a->x / s;
1015  result->y = a->y / s;
1016  result->z = a->z / s;
1017 }
1018 
1023 static __jo_force_inline float jo_vectorf_length(const jo_vectorf * const a)
1024 {
1025  return (jo_sqrtf(JO_SQUARE(a->x) + JO_SQUARE(a->y) + JO_SQUARE(a->z)));
1026 }
1027 
1033 static __jo_force_inline float jo_vectorf_dot(const jo_vectorf * const a, const jo_vectorf * const b)
1034 {
1035  return (a->x * b->x + a->y * b->y + a->z * b->z);
1036 }
1037 
1043 static __jo_force_inline void jo_vectorf_normalize(const jo_vectorf * const a, jo_vectorf * const result)
1044 {
1045  float len = jo_vectorf_length(a);
1046  if (len > 0)
1047  {
1048  result->x = a->x / len;
1049  result->y = a->y / len;
1050  result->z = a->z / len;
1051  }
1052  else
1053  {
1054  result->x = 0;
1055  result->y = 0;
1056  result->z = 0;
1057  }
1058 }
1059 
1065 static __jo_force_inline void jo_vectorf_proj(const jo_vectorf * const v, const jo_vectorf * const onto, jo_vectorf * const result)
1066 {
1067  jo_vectorf_muls(onto, jo_vectorf_dot(v, onto) / jo_vectorf_dot(onto, onto), result);
1068 }
1069 
1076 static __jo_force_inline void jo_vectorf_cross(const jo_vectorf * const a, const jo_vectorf * const b, jo_vectorf * const result)
1077 {
1078  result->x = a->y * b->z - a->z * b->y;
1079  result->y = a->z * b->x - a->x * b->z;
1080  result->z = a->x * b->y - a->y * b->x;
1081 }
1082 
1088 static __jo_force_inline float jo_vectorf_angle_between_radf(const jo_vectorf * const a, const jo_vectorf * const b)
1089 {
1091 }
1092 
1093 /*
1094 ██╗ ██╗██╗ ██╗██╗ ██╗ ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
1095 ██║ ██║╚██╗██╔╝██║ ██║ ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
1096 ███████║ ╚███╔╝ ███████║ ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
1097 ╚════██║ ██╔██╗ ╚════██║ ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
1098  ██║██╔╝ ██╗ ██║ ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
1099  ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
1100 
1101 */
1102 
1107 {
1108  register int i;
1109 
1110  for (i = 1; i < 15; ++i)
1111  result->table[i] = 0;
1112  result->m00 = 1;
1113  result->m11 = 1;
1114  result->m22 = 1;
1115  result->m33 = 1;
1116 }
1117 
1122 static __jo_force_inline void jo_matrixf_translation(const jo_vectorf * const offset, jo_matrixf * const result)
1123 {
1124  jo_matrixf_identity(result);
1125  result->m30 = offset->x;
1126  result->m31 = offset->y;
1127  result->m32 = offset->z;
1128 }
1129 
1134 static __jo_force_inline void jo_matrixf_scaling(const jo_vectorf * const scale, jo_matrixf * const result)
1135 {
1136  jo_matrixf_identity(result);
1137  result->m00 = scale->x;
1138  result->m11 = scale->y;
1139  result->m22 = scale->z;
1140 }
1141 
1146 static __jo_force_inline void jo_matrixf_rotation_x_rad(const float angle_in_rad, jo_matrixf * const result)
1147 {
1148  jo_matrixf_identity(result);
1149  result->m11 = jo_cos_radf(angle_in_rad);
1150  result->m12 = jo_sin_radf(angle_in_rad);
1151  result->m21 = -result->m12;
1152  result->m22 = result->m11;
1153 }
1154 
1159 static __jo_force_inline void jo_matrixf_rotation_y_rad(const float angle_in_rad, jo_matrixf * const result)
1160 {
1161  jo_matrixf_identity(result);
1162  result->m00 = jo_cos_radf(angle_in_rad);
1163  result->m20 = jo_sin_radf(angle_in_rad);
1164  result->m02 = -result->m20;
1165  result->m22 = result->m00;
1166 }
1167 
1172 static __jo_force_inline void jo_matrixf_rotation_z_rad(const float angle_in_rad, jo_matrixf * const result)
1173 {
1174  jo_matrixf_identity(result);
1175  result->m00 = jo_cos_radf(angle_in_rad);
1176  result->m01 = jo_sin_radf(angle_in_rad);
1177  result->m10 = -result->m01;
1178  result->m11 = result->m00;
1179 }
1180 
1186 static __jo_force_inline void jo_matrixf_transpose(const jo_matrixf * const matrix, jo_matrixf * const result)
1187 {
1188  result->m00 = matrix->m00;
1189  result->m10 = matrix->m01;
1190  result->m20 = matrix->m02;
1191  result->m30 = matrix->m03;
1192  result->m01 = matrix->m10;
1193  result->m11 = matrix->m11;
1194  result->m21 = matrix->m12;
1195  result->m31 = matrix->m13;
1196  result->m02 = matrix->m20;
1197  result->m12 = matrix->m21;
1198  result->m22 = matrix->m22;
1199  result->m32 = matrix->m23;
1200  result->m03 = matrix->m30;
1201  result->m13 = matrix->m31;
1202  result->m23 = matrix->m32;
1203  result->m33 = matrix->m33;
1204 }
1205 
1212 static __jo_force_inline void jo_matrixf_mul(const jo_matrixf * const a, const jo_matrixf * const b, jo_matrixf * const result)
1213 {
1214  register int i;
1215  register int j;
1216  register int k;
1217  register float sum;
1218 
1219  for (i = 0; i < 4; ++i)
1220  {
1221  for (j = 0; j < 4; ++j)
1222  {
1223  sum = 0;
1224  for (k = 0; k < 4; ++k)
1225  sum += a->m[k][j] * b->m[i][k];
1226  result->m[i][j] = sum;
1227  }
1228  }
1229 }
1230 
1236 static __jo_force_inline void jo_matrixf_rotation(const float angle_in_rad, const jo_vectorf * const axis, jo_matrixf * const result)
1237 {
1238  jo_vectorf normalized_axis;
1239 
1240  jo_vectorf_normalize(axis, &normalized_axis);
1241  float c = jo_cos_radf(angle_in_rad);
1242  float s = jo_sin_radf(angle_in_rad);
1243  float a = 1 - c;
1244  jo_matrixf_identity(result);
1245  result->m00 = c + normalized_axis.x * normalized_axis.x * a;
1246  result->m10 = normalized_axis.x * normalized_axis.y * a - normalized_axis.z * s;
1247  result->m20 = normalized_axis.x * normalized_axis.z * a + normalized_axis.y * s;
1248  result->m01 = normalized_axis.y * normalized_axis.x * a + normalized_axis.z * s;
1249  result->m11 = c + normalized_axis.y * normalized_axis.y * a;
1250  result->m21 = normalized_axis.y * normalized_axis.z * a - normalized_axis.x * s;
1251  result->m02 = normalized_axis.z * normalized_axis.x * a - normalized_axis.y * s;
1252  result->m12 = normalized_axis.z * normalized_axis.y * a + normalized_axis.x * s;
1253  result->m22 = c + normalized_axis.z * normalized_axis.z * a;
1254 }
1255 
1265 static __jo_force_inline void jo_matrixf_ortho(const float left, const float right, const float bottom, const float top,
1266  const float back, const float front, jo_matrixf * const result)
1267 {
1268  jo_matrixf_identity(result);
1269  result->m00 = 2 / (right - left);
1270  result->m11 = 2 / (top - bottom);
1271  result->m22 = 2 / (back - front);
1272  result->m30 = -(right + left) / (right - left);
1273  result->m31 = -(top + bottom) / (top - bottom);
1274  result->m32 = -(back + front) / (back - front);
1275 }
1276 
1285 static __jo_force_inline void jo_matrixf_perspective(const float vertical_field_of_view_in_deg, const float aspect_ratio,
1286  const float near_view_distance, const float far_view_distance, jo_matrixf * const result)
1287 {
1288  jo_matrixf_identity(result);
1289  result->m11 = 1.0f / jo_tan_radf((vertical_field_of_view_in_deg / 180 * JO_PI) / 2.0f);
1290  result->m00 = result->m11 / aspect_ratio;
1291  result->m22 = (far_view_distance + near_view_distance) / (near_view_distance - far_view_distance);
1292  result->m32 = (2 * far_view_distance * near_view_distance) / (near_view_distance - far_view_distance);
1293  result->m23 = -1;
1294  result->m33 = 0;
1295 }
1296 
1303 static __jo_force_inline void jo_matrixf_look_at(const jo_vectorf * const from, const jo_vectorf * const to,
1304  const jo_vectorf * const up, jo_matrixf * const result)
1305 {
1306  jo_vectorf tmp;
1307  jo_vectorf x;
1308  jo_vectorf y;
1309  jo_vectorf z;
1310 
1311  jo_vectorf_sub(to, from, &tmp);
1312  jo_vectorf_normalize(&tmp, &tmp);
1313  jo_vectorf_muls(&tmp, -1, &z);
1314  jo_vectorf_cross(up, &z, &tmp);
1315  jo_vectorf_normalize(&tmp, &x);
1316  jo_vectorf_cross(&z, &x, &y);
1317 
1318  jo_matrixf_identity(result);
1319  result->m00 = x.x;
1320  result->m10 = x.y;
1321  result->m20 = x.z;
1322  result->m30 = -jo_vectorf_dot(from, &x);
1323  result->m01 = y.x;
1324  result->m11 = y.y;
1325  result->m21 = y.z;
1326  result->m31 = -jo_vectorf_dot(from, &y);
1327  result->m02 = z.x;
1328  result->m12 = z.y;
1329  result->m22 = z.z;
1330  result->m33 = -jo_vectorf_dot(from, &z);
1331 }
1332 
1337 static __jo_force_inline void jo_matrixf_invert_affine(const jo_matrixf * const matrix, jo_matrixf * const result)
1338 {
1339  float c00 = matrix->m11 * matrix->m22 - matrix->m12 * matrix->m21;
1340  float c10 = -(matrix->m01 * matrix->m22 - matrix->m02 * matrix->m21);
1341  float c20 = matrix->m01 * matrix->m12 - matrix->m02 * matrix->m11;
1342  float det = matrix->m00 * c00 + matrix->m10 * c10 + matrix->m20 * c20;
1343  jo_matrixf_identity(result);
1344  if (JO_FABS(det) < JO_FLOAT_EPSILON)
1345  return;
1346  float c01 = -(matrix->m10 * matrix->m22 - matrix->m12 * matrix->m20);
1347  float c11 = matrix->m00 * matrix->m22 - matrix->m02 * matrix->m20;
1348  float c21 = -(matrix->m00 * matrix->m12 - matrix->m02 * matrix->m10);
1349  float c02 = matrix->m10 * matrix->m21 - matrix->m11 * matrix->m20;
1350  float c12 = -(matrix->m00 * matrix->m21 - matrix->m01 * matrix->m20);
1351  float c22 = matrix->m00 * matrix->m11 - matrix->m01 * matrix->m10;
1352  float i00 = c00 / det;
1353  float i10 = c01 / det;
1354  float i20 = c02 / det;
1355  float i01 = c10 / det;
1356  float i11 = c11 / det;
1357  float i21 = c12 / det;
1358  float i02 = c20 / det;
1359  float i12 = c21 / det;
1360  float i22 = c22 / det;
1361 
1362  result->m00 = i00;
1363  result->m10 = i10;
1364  result->m20 = i20;
1365  result->m30 = -(i00 * matrix->m30 + i10 * matrix->m31 + i20 * matrix->m32);
1366  result->m01 = i01;
1367  result->m11 = i11;
1368  result->m21 = i21;
1369  result->m31 = -(i01 * matrix->m30 + i11 * matrix->m31 + i21 * matrix->m32);
1370  result->m02 = i02;
1371  result->m12 = i12;
1372  result->m22 = i22;
1373  result->m32 = -(i02 * matrix->m30 + i12 * matrix->m31 + i22 * matrix->m32);
1374 }
1375 
1381 static __jo_force_inline void jo_matrixf_mul_pos(const jo_matrixf * const matrix, const jo_vectorf * const position,
1382  jo_vectorf * const result)
1383 {
1384  float w = matrix->m03 * position->x + matrix->m13 * position->y + matrix->m23 * position->z + matrix->m33;
1385  result->x = matrix->m00 * position->x + matrix->m10 * position->y + matrix->m20 * position->z + matrix->m30;
1386  result->y = matrix->m01 * position->x + matrix->m11 * position->y + matrix->m21 * position->z + matrix->m31;
1387  result->z = matrix->m02 * position->x + matrix->m12 * position->y + matrix->m22 * position->z + matrix->m32;
1388  if (w != 0 && w != 1)
1389  {
1390  result->x /= w;
1391  result->y /= w;
1392  result->z /= w;
1393  }
1394 }
1395 
1401 static __jo_force_inline void jo_matrixf_mul_dir(const jo_matrixf * const matrix, const jo_vectorf * const direction,
1402  jo_vectorf * const result)
1403 {
1404  float w = matrix->m03 * direction->x + matrix->m13 * direction->y + matrix->m23 * direction->z;
1405  result->x = matrix->m00 * direction->x + matrix->m10 * direction->y + matrix->m20 * direction->z;
1406  result->y = matrix->m01 * direction->x + matrix->m11 * direction->y + matrix->m21 * direction->z;
1407  result->z = matrix->m02 * direction->x + matrix->m12 * direction->y + matrix->m22 * direction->z;
1408  if (w != 0 && w != 1)
1409  {
1410  result->x /= w;
1411  result->y /= w;
1412  result->z /= w;
1413  }
1414 }
1415 
1416 /*
1417 ███╗ ███╗██╗███████╗ ██████╗
1418 ████╗ ████║██║██╔════╝██╔════╝
1419 ██╔████╔██║██║███████╗██║
1420 ██║╚██╔╝██║██║╚════██║██║
1421 ██║ ╚═╝ ██║██║███████║╚██████╗
1422 ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝
1423 
1424 */
1425 
1430 static __jo_force_inline bool jo_is_float_equals_zero(const float f)
1431 {
1432  return (JO_ABS(f) < 0.00000001f);
1433 }
1434 
1446 static __jo_force_inline bool jo_square_intersect(const int x1, const int y1, const int w1, const int h1,
1447  const int x2, const int y2, const int w2, const int h2)
1448 {
1449  return ((x1 < x2 + w2) && (x2 < x1 + w1)) && ((y1 < y2 + h2) && (y2 < y1 + h1));
1450 }
1451 
1458 int jo_gcd(int a, int b);
1459 
1467 void jo_planar_rotate(const jo_pos2D * const point, const jo_pos2D * const origin, const int angle, jo_pos2D * const result);
1468 
1474 {
1475  switch (direction)
1476  {
1477  case LEFT:
1478  return (180);
1479  case RIGHT:
1480  return (0);
1481  case UP:
1482  return (270);
1483  case DOWN:
1484  return (90);
1485  case UP_LEFT:
1486  return (225);
1487  case UP_RIGHT:
1488  return (315);
1489  case DOWN_LEFT:
1490  return (135);
1491  case DOWN_RIGHT:
1492  return (45);
1493  default:
1494  return (0);
1495  }
1496 }
1497 
1498 #endif /* !__JO_MATH_H__ */
1499 
1500 /*
1501 ** END OF FILE
1502 */
1503 
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:1212
jo_sin_mult
static __jo_force_inline int jo_sin_mult(const int value, const int deg)
Fast sinus multiplication.
Definition: math.h:653
jo_sin_radf
static __jo_force_inline float jo_sin_radf(const float rad)
Sinus computation.
Definition: math.h:643
jo_cosf_mult
static __jo_force_inline float jo_cosf_mult(const float value, const int deg)
Fast cosinus multiplication.
Definition: math.h:741
jo_gcd
int jo_gcd(int a, int b)
Get the greatest common divisor.
RIGHT
@ RIGHT
Definition: types.h:286
JO_FIXED_360
#define JO_FIXED_360
Fixed floating point value for 360.
Definition: math.h:377
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:493
UP_RIGHT
@ UP_RIGHT
Definition: types.h:290
jo_vectorf::y
float y
Definition: types.h:131
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:960
JO_FIXED_180
#define JO_FIXED_180
Fixed floating point value for 180.
Definition: math.h:375
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:1088
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:1134
JO_FIXED_PI_DIV_2
#define JO_FIXED_PI_DIV_2
Fixed value of PI/2.
Definition: math.h:396
UP_LEFT
@ UP_LEFT
Definition: types.h:289
jo_vectorf::z
float z
Definition: types.h:132
jo_sin
static __jo_force_inline jo_fixed jo_sin(const int deg)
Fast sinus computation.
Definition: math.h:613
jo_sin_rad
static __jo_force_inline jo_fixed jo_sin_rad(const float rad)
Sinus computation.
Definition: math.h:633
jo_cos_radf
static __jo_force_inline float jo_cos_radf(const float rad)
Cosinus computation.
Definition: math.h:721
DOWN_RIGHT
@ DOWN_RIGHT
Definition: types.h:292
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:876
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:1186
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:1076
jo_cosf
static __jo_force_inline float jo_cosf(const int deg)
Cosinus computation.
Definition: math.h:701
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:934
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
jo_acos_radf
static __jo_force_inline float jo_acos_radf(const float angle)
Fast Arc Cosinus computation.
Definition: math.h:808
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:1106
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:947
UP
@ UP
Definition: types.h:287
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:557
jo_fixed_deg2ANGLE
static __jo_force_inline ANGLE jo_fixed_deg2ANGLE(const jo_fixed deg)
Convert fixed degree to SGL ANGLE.
Definition: math.h:588
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:1446
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_rad2ANGLE
static __jo_force_inline ANGLE jo_fixed_rad2ANGLE(const jo_fixed rad)
Convert fixed radian to SGL ANGLE.
Definition: math.h:579
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:1430
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:1236
jo_matrixf::table
float table[16]
Definition: types.h:155
jo_cos
static __jo_force_inline jo_fixed jo_cos(const int deg)
Fast cosinus computation.
Definition: math.h:691
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:1473
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:1122
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:1401
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:452
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:973
jo_fixed2float
static __jo_force_inline float jo_fixed2float(const jo_fixed x)
Convert jo engine fixed to float.
Definition: math.h:432
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:1146
jo_atan2f
static __jo_force_inline int jo_atan2f(const float y, const float x)
Fast ATAN2 computation in degree.
Definition: math.h:837
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:1303
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:1043
jo_tan_radf
static __jo_force_inline float jo_tan_radf(const float rad)
Tangent computation.
Definition: math.h:790
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:921
jo_tan
static __jo_force_inline jo_fixed jo_tan(const int deg)
Fast tangent computation.
Definition: math.h:760
jo_fixed
int jo_fixed
Fixed point Q16.16 number.
Definition: types.h:46
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:1337
JO_FIXED_PI_2
#define JO_FIXED_PI_2
Fixed value of 2 PI.
Definition: math.h:390
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:405
JO_FIXED_PI
#define JO_FIXED_PI
Fixed value of PI.
Definition: math.h:388
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:147
jo_fixed2int
static __jo_force_inline int jo_fixed2int(const jo_fixed x)
Convert jo engine fixed to int.
Definition: math.h:414
jo_vectorf::x
float x
Definition: types.h:130
JO_FIXED_PI_DIV_180
#define JO_FIXED_PI_DIV_180
Fixed value of PI/180.
Definition: math.h:394
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:1023
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:999
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:1012
jo_cos_mult
static __jo_force_inline int jo_cos_mult(const int value, const int deg)
Fast cosinus multiplication.
Definition: math.h:731
jo_tanf
static __jo_force_inline float jo_tanf(const float deg)
Tangent computation.
Definition: math.h:770
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_sinf_mult
static __jo_force_inline float jo_sinf_mult(const float value, const int deg)
Fast sinus multiplication.
Definition: math.h:663
DOWN
@ DOWN
Definition: types.h:288
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:1159
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:531
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:502
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:153
jo_matrixf::m
float m[4][4]
Definition: types.h:154
jo_fixed_cos
static __jo_force_inline jo_fixed jo_fixed_cos(jo_fixed rad)
Fast cosinus computation using fixed number.
Definition: math.h:682
jo_sinf
static __jo_force_inline float jo_sinf(const int deg)
Sinus computation.
Definition: math.h:623
jo_cos_rad
static __jo_force_inline jo_fixed jo_cos_rad(const float rad)
Cosinus computation.
Definition: math.h:711
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:1033
jo_8_directions
jo_8_directions
8 directions definition
Definition: types.h:283
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:441
jo_pos2D
2D position
Definition: types.h:50
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:291
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:1381
JO_FIXED_1_DIV
#define JO_FIXED_1_DIV
Fixed value of 1/65536.
Definition: math.h:398
JO_FIXED_1
#define JO_FIXED_1
Fixed floating point value for 1.
Definition: math.h:359
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:423
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:1065
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:129
jo_tan_rad
static __jo_force_inline jo_fixed jo_tan_rad(const float rad)
Tangent computation.
Definition: math.h:780
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:1285
JO_FIXED_180_DIV_PI
#define JO_FIXED_180_DIV_PI
Fixed value of 180/PI.
Definition: math.h:392
LEFT
@ LEFT
Definition: types.h:285
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:986
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:1265
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:1172
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:889