Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/math/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -53,5 +54,3 @@ libpal_math_la_SOURCES = \
tinymt/tinymt32.h

libpal_math_la_LIBADD = -lm


34 changes: 34 additions & 0 deletions src/math/p_cross.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <pal.h>

/**
*
* 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);
}
}