From 8a0831f2b9e458d8f1976c27f7865166ad8de6a4 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Wed, 21 Mar 2018 09:11:54 -0600 Subject: Moved pose to linmath to support stronger typing --- redist/lintest.c | 97 +++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 71 deletions(-) (limited to 'redist/lintest.c') diff --git a/redist/lintest.c b/redist/lintest.c index 4765e68..4c53da7 100644 --- a/redist/lintest.c +++ b/redist/lintest.c @@ -32,72 +32,72 @@ void printFLTA(FLT *a, int length) { void testInvertPose() { - FLT rotAroundYOffset[7] = {1, 1, 1, .5, 0, .5, 0}; - FLT pose_out[7]; + LinmathPose rotAroundYOffset = {1, 1, 1, .5, 0, .5, 0}; + LinmathPose pose_out; { - FLT expected[] = {1, -1, -1, 0.7071068, 0, -0.7071068, 0}; - InvertPose(pose_out, rotAroundYOffset); - ASSERT_FLTA_EQUALS(pose_out, expected, 7); + LinmathPose expected = {1, -1, -1, 0.7071068, 0, -0.7071068, 0}; + InvertPose(&pose_out, &rotAroundYOffset); + ASSERT_FLTA_EQUALS(pose_out.Pos, expected.Pos, 7); FLT identity[] = {0, 0, 0, 1, 0, 0, 0}; - ApplyPoseToPose(pose_out, expected, rotAroundYOffset); - quatnormalize(&pose_out[3], &pose_out[3]); - ASSERT_FLTA_EQUALS(pose_out, identity, 7); + ApplyPoseToPose(&pose_out, &expected, &rotAroundYOffset); + quatnormalize(pose_out.Rot, pose_out.Rot); + ASSERT_FLTA_EQUALS(pose_out.Pos, identity, 7); } } void testApplyPoseToPose() { - FLT rotAroundYOffset[7] = {1, 1, 1, 0, 0, 1, 0}; - FLT pose_out[7]; + LinmathPose rotAroundYOffset = {1, 1, 1, 0, 0, 1, 0}; + LinmathPose pose_out; { - FLT pt[] = {0, 1, 0, 0, 0, 1, 0}; - FLT expected[] = {1, 2, 1, -1, 0, 0, 0}; - ApplyPoseToPose(pose_out, rotAroundYOffset, pt); - quatnormalize(&pose_out[3], &pose_out[3]); - ASSERT_FLTA_EQUALS(pose_out, expected, 7); + LinmathPose pt = {0, 1, 0, 0, 0, 1, 0}; + LinmathPose expected = {1, 2, 1, -1, 0, 0, 0}; + ApplyPoseToPose(&pose_out, &rotAroundYOffset, &pt); + quatnormalize(pose_out.Rot, pose_out.Rot); + ASSERT_FLTA_EQUALS(pose_out.Pos, expected.Pos, 7); } { - FLT pt[] = {0, 1, 0, 0, 1, 0, 0}; - FLT expected[] = {1, 2, 1, 0, 0, 0, -1}; - ApplyPoseToPose(pose_out, rotAroundYOffset, pt); - ASSERT_FLTA_EQUALS(pose_out, expected, 7); + LinmathPose pt = {0, 1, 0, 0, 1, 0, 0}; + LinmathPose expected = {1, 2, 1, 0, 0, 0, -1}; + ApplyPoseToPose(&pose_out, &rotAroundYOffset, &pt); + ASSERT_FLTA_EQUALS(pose_out.Pos, expected.Pos, 7); } } void testApplyPoseToPoint() { - FLT rotAroundY[7] = {0, 0, 0, 0, 0, 1, 0}; + LinmathPose rotAroundY = {0, 0, 0, 0, 0, 1, 0}; FLT pt_out[3]; { FLT pt[3] = {0, 1, 0}; FLT expected[3] = {0, 1, 0}; - ApplyPoseToPoint(pt_out, rotAroundY, pt); + ApplyPoseToPoint(pt_out, &rotAroundY, pt); ASSERT_FLTA_EQUALS(pt_out, expected, 3); } { FLT pt[3] = {1, 1, 0}; FLT expected[3] = {-1, 1, 0}; - ApplyPoseToPoint(pt_out, rotAroundY, pt); + ApplyPoseToPoint(pt_out, &rotAroundY, pt); ASSERT_FLTA_EQUALS(pt_out, expected, 3); } - FLT rotAroundYOffset[7] = {1, 1, 1, 0, 0, 1, 0}; + LinmathPose rotAroundYOffset = {1, 1, 1, 0, 0, 1, 0}; { FLT pt[3] = {0, 1, 0}; FLT expected[3] = {1, 2, 1}; - ApplyPoseToPoint(pt_out, rotAroundYOffset, pt); + ApplyPoseToPoint(pt_out, &rotAroundYOffset, pt); ASSERT_FLTA_EQUALS(pt_out, expected, 3); } { FLT pt[3] = {1, 1, 0}; FLT expected[3] = {0, 2, 1}; - ApplyPoseToPoint(pt_out, rotAroundYOffset, pt); + ApplyPoseToPoint(pt_out, &rotAroundYOffset, pt); ASSERT_FLTA_EQUALS(pt_out, expected, 3); } } @@ -163,53 +163,8 @@ int main() printf( "%f %f %f\n", PFTHREE( pOut1 ) ); printf( "%f %f %f\n", PFTHREE( pOut2 ) ); */ - return -1; - -#endif + return 0; -#if 0 - - FLT e[3] = { 1,1,3.14 }; - FLT q[4]; - FLT m[16]; - FLT pt[3] = { 1, 1, 1 }; - - q[0] = 0; - q[1] = 0; - q[2] = 0; - q[3] = 1; - - quatrotatevector( pt, q, pt ); - printf( "%f %f %f\n", PFTHREE( pt ) ); - printf( "\n" ); - - quatfromeuler( q, e ); - printf( "%f %f %f %f\n\n", PFFOUR( q ) ); - quattomatrix(m,q); - printf( "%f %f %f %f\n", PFFOUR( &m[0] ) ); - printf( "%f %f %f %f\n", PFFOUR( &m[4] ) ); - printf( "%f %f %f %f\n", PFFOUR( &m[8] ) ); - printf( "%f %f %f %f\n\n", PFFOUR( &m[12] ) ); - quatfrommatrix(q,m ); - printf( "%f %f %f %f\n\n", PFFOUR( q ) ); - quattoeuler( e,q ); - printf( "E: %f %f %f\n", e[0], e[1], e[2] ); - - - FLT pfromlh[3] = { 0, 1, 0 }; - FLT p[3] = { 0, 1, 0 }; - quatrotatevector( p, q, p ); - printf( "%f %f %f\n", PFTHREE( p ) ); - printf( "Flipping rotation\n" ); - q[0] *= -1; //Wow that was easy. - quatrotatevector( p, q, p ); - printf( "%f %f %f\n", PFTHREE( p ) ); - - //Try setting up a pose. -// FLT mypose[7] = { 0, 0, 10, q[0], q[1], q[2], q[3] ); -// ApplyPoseToPoint( FLT * pout, const FLT * pin, const FLT * pose ); -//void InvertPose( FLT * poseout, const FLT * pose ); - #endif } -- cgit v1.2.3