16#ifndef AEONGAMES_MATH_H
17#define AEONGAMES_MATH_H
52constexpr float PI = M_PI;
54constexpr float TWOPI = M_PI * 2;
56constexpr float PIOVER180 = M_PI / 180.0f;
58constexpr float ONE80OVERPI = 180 / M_PI;
60const float FLT_TOLERANCE = std::sqrt ( FLT_EPSILON );
73inline float DEG2RAD (
float deg )
75 return PIOVER180 * deg;
81inline float RAD2DEG (
float rad )
83 return ONE80OVERPI * rad;
92inline float sabs (
float x )
94 return x < 0 ? -x : x;
106inline float*
Cross3 (
float* v1,
float* v2,
float* dst )
109 r[0] = ( ( v1[1] * v2[2] ) - ( v1[2] * v2[1] ) );
110 r[1] = ( ( v1[2] * v2[0] ) - ( v1[0] * v2[2] ) );
111 r[2] = ( ( v1[0] * v2[1] ) - ( v1[1] * v2[0] ) );
112 memcpy ( dst, r,
sizeof (
float ) * 3 );
120inline float Length (
float const *
const v )
122 return (
float ) sqrtf ( ( v[0] * v[0] ) + ( v[1] * v[1] ) + ( v[2] * v[2] ) );
131 return (
float ) sqrtf ( ( v[0] * v[0] ) + ( v[1] * v[1] ) + ( v[2] * v[2] ) + ( v[3] * v[3] ) );
139inline float Dot (
const float v1[],
const float v2[] )
141 return (
float ) ( v1[0] * v2[0] ) + ( v1[1] * v2[1] ) + ( v1[2] * v2[2] );
149inline float Dot4 (
const float v1[],
const float v2[] )
151 return (
float ) ( v1[0] * v2[0] ) + ( v1[1] * v2[1] ) + ( v1[2] * v2[2] ) + ( v1[3] * v2[3] );
160 float length =
Length ( v );
181 float oneoverlength = 1.0f / length;
182 v[0] *= oneoverlength;
183 v[1] *= oneoverlength;
184 v[2] *= oneoverlength;
185 v[3] *= oneoverlength;
197 float length =
Length ( aPlane );
201 aOut[0] = aPlane[0] / length;
202 aOut[1] = aPlane[1] / length;
203 aOut[2] = aPlane[2] / length;
204 aOut[3] = aPlane[3] / length;
212inline float*
Add4 (
float* v1,
float* v2,
float* out )
214 out[0] = v1[0] + v2[0];
215 out[1] = v1[1] + v2[1];
216 out[2] = v1[2] + v2[2];
217 out[3] = v1[3] + v2[3];
223inline float*
Subtract4 (
float* v1,
float* v2,
float* out )
225 out[0] = v1[0] - v2[0];
226 out[1] = v1[1] - v2[1];
227 out[2] = v1[2] - v2[2];
228 out[3] = v1[3] - v2[3];
260 backoff *= overbounce;
264 backoff /= overbounce;
266 for ( i = 0 ; i < 3 ; i++ )
268 change = normal[i] * backoff;
269 v[i] = v[i] - change;
284 int axis = ( a[0] =
sabs ( v[0] ) ) < ( a[1] =
sabs ( v[1] ) ) ? 1 : 0;
285 return a[axis] <
sabs ( v[2] ) ? 2 : axis;
301 localout[0] = v1[0] + ( ( v2[0] - v1[0] ) * interpolation );
302 localout[1] = v1[1] + ( ( v2[1] - v1[1] ) * interpolation );
303 localout[2] = v1[2] + ( ( v2[2] - v1[2] ) * interpolation );
304 out[0] = localout[0];
305 out[1] = localout[1];
306 out[2] = localout[2];
318 float v[3] = {b[0] - a[0], b[1] - a[1], b[2] - a[2]};
319 return ( v[0] * v[0] ) + ( v[1] * v[1] ) + ( v[2] * v[2] );
329inline float Distance (
const float a[],
const float b[] )
343 float vc[3] = {v[0], v[1], v[2]};
344 out[0] = vc[0] * m[0] + vc[1] * m[4] + vc[2] * m[ 8] + m[12];
345 out[1] = vc[0] * m[1] + vc[1] * m[5] + vc[2] * m[ 9] + m[13];
346 out[2] = vc[0] * m[2] + vc[1] * m[6] + vc[2] * m[10] + m[14];
373 float vc[3] = {v[0], v[1], v[2]};
374 out[0] = vc[0] * m[0] + vc[1] * m[4] + vc[2] * m[ 8];
375 out[1] = vc[0] * m[1] + vc[1] * m[5] + vc[2] * m[ 9];
376 out[2] = vc[0] * m[2] + vc[1] * m[6] + vc[2] * m[10];
382 out[0] = 1.0f / v[0];
383 out[1] = 1.0f / v[1];
384 out[2] = 1.0f / v[2];
412 M[0] = M[5] = M[10] = M[15] = 1.0f;
413 M[1] = M[2] = M[3] = M[4] = M[6] = M[7] = M[8] = M[9] = M[11] = M[12] = M[13] = M[14] = 0.0f;
504 for (
int i = 0; i < 3; i++ )
507 tmp[i + 3] = src[i * 3 + 1];
508 tmp[i + 6] = src[i * 3 + 2];
510 memcpy ( dst, tmp,
sizeof (
float ) * 9 );
520 float A = src[4] * src[8] - src[5] * src[7];
521 float B = - ( src[3] * src[8] - src[5] * src[6] );
522 float C = ( src[3] * src[7] - src[4] * src[6] );
523 return src[0] * A + src[1] * B + src[2] * C;
532 float A = src[4] * src[8] - src[5] * src[7];
533 float B = - ( src[3] * src[8] - src[5] * src[6] );
534 float C = ( src[3] * src[7] - src[4] * src[6] );
535 float determinant = src[0] * A + src[1] * B + src[2] * C;
536 if ( determinant != 0.0f )
538 float D = - ( src[1] * src[8] - src[2] * src[7] );
539 float E = src[0] * src[8] - src[2] * src[6];
540 float F = - ( src[0] * src[7] - src[1] * src[6] );
541 float G = src[1] * src[5] - src[2] * src[4];
542 float H = - ( src[0] * src[5] - src[2] * src[3] );
543 float I = src[0] * src[4] - src[1] * src[3];
544 dst[0] = A / determinant;
545 dst[3] = B / determinant;
546 dst[6] = C / determinant;
547 dst[1] = D / determinant;
548 dst[4] = E / determinant;
549 dst[7] = F / determinant;
550 dst[2] = G / determinant;
551 dst[5] = H / determinant;
552 dst[8] = I / determinant;
611 src[ 0], src[ 4], src[ 8], 0.0f,
612 src[ 1], src[ 5], src[ 9], 0.0f,
613 src[ 2], src[ 6], src[10], 0.0f,
614 - ( src[12]*src[ 0] + src[13]*src[ 1] + src[14]*src[ 2] ),
615 - ( src[12]*src[ 4] + src[13]*src[ 5] + src[14]*src[ 6] ),
616 - ( src[12]*src[ 8] + src[13]*src[ 9] + src[14]*src[ 10] ),
620 memcpy ( dst, tmp,
sizeof (
float ) * 16 );
640 memcpy ( dst, dest,
sizeof (
float ) * 16 );
645 for (
int i = 0; i < 4; i++ )
648 src[i + 4] = mat[i * 4 + 1];
649 src[i + 8] = mat[i * 4 + 2];
650 src[i + 12] = mat[i * 4 + 3];
653 tmp[0] = src[10] * src[15];
654 tmp[1] = src[11] * src[14];
655 tmp[2] = src[9] * src[15];
656 tmp[3] = src[11] * src[13];
657 tmp[4] = src[9] * src[14];
658 tmp[5] = src[10] * src[13];
659 tmp[6] = src[8] * src[15];
660 tmp[7] = src[11] * src[12];
661 tmp[8] = src[8] * src[14];
662 tmp[9] = src[10] * src[12];
663 tmp[10] = src[8] * src[13];
664 tmp[11] = src[9] * src[12];
666 dst[0] = tmp[0] * src[5] + tmp[3] * src[6] + tmp[4] * src[7];
667 dst[0] -= tmp[1] * src[5] + tmp[2] * src[6] + tmp[5] * src[7];
668 dst[1] = tmp[1] * src[4] + tmp[6] * src[6] + tmp[9] * src[7];
669 dst[1] -= tmp[0] * src[4] + tmp[7] * src[6] + tmp[8] * src[7];
670 dst[2] = tmp[2] * src[4] + tmp[7] * src[5] + tmp[10] * src[7];
671 dst[2] -= tmp[3] * src[4] + tmp[6] * src[5] + tmp[11] * src[7];
672 dst[3] = tmp[5] * src[4] + tmp[8] * src[5] + tmp[11] * src[6];
673 dst[3] -= tmp[4] * src[4] + tmp[9] * src[5] + tmp[10] * src[6];
674 dst[4] = tmp[1] * src[1] + tmp[2] * src[2] + tmp[5] * src[3];
675 dst[4] -= tmp[0] * src[1] + tmp[3] * src[2] + tmp[4] * src[3];
676 dst[5] = tmp[0] * src[0] + tmp[7] * src[2] + tmp[8] * src[3];
677 dst[5] -= tmp[1] * src[0] + tmp[6] * src[2] + tmp[9] * src[3];
678 dst[6] = tmp[3] * src[0] + tmp[6] * src[1] + tmp[11] * src[3];
679 dst[6] -= tmp[2] * src[0] + tmp[7] * src[1] + tmp[10] * src[3];
680 dst[7] = tmp[4] * src[0] + tmp[9] * src[1] + tmp[10] * src[2];
681 dst[7] -= tmp[5] * src[0] + tmp[8] * src[1] + tmp[11] * src[2];
683 tmp[0] = src[2] * src[7];
684 tmp[1] = src[3] * src[6];
685 tmp[2] = src[1] * src[7];
686 tmp[3] = src[3] * src[5];
687 tmp[4] = src[1] * src[6];
688 tmp[5] = src[2] * src[5];
689 tmp[6] = src[0] * src[7];
690 tmp[7] = src[3] * src[4];
691 tmp[8] = src[0] * src[6];
692 tmp[9] = src[2] * src[4];
693 tmp[10] = src[0] * src[5];
694 tmp[11] = src[1] * src[4];
696 dst[8] = tmp[0] * src[13] + tmp[3] * src[14] + tmp[4] * src[15];
697 dst[8] -= tmp[1] * src[13] + tmp[2] * src[14] + tmp[5] * src[15];
698 dst[9] = tmp[1] * src[12] + tmp[6] * src[14] + tmp[9] * src[15];
699 dst[9] -= tmp[0] * src[12] + tmp[7] * src[14] + tmp[8] * src[15];
700 dst[10] = tmp[2] * src[12] + tmp[7] * src[13] + tmp[10] * src[15];
701 dst[10] -= tmp[3] * src[12] + tmp[6] * src[13] + tmp[11] * src[15];
702 dst[11] = tmp[5] * src[12] + tmp[8] * src[13] + tmp[11] * src[14];
703 dst[11] -= tmp[4] * src[12] + tmp[9] * src[13] + tmp[10] * src[14];
704 dst[12] = tmp[2] * src[10] + tmp[5] * src[11] + tmp[1] * src[9];
705 dst[12] -= tmp[4] * src[11] + tmp[0] * src[9] + tmp[3] * src[10];
706 dst[13] = tmp[8] * src[11] + tmp[0] * src[8] + tmp[7] * src[10];
707 dst[13] -= tmp[6] * src[10] + tmp[9] * src[11] + tmp[1] * src[8];
708 dst[14] = tmp[6] * src[9] + tmp[11] * src[11] + tmp[3] * src[8];
709 dst[14] -= tmp[10] * src[11] + tmp[2] * src[8] + tmp[7] * src[9];
710 dst[15] = tmp[10] * src[10] + tmp[4] * src[8] + tmp[9] * src[9];
711 dst[15] -= tmp[8] * src[9] + tmp[11] * src[10] + tmp[5] * src[8];
713 det = src[0] * dst[0] + src[1] * dst[1] + src[2] * dst[2] + src[3] * dst[3];
716 for (
float & j : dst )
720 memcpy ( dest, dst,
sizeof (
float ) * 16 );
737inline float* Multiply4x4Matrix (
const float* A,
const float* B,
float* out )
742 memcpy ( mx1, A,
sizeof (
float ) * 16 );
743 memcpy ( mx2, B,
sizeof (
float ) * 16 );
751 "movss %0,%%xmm4\n\t"
752 "shufps $0x0,%%xmm4,%%xmm4\n\t"
753 "movups %1,%%xmm0\n\t"
754 "mulps %%xmm4,%%xmm0\n\t"
756 "movss 4%0,%%xmm4\n\t"
757 "shufps $0x0,%%xmm4,%%xmm4\n\t"
758 "movups 16%1,%%xmm1\n\t"
759 "mulps %%xmm4,%%xmm1\n\t"
761 "movss 8%0,%%xmm4\n\t"
762 "shufps $0x0,%%xmm4,%%xmm4\n\t"
763 "movups 32%1,%%xmm2\n\t"
764 "mulps %%xmm4,%%xmm2\n\t"
766 "movss 12%0,%%xmm4\n\t"
767 "shufps $0x0,%%xmm4,%%xmm4\n\t"
768 "movups 48%1,%%xmm3\n\t"
769 "mulps %%xmm4,%%xmm3\n\t"
771 "addps %%xmm1,%%xmm0\n\t"
772 "addps %%xmm2,%%xmm0\n\t"
773 "addps %%xmm3,%%xmm0\n\t"
774 "movups %%xmm0,%2\n\t"
776 "movss 16%0,%%xmm4\n\t"
777 "shufps $0x0,%%xmm4,%%xmm4\n\t"
778 "movups %1,%%xmm0\n\t"
779 "mulps %%xmm4,%%xmm0\n\t"
781 "movss 20%0,%%xmm4\n\t"
782 "shufps $0x0,%%xmm4,%%xmm4\n\t"
783 "movups 16%1,%%xmm1\n\t"
784 "mulps %%xmm4,%%xmm1\n\t"
786 "movss 24%0,%%xmm4\n\t"
787 "shufps $0x0,%%xmm4,%%xmm4\n\t"
788 "movups 32%1,%%xmm2\n\t"
789 "mulps %%xmm4,%%xmm2\n\t"
791 "movss 28%0,%%xmm4\n\t"
792 "shufps $0x0,%%xmm4,%%xmm4\n\t"
793 "movups 48%1,%%xmm3\n\t"
794 "mulps %%xmm4,%%xmm3\n\t"
796 "addps %%xmm1,%%xmm0\n\t"
797 "addps %%xmm2,%%xmm0\n\t"
798 "addps %%xmm3,%%xmm0\n\t"
799 "movups %%xmm0,16%2\n\t"
801 "movss 32%0,%%xmm4\n\t"
802 "shufps $0x0,%%xmm4,%%xmm4\n\t"
803 "movups %1,%%xmm0\n\t"
804 "mulps %%xmm4,%%xmm0\n\t"
806 "movss 36%0,%%xmm4\n\t"
807 "shufps $0x0,%%xmm4,%%xmm4\n\t"
808 "movups 16%1,%%xmm1\n\t"
809 "mulps %%xmm4,%%xmm1\n\t"
811 "movss 40%0,%%xmm4\n\t"
812 "shufps $0x0,%%xmm4,%%xmm4\n\t"
813 "movups 32%1,%%xmm2\n\t"
814 "mulps %%xmm4,%%xmm2\n\t"
816 "movss 44%0,%%xmm4\n\t"
817 "shufps $0x0,%%xmm4,%%xmm4\n\t"
818 "movups 48%1,%%xmm3\n\t"
819 "mulps %%xmm4,%%xmm3\n\t"
821 "addps %%xmm1,%%xmm0\n\t"
822 "addps %%xmm2,%%xmm0\n\t"
823 "addps %%xmm3,%%xmm0\n\t"
824 "movups %%xmm0,32%2\n\t"
826 "movss 48%0,%%xmm4\n\t"
827 "shufps $0x0,%%xmm4,%%xmm4\n\t"
828 "movups %1,%%xmm0\n\t"
829 "mulps %%xmm4,%%xmm0\n\t"
831 "movss 52%0,%%xmm4\n\t"
832 "shufps $0x0,%%xmm4,%%xmm4\n\t"
833 "movups 16%1,%%xmm1\n\t"
834 "mulps %%xmm4,%%xmm1\n\t"
836 "movss 56%0,%%xmm4\n\t"
837 "shufps $0x0,%%xmm4,%%xmm4\n\t"
838 "movups 32%1,%%xmm2\n\t"
839 "mulps %%xmm4,%%xmm2\n\t"
841 "movss 60%0,%%xmm4\n\t"
842 "shufps $0x0,%%xmm4,%%xmm4\n\t"
843 "movups 48%1,%%xmm3\n\t"
844 "mulps %%xmm4,%%xmm3\n\t"
846 "addps %%xmm1,%%xmm0\n\t"
847 "addps %%xmm2,%%xmm0\n\t"
848 "addps %%xmm3,%%xmm0\n\t"
849 "movups %%xmm0,48%2\n\t"
851 :
"m" ( mx[0] ),
"m" ( m2[0] ),
"m" ( result[0] )
852 :
"%xmm0",
"%xmm1",
"%xmm2",
"%xmm3",
"%xmm4"
863 lea eax, [eax]this.mx
874 movups xmm1, [ecx+16]
879 movups xmm2, [ecx+32]
882 movss xmm4, [eax+ 12]
884 movups xmm3, [ecx+48]
892 movss xmm4, [eax+ 16]
897 movss xmm4, [eax+ 20]
899 movups xmm1, [ecx+16]
902 movss xmm4, [eax+ 24]
904 movups xmm2, [ecx+32]
907 movss xmm4, [eax+ 28]
909 movups xmm3, [ecx+48]
915 movups [edx+16], xmm0
917 movss xmm4, [eax+ 32]
922 movss xmm4, [eax+ 36]
924 movups xmm1, [ecx+16]
927 movss xmm4, [eax+ 40]
929 movups xmm2, [ecx+32]
932 movss xmm4, [eax+ 44]
934 movups xmm3, [ecx+48]
940 movups [edx+32], xmm0
942 movss xmm4, [eax+ 48]
947 movss xmm4, [eax+ 52]
949 movups xmm1, [ecx+16]
952 movss xmm4, [eax+ 56]
954 movups xmm2, [ecx+32]
957 movss xmm4, [eax+ 60]
959 movups xmm3, [ecx+48]
965 movups [edx+48], xmm0
978 result[ 0] = mx1[ 0] * mx2[ 0] + mx1[ 1] * mx2[ 4] + mx1[ 2] * mx2[ 8] + mx1[ 3] * mx2[12];
979 result[ 1] = mx1[ 0] * mx2[ 1] + mx1[ 1] * mx2[ 5] + mx1[ 2] * mx2[ 9] + mx1[ 3] * mx2[13];
980 result[ 2] = mx1[ 0] * mx2[ 2] + mx1[ 1] * mx2[ 6] + mx1[ 2] * mx2[10] + mx1[ 3] * mx2[14];
981 result[ 3] = mx1[ 0] * mx2[ 3] + mx1[ 1] * mx2[ 7] + mx1[ 2] * mx2[11] + mx1[ 3] * mx2[15];
983 result[ 4] = mx1[ 4] * mx2[ 0] + mx1[ 5] * mx2[ 4] + mx1[ 6] * mx2[ 8] + mx1[ 7] * mx2[12];
984 result[ 5] = mx1[ 4] * mx2[ 1] + mx1[ 5] * mx2[ 5] + mx1[ 6] * mx2[ 9] + mx1[ 7] * mx2[13];
985 result[ 6] = mx1[ 4] * mx2[ 2] + mx1[ 5] * mx2[ 6] + mx1[ 6] * mx2[10] + mx1[ 7] * mx2[14];
986 result[ 7] = mx1[ 4] * mx2[ 3] + mx1[ 5] * mx2[ 7] + mx1[ 6] * mx2[11] + mx1[ 7] * mx2[15];
988 result[ 8] = mx1[ 8] * mx2[ 0] + mx1[ 9] * mx2[ 4] + mx1[10] * mx2[ 8] + mx1[11] * mx2[12];
989 result[ 9] = mx1[ 8] * mx2[ 1] + mx1[ 9] * mx2[ 5] + mx1[10] * mx2[ 9] + mx1[11] * mx2[13];
990 result[10] = mx1[ 8] * mx2[ 2] + mx1[ 9] * mx2[ 6] + mx1[10] * mx2[10] + mx1[11] * mx2[14];
991 result[11] = mx1[ 8] * mx2[ 3] + mx1[ 9] * mx2[ 7] + mx1[10] * mx2[11] + mx1[11] * mx2[15];
993 result[12] = mx1[12] * mx2[ 0] + mx1[13] * mx2[ 4] + mx1[14] * mx2[ 8] + mx1[15] * mx2[12];
994 result[13] = mx1[12] * mx2[ 1] + mx1[13] * mx2[ 5] + mx1[14] * mx2[ 9] + mx1[15] * mx2[13];
995 result[14] = mx1[12] * mx2[ 2] + mx1[13] * mx2[ 6] + mx1[14] * mx2[10] + mx1[15] * mx2[14];
996 result[15] = mx1[12] * mx2[ 3] + mx1[13] * mx2[ 7] + mx1[14] * mx2[11] + mx1[15] * mx2[15];
1002 result[ 0] = mx1[ 0] * mx2[ 0] + mx1[ 4] * mx2[ 1] + mx1[ 8] * mx2[ 2] + mx1[12] * mx2[ 3];
1003 result[ 1] = mx1[ 1] * mx2[ 0] + mx1[ 5] * mx2[ 1] + mx1[ 9] * mx2[ 2] + mx1[13] * mx2[ 3];
1004 result[ 2] = mx1[ 2] * mx2[ 0] + mx1[ 6] * mx2[ 1] + mx1[10] * mx2[ 2] + mx1[14] * mx2[ 3];
1005 result[ 3] = mx1[ 3] * mx2[ 0] + mx1[ 7] * mx2[ 1] + mx1[11] * mx2[ 2] + mx1[15] * mx2[ 3];
1007 result[ 4] = mx1[ 0] * mx2[ 4] + mx1[ 4] * mx2[ 5] + mx1[ 8] * mx2[ 6] + mx1[12] * mx2[ 7];
1008 result[ 5] = mx1[ 1] * mx2[ 4] + mx1[ 5] * mx2[ 5] + mx1[ 9] * mx2[ 6] + mx1[13] * mx2[ 7];
1009 result[ 6] = mx1[ 2] * mx2[ 4] + mx1[ 6] * mx2[ 5] + mx1[10] * mx2[ 6] + mx1[14] * mx2[ 7];
1010 result[ 7] = mx1[ 3] * mx2[ 4] + mx1[ 7] * mx2[ 5] + mx1[11] * mx2[ 6] + mx1[15] * mx2[ 7];
1012 result[ 8] = mx1[ 0] * mx2[ 8] + mx1[ 4] * mx2[ 9] + mx1[ 8] * mx2[10] + mx1[12] * mx2[11];
1013 result[ 9] = mx1[ 1] * mx2[ 8] + mx1[ 5] * mx2[ 9] + mx1[ 9] * mx2[10] + mx1[13] * mx2[11];
1014 result[10] = mx1[ 2] * mx2[ 8] + mx1[ 6] * mx2[ 9] + mx1[10] * mx2[10] + mx1[14] * mx2[11];
1015 result[11] = mx1[ 3] * mx2[ 8] + mx1[ 7] * mx2[ 9] + mx1[11] * mx2[10] + mx1[15] * mx2[11];
1017 result[12] = mx1[ 0] * mx2[12] + mx1[ 4] * mx2[13] + mx1[ 8] * mx2[14] + mx1[12] * mx2[15];
1018 result[13] = mx1[ 1] * mx2[12] + mx1[ 5] * mx2[13] + mx1[ 9] * mx2[14] + mx1[13] * mx2[15];
1019 result[14] = mx1[ 2] * mx2[12] + mx1[ 6] * mx2[13] + mx1[10] * mx2[14] + mx1[14] * mx2[15];
1020 result[15] = mx1[ 3] * mx2[12] + mx1[ 7] * mx2[13] + mx1[11] * mx2[14] + mx1[15] * mx2[15];
1025 memcpy ( out, result,
sizeof (
float ) * 16 );
1062 memcpy ( mx1, A,
sizeof (
float ) * 16 );
1063 memcpy ( mx2, B,
sizeof (
float ) * 16 );
1065 dst[ 0] = mx1[ 0] * mx2[ 0] + mx1[ 4] * mx2[ 1] + mx1[ 8] * mx2[ 2];
1066 dst[ 1] = mx1[ 1] * mx2[ 0] + mx1[ 5] * mx2[ 1] + mx1[ 9] * mx2[ 2];
1067 dst[ 2] = mx1[ 2] * mx2[ 0] + mx1[ 6] * mx2[ 1] + mx1[10] * mx2[ 2];
1069 dst[ 4] = mx1[ 0] * mx2[ 4] + mx1[ 4] * mx2[ 5] + mx1[ 8] * mx2[ 6];
1070 dst[ 5] = mx1[ 1] * mx2[ 4] + mx1[ 5] * mx2[ 5] + mx1[ 9] * mx2[ 6];
1071 dst[ 6] = mx1[ 2] * mx2[ 4] + mx1[ 6] * mx2[ 5] + mx1[10] * mx2[ 6];
1073 dst[ 8] = mx1[ 0] * mx2[ 8] + mx1[ 4] * mx2[ 9] + mx1[ 8] * mx2[10];
1074 dst[ 9] = mx1[ 1] * mx2[ 8] + mx1[ 5] * mx2[ 9] + mx1[ 9] * mx2[10];
1075 dst[10] = mx1[ 2] * mx2[ 8] + mx1[ 6] * mx2[ 9] + mx1[10] * mx2[10];
1093 memcpy ( o, m1,
sizeof (
float ) * 16 );
1096 else if ( i > 1.0f )
1098 memcpy ( o, m2,
sizeof (
float ) * 16 );
1101 o[ 0] = m1[ 0] + ( ( m2[ 0] - m1[ 0] ) * i );
1102 o[ 1] = m1[ 1] + ( ( m2[ 1] - m1[ 1] ) * i );
1103 o[ 2] = m1[ 2] + ( ( m2[ 2] - m1[ 2] ) * i );
1104 o[ 3] = m1[ 3] + ( ( m2[ 3] - m1[ 3] ) * i );
1105 o[ 4] = m1[ 4] + ( ( m2[ 4] - m1[ 4] ) * i );
1106 o[ 5] = m1[ 5] + ( ( m2[ 5] - m1[ 5] ) * i );
1107 o[ 6] = m1[ 6] + ( ( m2[ 6] - m1[ 6] ) * i );
1108 o[ 7] = m1[ 7] + ( ( m2[ 7] - m1[ 7] ) * i );
1109 o[ 8] = m1[ 8] + ( ( m2[ 8] - m1[ 8] ) * i );
1110 o[ 9] = m1[ 9] + ( ( m2[ 9] - m1[ 9] ) * i );
1111 o[10] = m1[10] + ( ( m2[10] - m1[10] ) * i );
1112 o[11] = m1[11] + ( ( m2[11] - m1[11] ) * i );
1113 o[12] = m1[12] + ( ( m2[12] - m1[12] ) * i );
1114 o[13] = m1[13] + ( ( m2[13] - m1[13] ) * i );
1115 o[14] = m1[14] + ( ( m2[14] - m1[14] ) * i );
1116 o[15] = m1[15] + ( ( m2[15] - m1[15] ) * i );
1133inline float* GetRotationMatrix (
float* R,
float angle,
float x,
float y,
float z )
1135 float radians = float ( ( angle / 180.0f ) * PI );
1136 float c = cosf ( radians );
1137 float s = sinf ( radians );
1138 R[ 0] = x * x * ( 1 - c ) + c;
1139 R[ 1] = x * y * ( 1 - c ) - z * s;
1140 R[ 2] = x * z * ( 1 - c ) + y * s;
1142 R[ 4] = y * x * ( 1 - c ) + z * s;
1143 R[ 5] = y * y * ( 1 - c ) + c;
1144 R[ 6] = y * z * ( 1 - c ) - x * s;
1146 R[ 8] = x * z * ( 1 - c ) - y * s;
1147 R[ 9] = y * z * ( 1 - c ) + x * s;
1148 R[10] = z * z * ( 1 - c ) + c;
1169inline float* RotateMatrix (
float* src,
float* dst,
float angle,
float x,
float y,
float z )
1175 GetRotationMatrix ( r, angle, x, y, z );
1176 return Multiply4x4Matrix ( src, r, dst );
1194inline float* RotateMatrixObjectSpace (
float* src,
float* dst,
float angle,
float x,
float y,
float z )
1196 float v[3] = {x, y, z};
1210 GetRotationMatrix ( r, angle, v[0], v[1], v[2] );
1229inline float* RotateMatrixInertialSpace (
float* src,
float* dst,
float angle,
float x,
float y,
float z )
1243 GetRotationMatrix ( r, angle, x, y, z );
1304 result[ 0] = src[ 0];
1305 result[ 1] = src[ 1];
1306 result[ 2] = src[ 2];
1307 result[ 3] = src[ 3];
1309 result[ 4] = src[ 4];
1310 result[ 5] = src[ 5];
1311 result[ 6] = src[ 6];
1312 result[ 7] = src[ 7];
1314 result[ 8] = src[ 8];
1315 result[ 9] = src[ 9];
1316 result[10] = src[10];
1317 result[11] = src[11];
1319 result[12] = v[0] * src[ 0] + v[1] * src[ 4] + v[2] * src[ 8] + src[12];
1320 result[13] = v[0] * src[ 1] + v[1] * src[ 5] + v[2] * src[ 9] + src[13];
1321 result[14] = v[0] * src[ 2] + v[1] * src[ 6] + v[2] * src[10] + src[14];
1323 result[15] = v[0] * src[ 3] + v[1] * src[ 7] + v[2] * src[11] + src[15];
1326 result[12] = src[ 0] * v[0] + src[ 4] * v[1] + src[ 8] * v[2] + src[12];
1327 result[13] = src[ 1] * v[0] + src[ 5] * v[1] + src[ 9] * v[2] + src[13];
1328 result[14] = src[ 2] * v[0] + src[ 6] * v[1] + src[10] * v[2] + src[14];
1331 memcpy ( dst, result,
sizeof (
float ) * 16 );
1362 result[ 0] = src[ 0] + src[ 3] * v[ 0];
1363 result[ 1] = src[ 1] + src[ 3] * v[ 1];
1364 result[ 2] = src[ 2] + src[ 3] * v[ 2];
1365 result[ 3] = src[ 3];
1367 result[ 4] = src[ 4] + src[ 7] * v[ 0];
1368 result[ 5] = src[ 5] + src[ 7] * v[ 1];
1369 result[ 6] = src[ 6] + src[ 7] * v[ 2];
1370 result[ 7] = src[ 7];
1372 result[ 8] = src[ 8] + src[11] * v[ 0];
1373 result[ 9] = src[ 9] + src[11] * v[ 1];
1374 result[10] = src[10] + src[11] * v[ 2];
1375 result[11] = src[11];
1377 result[12] = src[12] + src[15] * v[ 0];
1378 result[13] = src[13] + src[15] * v[ 1];
1379 result[14] = src[14] + src[15] * v[ 2];
1380 result[15] = src[15];
1383 result[12] = src[12] + v[ 0];
1384 result[13] = src[13] + v[ 1];
1385 result[14] = src[14] + v[ 2];
1387 memcpy ( dst, result,
sizeof (
float ) * 16 );
1402 M[ 0] = R[ 0] * srt[0];
1403 M[ 1] = R[ 1] * srt[0];
1404 M[ 2] = R[ 2] * srt[0];
1407 M[ 4] = R[ 3] * srt[1];
1408 M[ 5] = R[ 4] * srt[1];
1409 M[ 6] = R[ 5] * srt[1];
1412 M[ 8] = R[ 6] * srt[2];
1413 M[ 9] = R[ 7] * srt[2];
1414 M[10] = R[ 8] * srt[2];
1435 float srt[10] = {s[0], s[1], s[2], r[0], r[1], r[2], r[3], t[0], t[1], t[2],};
1459 M[0 ] = R[0] * srt[0];
1460 M[4 ] = R[1] * srt[0];
1461 M[8 ] = R[2] * srt[0];
1464 M[1 ] = R[3] * srt[1];
1465 M[5 ] = R[4] * srt[1];
1466 M[9 ] = R[5] * srt[1];
1469 M[2 ] = R[6] * srt[2];
1470 M[6 ] = R[7] * srt[2];
1471 M[10] = R[8] * srt[2];
1475 M[12] = M[0] * srt[7] + M[1] * srt[8] + M[2] * srt[9] + M[3];
1476 M[13] = M[4] * srt[7] + M[5] * srt[8] + M[6] * srt[9] + M[7];
1477 M[14] = M[8] * srt[7] + M[9] * srt[8] + M[10] * srt[9] + M[11];
1484 1.0f / srt[0], 1.0f / srt[1], 1.0f / srt[2],
1485 srt[3], -srt[4], -srt[5], -srt[6],
1486 -srt[7], -srt[8], -srt[9]
1522 float radians = float ( ( angle / 180.0f ) * M_PI );
1523 float result = ( float ) sin ( radians / 2.0f );
1524 quat[0] = ( float ) cos ( radians / 2.0f );
1525 quat[1] = float ( x * result );
1526 quat[2] = float ( y * result );
1527 quat[3] = float ( z * result );
1542 float roll = ( ( euler[0] / 180.0f ) *
static_cast<float> ( M_PI ) );
1543 float pitch = ( ( euler[1] / 180.0f ) *
static_cast<float> ( M_PI ) );
1544 float yaw = ( ( euler[2] / 180.0f ) *
static_cast<float> ( M_PI ) );
1545 q[0] = cos ( roll / 2 ) * cos ( pitch / 2 ) * cos ( yaw / 2 ) + sin ( roll / 2 ) * sin ( pitch / 2 ) * sin ( yaw / 2 );
1546 q[1] = sin ( roll / 2 ) * cos ( pitch / 2 ) * cos ( yaw / 2 ) - cos ( roll / 2 ) * sin ( pitch / 2 ) * sin ( yaw / 2 );
1547 q[2] = cos ( roll / 2 ) * sin ( pitch / 2 ) * cos ( yaw / 2 ) + sin ( roll / 2 ) * cos ( pitch / 2 ) * sin ( yaw / 2 );
1548 q[3] = cos ( roll / 2 ) * cos ( pitch / 2 ) * sin ( yaw / 2 ) - sin ( roll / 2 ) * sin ( pitch / 2 ) * cos ( yaw / 2 );
1556inline float*
MultQuats (
const float* q1,
const float* q2,
float* out )
1559 float qc1[4] = {q1[0], q1[1], q1[2], q1[3]};
1560 float qc2[4] = {q2[0], q2[1], q2[2], q2[3]};
1561 out[0] = ( qc1[0] * qc2[0] - qc1[1] * qc2[1] - qc1[2] * qc2[2] - qc1[3] * qc2[3] );
1562 out[1] = ( qc1[0] * qc2[1] + qc1[1] * qc2[0] + qc1[2] * qc2[3] - qc1[3] * qc2[2] );
1563 out[2] = ( qc1[0] * qc2[2] - qc1[1] * qc2[3] + qc1[2] * qc2[0] + qc1[3] * qc2[1] );
1564 out[3] = ( qc1[0] * qc2[3] + qc1[1] * qc2[2] - qc1[2] * qc2[1] + qc1[3] * qc2[0] );
1578 m[ 0] = 1.0f - 2.0f * ( q[2] * q[2] + q[3] * q[3] );
1579 m[ 1] = 2.0f * ( q[1] * q[2] + q[3] * q[0] );
1580 m[ 2] = 2.0f * ( q[1] * q[3] - q[2] * q[0] );
1583 m[ 4] = 2.0f * ( q[1] * q[2] - q[3] * q[0] );
1584 m[ 5] = 1.0f - 2.0f * ( q[1] * q[1] + q[3] * q[3] );
1585 m[ 6] = 2.0f * ( q[3] * q[2] + q[1] * q[0] );
1588 m[ 8] = 2.0f * ( q[1] * q[3] + q[2] * q[0] );
1589 m[ 9] = 2.0f * ( q[2] * q[3] - q[1] * q[0] );
1590 m[10] = 1.0f - 2.0f * ( q[1] * q[1] + q[2] * q[2] );
1601 m[ 0] = 1.0f - 2.0f * ( q[2] * q[2] + q[3] * q[3] );
1602 m[ 1] = 2.0f * ( q[1] * q[2] + q[3] * q[0] );
1603 m[ 2] = 2.0f * ( q[1] * q[3] - q[2] * q[0] );
1605 m[ 3] = 2.0f * ( q[1] * q[2] - q[3] * q[0] );
1606 m[ 4] = 1.0f - 2.0f * ( q[1] * q[1] + q[3] * q[3] );
1607 m[ 5] = 2.0f * ( q[3] * q[2] + q[1] * q[0] );
1609 m[ 6] = 2.0f * ( q[1] * q[3] + q[2] * q[0] );
1610 m[ 7] = 2.0f * ( q[2] * q[3] - q[1] * q[0] );
1611 m[ 8] = 1.0f - 2.0f * ( q[1] * q[1] + q[2] * q[2] );
1614 float p1 = q[0] * q[1];
1615 float p2 = q[0] * q[2];
1616 float p3 = q[0] * q[3];
1618 float p4 = q[1] * q[1];
1619 float p5 = q[1] * q[2];
1620 float p6 = q[1] * q[3];
1622 float p7 = q[2] * q[2];
1623 float p8 = q[2] * q[3];
1625 float p9 = q[3] * q[3];
1628 m[ 0] = 1.0f - 2.0f * ( p7 + p9 );
1629 m[ 1] = 2.0f * ( p5 + p3 );
1630 m[ 2] = 2.0f * ( p6 - p2 );
1632 m[ 3] = 2.0f * ( p5 - p3 );
1633 m[ 4] = 1.0f - 2.0f * ( p4 + p9 );
1634 m[ 5] = 2.0f * ( p8 + p1 );
1636 m[ 6] = 2.0f * ( p6 + p2 );
1637 m[ 7] = 2.0f * ( p8 - p1 );
1638 m[ 8] = 1.0f - 2.0f * ( p4 + p7 );
1657 float T = matrix[0] + matrix[5] + matrix[10] + 1;
1661 S = 0.5f / sqrtf ( T );
1663 q[1] = ( matrix[6] - matrix[9] ) * S;
1664 q[2] = ( matrix[8] - matrix[2] ) * S;
1665 q[3] = ( matrix[1] - matrix[4] ) * S;
1670 if ( ( matrix[0] > matrix[5] ) & ( matrix[0] > matrix[10] ) )
1672 S = sqrtf ( 1.0f + matrix[0] - matrix[5] - matrix[10] ) * 2.0f;
1673 q[0] = ( matrix[9] - matrix[6] ) / S;
1675 q[2] = ( matrix[4] + matrix[1] ) / S;
1676 q[3] = ( matrix[8] + matrix[2] ) / S;
1678 else if ( matrix[5] > matrix[10] )
1680 S = sqrt ( 1.0f + matrix[5] - matrix[0] - matrix[10] ) * 2.0f;
1681 q[0] = ( matrix[8] - matrix[2] ) / S;
1682 q[1] = ( matrix[4] + matrix[1] ) / S;
1684 q[3] = ( matrix[9] + matrix[6] ) / S;
1688 S = sqrt ( 1.0f + matrix[10] - matrix[0] - matrix[5] ) * 2.0f;
1689 q[0] = ( matrix[4] - matrix[1] ) / S;
1690 q[1] = ( matrix[8] + matrix[2] ) / S;
1691 q[2] = ( matrix[9] + matrix[6] ) / S;
1709inline void Quat4x4MatrixMult (
float* q,
float* m,
float* dst )
1718 Multiply4x4Matrix ( qm, m, dst );
1734 float t1 = ( -q[1] * v[0] - q[2] * v[1] - q[3] * v[2] );
1735 float t2 = ( q[0] * v[0] + q[2] * v[2] - q[3] * v[1] );
1736 float t3 = ( q[0] * v[1] + q[3] * v[0] - q[1] * v[2] );
1737 float t4 = ( q[0] * v[2] + q[1] * v[1] - q[2] * v[0] );
1739 localout[0] = t1 * -q[1] + t2 * q[0] + t3 * -q[3] - t4 * -q[2];
1740 localout[1] = t1 * -q[2] + t3 * q[0] + t4 * -q[1] - t2 * -q[3];
1741 localout[2] = t1 * -q[3] + t4 * q[0] + t2 * -q[2] - t3 * -q[1];
1744 ( -q[1] * v[0] - q[2] * v[1] - q[3] * v[2] ) * -q[1] +
1745 ( q[0] * v[0] + q[2] * v[2] - q[3] * v[1] ) * q[0] +
1746 ( q[0] * v[1] + q[3] * v[0] - q[1] * v[2] ) * -q[3] -
1747 ( q[0] * v[2] + q[1] * v[1] - q[2] * v[0] ) * -q[2] ;
1749 ( -q[1] * v[0] - q[2] * v[1] - q[3] * v[2] ) * -q[2] +
1750 ( q[0] * v[1] + q[3] * v[0] - q[1] * v[2] ) * q[0] +
1751 ( q[0] * v[2] + q[1] * v[1] - q[2] * v[0] ) * -q[1] -
1752 ( q[0] * v[0] + q[2] * v[2] - q[3] * v[1] ) * -q[3] ;
1754 ( -q[1] * v[0] - q[2] * v[1] - q[3] * v[2] ) * -q[3] +
1755 ( q[0] * v[2] + q[1] * v[1] - q[2] * v[0] ) * q[0] +
1756 ( q[0] * v[0] + q[2] * v[2] - q[3] * v[1] ) * -q[2] -
1757 ( q[0] * v[1] + q[3] * v[0] - q[1] * v[2] ) * -q[1];
1759 out[0] = localout[0];
1760 out[1] = localout[1];
1761 out[2] = localout[2];
1775 localout[0] = ( q1[0] * q2[0] ) - ( q1[1] * q2[1] ) - ( q1[2] * q2[2] ) - ( q1[3] * q2[3] );
1776 localout[1] = ( q1[1] * q2[0] ) + ( q1[0] * q2[1] ) + ( q1[2] * q2[3] ) - ( q1[3] * q2[2] );
1777 localout[2] = ( q1[2] * q2[0] ) + ( q1[0] * q2[2] ) + ( q1[3] * q2[1] ) - ( q1[1] * q2[3] );
1778 localout[3] = ( q1[3] * q2[0] ) + ( q1[0] * q2[3] ) + ( q1[1] * q2[2] ) - ( q1[2] * q2[1] );
1782 float mag = sqrtf ( ( localout[1] * localout[1] ) + ( localout[2] * localout[2] )
1783 + ( localout[3] * localout[3] ) + ( localout[0] * localout[0] ) );
1789 float oneOverMag = 1.0f / mag;
1790 localout[0] *= oneOverMag;
1791 localout[1] *= oneOverMag;
1792 localout[2] *= oneOverMag;
1793 localout[3] *= oneOverMag;
1796 out[0] = localout[0];
1797 out[1] = localout[1];
1798 out[2] = localout[2];
1799 out[3] = localout[3];
1808inline bool CapInterpolation (
const float* q1,
const float* q2,
double interpolation,
float* out )
1810 if ( interpolation <= 0.0f )
1818 else if ( interpolation >= 1.0f )
1837inline float*
LerpQuats (
const float* q1,
const float* q2,
double interpolation,
float* out )
1841 float dot =
Dot4 ( q1, q2 );
1848 else if ( dot < 0.0f )
1852 out[0] = q1[0] + ( ( ( q2[0] * sign ) - q1[0] ) * interpolation );
1853 out[1] = q1[1] + ( ( ( q2[1] * sign ) - q1[1] ) * interpolation );
1854 out[2] = q1[2] + ( ( ( q2[2] * sign ) - q1[2] ) * interpolation );
1855 out[3] = q1[3] + ( ( ( q2[3] * sign ) - q1[3] ) * interpolation );
1857 out[0] =
static_cast<float> ( ( q1[0] * ( 1.0 - interpolation ) ) + ( q2[0] * interpolation ) );
1858 out[1] =
static_cast<float> ( ( q1[1] * ( 1.0 - interpolation ) ) + ( q2[1] * interpolation ) );
1859 out[2] =
static_cast<float> ( ( q1[2] * ( 1.0 - interpolation ) ) + ( q2[2] * interpolation ) );
1860 out[3] =
static_cast<float> ( ( q1[3] * ( 1.0 - interpolation ) ) + ( q2[3] * interpolation ) );
1874inline float*
NlerpQuats (
const float* q1,
const float* q2,
double interp,
float* out )
1885inline float*
SlerpQuats (
float* q1,
float* q2,
float interpolation,
float* out )
1891 float dot =
Dot4 ( q1, q2 );
1893 if ( fabs ( dot ) > 0.9999f )
1895 memcpy ( out, q1,
sizeof (
float ) * 4 );
1898 else if ( dot < 0.0f )
1903 float theta = acosf ( dot );
1904 float sinT = 1.0f / sinf ( theta );
1905 float newFactor = sinf ( interpolation * theta ) * sinT;
1906 float invFactor = sinf ( ( 1.0f - interpolation ) * theta ) * sinT;
1908 out[0] = invFactor * q1[0] + newFactor * q2[0] * sign;
1909 out[1] = invFactor * q1[1] + newFactor * q2[1] * sign;
1910 out[2] = invFactor * q1[2] + newFactor * q2[2] * sign;
1911 out[3] = invFactor * q1[3] + newFactor * q2[3] * sign;
1916inline float* QuatLn (
float* q,
float* out )
1919 float w = q[0] > 1.0f ? 1.0f : q[0] < -1.0f ? -1.0f : q[0];
1920 float a = acosf ( w );
1921 float s = sinf ( a );
1925 memset ( out, 0,
sizeof (
float ) * 4 );
1939inline float* QuatExp (
float* q,
float* out )
1941 float a =
Length ( q + 1 );
1942 float s = sinf ( a );
1943 float c = cosf ( a );
1948 memset ( out + 1, 0,
sizeof (
float ) * 3 );
1959inline float* GetInnerQuat (
float* past,
float* current,
float* future,
float* out )
1961 float q[4] = {current[0], -current[1], -current[2], -current[3]};
1969 return Normalize4 (
MultQuats ( current,
ScalarMultiply4 ( QuatExp (
Add4 ( QuatLn (
MultQuats ( q, past, tmp1 ), tmp2 ), QuatLn (
MultQuats ( q, future, tmp3 ), tmp4 ), tmp5 ), tmp6 ), -0.25f, tmp7 ), out ) );
1978inline float* SquadQuats (
float* q0,
float* q1,
float* q2,
float* q3,
float interp,
float* out )
1990 return SlerpQuats (
SlerpQuats ( q1, q2, interp, tmp1 ),
SlerpQuats ( GetInnerQuat ( q0, q1, q2, a1 ), GetInnerQuat ( q1, q2, q3, a2 ), interp, tmp2 ), 2 * interp * ( 1 - interp ), out );
1999inline float*
MultSRTs (
const float* srt1,
const float* srt2,
float* out )
2003 localout[0] = srt1[0] * srt2[0];
2004 localout[1] = srt1[1] * srt2[1];
2005 localout[2] = srt1[2] * srt2[2];
2007 MultQuats ( srt1 + 3, srt2 + 3, localout + 3 );
2010 localout[7] += srt1[7];
2011 localout[8] += srt1[8];
2012 localout[9] += srt1[9];
2013 memcpy ( out, localout,
sizeof (
float ) * 10 );
2023 out[0] = 1.0f / srt[0];
2024 out[1] = 1.0f / srt[1];
2025 out[2] = 1.0f / srt[2];
2048 plane[0] * point[0] +
2049 plane[1] * point[1] +
2050 plane[2] * point[2] -
2062 plane[0] * point[0] +
2063 plane[1] * point[1] +
2064 plane[2] * point[2] -
2065 ( plane[3] + dimensions[0] );
2077 ( plane[0] < 0 ) ? dimensions[0] : -dimensions[0],
2078 ( plane[1] < 0 ) ? dimensions[1] : -dimensions[1],
2079 ( plane[2] < 0 ) ? dimensions[2] : -dimensions[2]
2082 float dist = plane[3] -
Dot ( offsets, plane );
2085 plane[0] * point[0] +
2086 plane[1] * point[1] +
2087 plane[2] * point[2] - dist;
2099 float dist = plane[3] + dimensions[0];
2101 float offset = dimensions[1] - dimensions[0];
2103 float direction = plane[2] * offset;
2105 if ( direction > 0 )
2109 plane[0] * point[0] +
2110 plane[1] * point[1] +
2111 plane[2] * ( point[2] - offset ) -
2116 plane[0] * point[0] +
2117 plane[1] * point[1] +
2118 plane[2] * ( point[2] + offset ) -
2132 M[0], M[4], M[ 8], M[12],
2133 M[1], M[5], M[ 9], M[13],
2134 M[2], M[6], M[10], M[14],
2135 M[3], M[7], M[11], M[15]
float * MultQuats(const float *q1, const float *q2, float *out)
Multiply two quaternions.
float * InvertOrthogonalMatrix(float *src, float *dst)
Inverts a RT (rotation and translation) 4x4 matrix.
void PrintMatrix(const float *M)
Prints a 4x4 matrix to stdout in row-major visual layout.
float * LerpQuats(const float *q1, const float *q2, double interpolation, float *out)
Linearly interpolate between two quaternions.
float * NormalizePlane(float const *const aPlane, float *aOut)
Normalizes a plane.
float * TranslateMatrixInertialSpace(float *v, float *src, float *dst)
Translates a 4x4 matrix using a vector relative from its current position using the inertial axis.
float * MultVectorScalar(float *v, float s, float *out)
Multiplies a vector and a Scalar.
float * InvertSRT(const float *srt, float *out)
Inverts an SRT (scale-rotation-translation) transform.
float sabs(float x)
Single pressision floating point absolute value.
float * Transpose3x3Matrix(const float *src, float *dst)
Transposes a 3x3 Matrix.
float * Extract3x3Matrix(const float *m, float *out)
Extracts a 3x3 matrix from a 4x4 matrix.
float PointDistanceToPlane(float *plane, const float *point, const float *dimensions=nullptr)
Computes the signed distance from a point to a plane.
float * Convert3x3To4x3(const float *m, float *out)
converts a 3x3 matrix to a 4x3 matrix.
float * Matrix3x3To4x4(const float *src, float *dst)
Copies the 3x3 rotational part of a 4x4 matrix into a new 4x4 matrix.
float * NlerpQuats(const float *q1, const float *q2, double interp, float *out)
Linearly interpolate between two quaternions return the normalized result.
float * GetMatrixFromSRT(const float *srt, float *M)
Constructs a transformation matrix from SRT vector.
void EulerToQuat(float *euler, float *q)
Convert euler angle rotation notation to a quaternion.
float Distance(const float a[], const float b[])
Returns the distance between point a and b.
float * GetQuaternionInverse(const float *q, float *out)
Inverts a unit length quaternion, same as quaternion conjugate.
float * Normalize4(float *v)
Normalize vector.
void QuatTo3x3Matrix(const float *q, float *m)
Builds a 3x3 rotation matrix out of a quaternion.
float * Invert3x3Matrix(const float *src, float *dst)
Inverts a 3x3 Matrix.
float DeterminantMatrix3(const float *src)
Computes the determinant of a 3x3 matrix.
float * Multiply3x3Matrix(float *A, float *B, float *dst)
Multiplies only the 3x3 part of two 4x4 matrices.
float * Cross3(float *v1, float *v2, float *dst)
Cross product.
float SphereDistanceToPlane(float *plane, const float *point, const float *dimensions)
Computes the distance from a bounding sphere to a plane.
float * GetScaleVectorInverse(const float *v, float *out)
Returns the multiplicative inverse of a scale (transform) vector.
void MultQuats4(float *q1, float *q2, float *out)
Multiplies two quaternions.
void QuatTo4x4Matrix(float *q, float *m)
Builds a 3x4 rotation matrix out of a quaternion inside a 4x4 matrix.
void ClipVelocity(float *v, float *normal, float overbounce)
Clips Velocity against impacting surface normal.
void InterpolateMatrices(float *m1, float *m2, float *o, float i)
Linearly interpolate two matrices.
float * SetIdentityMatrix4x4(float *M)
Set a matrix to the Identity.
float * Convert3x3To4x4(const float *m, float *out)
converts a 3x3 matrix to a 4x4 matrix.
float * Extract3x3Into4x4(const float *m, float *out)
Extracts a 3x3 matrix from a 4x4 matrix into a 4x4 matrix.
void Matrix4x4ToQuat(float *matrix, float *q)
Extracts rotation matrix and converts it into a quaternion.
float DistanceSquared(const float a[], const float b[])
Returns the squared distance between point a and b.
void AngleAxisToQuat(float angle, float x, float y, float z, float *quat)
Convert axis angle rotation notation to a quaternion.
int ClosestAxis(float *v)
Returns the closest to paralell axis to the provided vector.
float * TranslateMatrixObjectSpace(float *v, float *src, float *dst)
Translates a 4x4 matrix using a vector relative from its current position using the object axis.
float * Add4(float *v1, float *v2, float *out)
adds two 4 element vectors.
float * MultSRTs(const float *srt1, const float *srt2, float *out)
This function should be equivalent to multiplying the two matrices generated from the SRTs.
float BoxDistanceToPlane(float *plane, const float *point, const float *dimensions)
Computes the distance from an axis-aligned bounding box to a plane.
float * GetPositionVectorInverse(const float *v, float *out)
Returns the additive inverse of a position (transform) vector.
float * MultVector4x4Matrix(const float *v, const float *m, float *out)
Multiplies a vector and a 4x4 matrix.
void RotateVectorByQuat(const float *q, const float *v, float *out)
Rotates a vector around the origin by a quaternion.
float Dot(const float v1[], const float v2[])
3 element vector Dot Product.
float Length(float const *const v)
Calculate vector length.
float * Subtract4(float *v1, float *v2, float *out)
adds two 4 element vectors.
void MultVector3x3Matrix(float *v, float *m, float *out)
Multiplies a vector and the rotational 3x3 part of a 4x4 matrix.
bool CapInterpolation(const float *q1, const float *q2, double interpolation, float *out)
Caps quaternion interpolation factor to [0,1] and copies the corresponding endpoint.
float Length4(float *v)
Calculate 4 element vector length.
float CapsuleDistanceToPlane(float *plane, const float *point, const float *dimensions)
Computes the distance from a capsule to a plane.
float * GetInvertedMatrixFromSRT(const float *srt, float *M)
Constructs an inverted transformation matrix from SRT vector.
float * SlerpQuats(float *q1, float *q2, float interpolation, float *out)
Spherical Linear interpolation between two quaternions.
float Dot4(const float v1[], const float v2[])
4 element vector Dot Product.
void InterpolateVectors(float *v1, float *v2, float interpolation, float *out)
Interpolates between two vectors.
float * Normalize(float *v)
Normalize vector.
float * InvertMatrix(float *mat, float *dest)
Invert a 4x4 matrix.
float * ScalarMultiply4(float *v, float s, float *out)
Multiply 4 element vector by a scalar.