From ce04edb8cb82a494d5864260aa3cde1da9e685f8 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 20 Feb 2014 21:15:54 -0700 Subject: [PATCH] Making changes to Vector3 related stuff. --- include/math/MathDefs.h | 20 +++++++++++++++++ include/math/Vector3.h | 6 +++++- tests/main.cpp | 2 ++ tests/tests/TestsVector3.h | 44 ++++++++++++++++++++++++++++++++------ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/include/math/MathDefs.h b/include/math/MathDefs.h index a502437..9bb1132 100644 --- a/include/math/MathDefs.h +++ b/include/math/MathDefs.h @@ -12,4 +12,24 @@ typedef float Scalar; + // May not need this, so may be removed. + struct CoordinateSystem + { + struct Types + { + enum Enum + { + RightHandedZUp, // x-right, y-forward, z-up + RightHandedYUp, // x-right, y-up, z-backwards + LeftHandedZUp, // x-left y-forward, z-up + LeftHandedYUp // x-right, y-up, z-backwards + }; + }; + + // set this to whichever you like + static const Types::Enum Type = Types::RightHandedZUp; + + // If I want to provide helpers for up/down/left/right/forward/backwards vectors, then you'll need to know the coordinate system type^ + }; + #endif diff --git a/include/math/Vector3.h b/include/math/Vector3.h index 17a2410..d3f9aa3 100644 --- a/include/math/Vector3.h +++ b/include/math/Vector3.h @@ -48,7 +48,8 @@ bool IsZero( void ) const; - static TVector3 Zero( void ); + // Predefined helper vectors + static TVector3 Zero; }; typedef TVector3< Scalar > Vec3f; @@ -176,4 +177,7 @@ return x == 0 && y == 0 && z == 0; } + template< typename BaseType > + TVector3< BaseType > TVector3< BaseType >::Zero = TVector3< BaseType >(0.f, 0.f, 0.f); + #endif diff --git a/tests/main.cpp b/tests/main.cpp index bae85b6..a44ab46 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -5,6 +5,8 @@ using namespace igloo; +#include "math/Vector3.h" + // Testing headers: #include "tests/TestsVector3.h" diff --git a/tests/tests/TestsVector3.h b/tests/tests/TestsVector3.h index 3a348c5..69751bb 100644 --- a/tests/tests/TestsVector3.h +++ b/tests/tests/TestsVector3.h @@ -7,9 +7,7 @@ { Then( it_should_be_correct ) { - value1.x = 1.f; - value1.y = 1.f; - value1.z = 1.f; + value1 = Vec3f( 1.f, 1.f, 1.f ); value1 *= 2.f; @@ -23,9 +21,7 @@ { Then( it_should_be_correct ) { - value1.x = 2.f; - value1.y = 2.f; - value1.z = 2.f; + value1 = Vec3f( 2.f, 2.f, 2.f ); value1 /= 2.f; @@ -35,4 +31,40 @@ Vec3f value1; }; + When( vector3_scalar_multiply_assignment ) + { + Then( it_should_be_correct ) + { + value1 = Vec3f( 1.f, 1.f, 1.f ) * 2.f; + + Assert::That( value1, Equals( Vec3f( 2.f, 2.f, 2.f ) ) ); + } + + Vec3f value1; + }; + + When( vector3_scalar_divide_assignment ) + { + Then( it_should_be_correct ) + { + value1 = Vec3f( 2.f, 2.f, 2.f ) / 2.f; + + Assert::That( value1, Equals( Vec3f( 1.f, 1.f, 1.f ) ) ); + } + + Vec3f value1; + }; + + When( vector3_set_to_zero ) + { + Then( it_should_be_correct ) + { + value1 = Vec3f::Zero; + + Assert::That( value1, Equals( Vec3f( 0.f, 0.f, 0.f ) ) ); + } + + Vec3f value1; + }; + #endif //__TESTSVECTOR3_H__