diff --git a/src/math/Makefile.am b/src/math/Makefile.am index 3dea94c..d31cc7d 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -18,6 +18,7 @@ libpal_math_la_SOURCES = \ p_cbrt.c \ p_cos.c \ p_cosh.c \ + p_cross.c \ p_div.c \ p_dot.c \ p_exp.c p_exp.h \ @@ -53,5 +54,3 @@ libpal_math_la_SOURCES = \ tinymt/tinymt32.h libpal_math_la_LIBADD = -lm - - diff --git a/src/math/p_cross.c b/src/math/p_cross.c new file mode 100644 index 0000000..0a4c2cf --- /dev/null +++ b/src/math/p_cross.c @@ -0,0 +1,34 @@ +#include + +/** + * + * Calculates the cross product between vectors 'a' and 'b', producing + * another vector result 'c'. + * + * @param a Pointer to input 3d vector + * + * @param b Pointer to input 3d vector + * + * @param c Pointer to output 3d vector + * + * @param mag Pointer to output magnitude scalar (set null to not compute) + * + * @return None + * + */ +void p_cross_f32(const float *a, const float *b, float *c, float *mag) +{ + float tmp; + + c[0] = a[1]*b[2] - a[2]*b[1]; + + c[1] = a[2]*b[0] - a[0]*b[2]; + + c[2] = a[0]*b[1] - a[1]*b[0]; + + if(mag) + { + tmp = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]; + p_sqrt_f32(&tmp, mag, 1); + } +}