diff options
author | mwturvey <michael.w.turvey@intel.com> | 2017-03-27 13:02:23 -0700 |
---|---|---|
committer | mwturvey <michael.w.turvey@intel.com> | 2017-03-27 13:02:23 -0700 |
commit | ad5afae7e264ffa72ed16d2ec2c6f6090e7aa7b5 (patch) | |
tree | 0c6e13572771e7e9bb50baaeac6484b2a9085a7f /redist | |
parent | b9e9c89a46a91cbc69d7832d6f67e571723d11e6 (diff) | |
download | libsurvive-ad5afae7e264ffa72ed16d2ec2c6f6090e7aa7b5.tar.gz libsurvive-ad5afae7e264ffa72ed16d2ec2c6f6090e7aa7b5.tar.bz2 |
Adding operation for rotating about an axis
Diffstat (limited to 'redist')
-rw-r--r-- | redist/linmath.c | 19 | ||||
-rw-r--r-- | redist/linmath.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/redist/linmath.c b/redist/linmath.c index eefcd5f..0e06156 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -82,6 +82,25 @@ FLT anglebetween3d( FLT * a, FLT * b ) return FLT_ACOS(dot); } +// algorithm found here: http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/ +void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) +{ + FLT s = FLT_SIN(angle); + FLT c = FLT_COS(angle); + + FLT u=axis[0]; + FLT v=axis[1]; + FLT w=axis[2]; + + FLT x=invec3[0]; + FLT y=invec3[1]; + FLT z=invec3[2]; + + outvec3[0] = u*(u*x + v*y + w*z)*(1-c) + x*c + (-w*y + v*z)*s; + outvec3[1] = v*(u*x + v*y + w*z)*(1-c) + y*c + ( w*x - u*z)*s; + outvec3[2] = w*(u*x + v*y + w*z)*(1-c) + z*c + (-v*x + u*y)*s; +} + /////////////////////////////////////QUATERNIONS////////////////////////////////////////// //Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman) //Under the mit/X11 license. diff --git a/redist/linmath.h b/redist/linmath.h index 4e0cb77..6f0bf60 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -70,6 +70,7 @@ FLT magnitude3d(const FLT * a ); FLT anglebetween3d( FLT * a, FLT * b ); +void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle); //Quaternion things... void quatsetnone( FLT * q ); |