From b30cdc227fafbdf9ee004ee200bfab9c764cc5d6 Mon Sep 17 00:00:00 2001 From: Aaron Wisner Date: Sun, 19 Jul 2015 19:54:57 -0400 Subject: [PATCH 1/3] Implemented 3D vector cross product function Signed-off-by: Aaron Wisner --- src/math/p_cross.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/math/p_cross.c diff --git a/src/math/p_cross.c b/src/math/p_cross.c new file mode 100644 index 0000000..ac6bed1 --- /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); + } +} From bd4b05b5dd0afb9273fec3899f02d9f89a44753f Mon Sep 17 00:00:00 2001 From: Aaron Wisner Date: Sun, 19 Jul 2015 19:59:45 -0400 Subject: [PATCH 2/3] Fixed whitespace issue Signed-off-by: Aaron Wisner --- src/math/p_cross.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/math/p_cross.c b/src/math/p_cross.c index ac6bed1..0a4c2cf 100644 --- a/src/math/p_cross.c +++ b/src/math/p_cross.c @@ -18,7 +18,7 @@ */ void p_cross_f32(const float *a, const float *b, float *c, float *mag) { - float tmp; + float tmp; c[0] = a[1]*b[2] - a[2]*b[1]; @@ -28,7 +28,7 @@ void p_cross_f32(const float *a, const float *b, float *c, float *mag) if(mag) { - tmp = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]; - p_sqrt_f32(&tmp, mag, 1); - } + tmp = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]; + p_sqrt_f32(&tmp, mag, 1); + } } From cf74d3b5c25e1e86cb0a41866eb86dd92ab7b43f Mon Sep 17 00:00:00 2001 From: Aaron Wisner Date: Sun, 19 Jul 2015 23:44:41 -0400 Subject: [PATCH 3/3] Added p_cross.c to makefile Signed-off-by: Aaron Wisner --- src/math/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 - -