diff options
author | Michael Turvey <mwturvey@users.noreply.github.com> | 2017-05-31 10:12:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-31 10:12:24 -0700 |
commit | 4d795f16f188513f96d167164131268c8cc66b4b (patch) | |
tree | 29e04a5990895ccdf7b7a6141ead2c6af0fd718a /redist/linmath.c | |
parent | b61178ee2038e6d08ce237d71f51ea26908b1161 (diff) | |
parent | 5c6d30471e789b975a3eceab05d8e68dbaec0533 (diff) | |
download | libsurvive-4d795f16f188513f96d167164131268c8cc66b4b.tar.gz libsurvive-4d795f16f188513f96d167164131268c8cc66b4b.tar.bz2 |
Merge pull request #77 from mwturvey/ToriiCleanup
Modest updates to Tori
Diffstat (limited to 'redist/linmath.c')
-rw-r--r-- | redist/linmath.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/redist/linmath.c b/redist/linmath.c index b3896ff..5d51708 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -104,6 +104,45 @@ void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) outvec3[2] = w*(u*x + v*y + w*z)*(1-c) + z*c + (-v*x + u*y)*s; } +void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest) +{ + FLT v0[3]; + FLT v1[3]; + normalize3d(v0, src); + normalize3d(v1, dest); + + FLT d = dot3d(v0, v1);// v0.dotProduct(v1); + + // If dot == 1, vectors are the same + // If dot == -1, vectors are opposite + if (FLT_FABS(d - 1) < DEFAULT_EPSILON) + { + axis[0] = 0; + axis[1] = 1; + axis[2] = 0; + *angle = 0; + return; + } + else if (FLT_FABS(d + 1) < DEFAULT_EPSILON) + { + axis[0] = 0; + axis[1] = 1; + axis[2] = 0; + *angle = LINMATHPI; + return; + } + + FLT v0Len = magnitude3d(v0); + FLT v1Len = magnitude3d(v1); + + *angle = FLT_ACOS(d / (v0Len * v1Len)); + + //cross3d(c, v0, v1); + cross3d(axis, v1, v0); + +} + + /////////////////////////////////////QUATERNIONS////////////////////////////////////////// //Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman) //Under the mit/X11 license. |