From ad5afae7e264ffa72ed16d2ec2c6f6090e7aa7b5 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Mon, 27 Mar 2017 13:02:23 -0700 Subject: Adding operation for rotating about an axis --- redist/linmath.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'redist/linmath.c') 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. -- cgit v1.2.3 From e5c15af3af93356bb056624726e0b6068354690f Mon Sep 17 00:00:00 2001 From: mwturvey Date: Mon, 27 Mar 2017 14:20:29 -0700 Subject: Getting very close --- redist/linmath.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'redist/linmath.c') diff --git a/redist/linmath.c b/redist/linmath.c index 0e06156..69a70f6 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -85,6 +85,9 @@ FLT anglebetween3d( FLT * a, FLT * b ) // algorithm found here: http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/ void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) { + // TODO: this really should be external. + normalize3d(axis, axis); + FLT s = FLT_SIN(angle); FLT c = FLT_COS(angle); -- cgit v1.2.3