diff --git a/README.md b/README.md index 9f09efd..0272999 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,12 @@ C++ GameDev related math helpers. These helpers will be designed for ease of us Requirements ----------- -Aside from a C++ compiler, there are no external dependencies outside of the stdlib. However, for running unit tests this uses [igloo](https://github.com/joakimkarlsson/igloo), already referenced as an external. +Aside from a C++ compiler, there are no external dependencies outside of the stdlib. However, for running unit tests I use [igloo](https://github.com/joakimkarlsson/igloo), which is already referenced, and you'll need premake4. Cloning ----------- -Since there's an external for testing, don't forget `--recursive`: `git clone --recursive https://github.com/leetNightshade/math.beta.git`. \ No newline at end of file +Since there's an external for testing, don't forget `--recursive`: `git clone --recursive https://github.com/leetNightshade/math.beta.git`. + +Testing +----------- +You'll need premake4. On the commandline `premake4 --help` to see what project types are available for your platform, and pick the project type you want to use. For example, on Windows I'll use `premake4 vs2010`. From there build your project. When it's done building, run the program directly; for convenience you don't need to run it from the commandline. \ No newline at end of file diff --git a/include/Debug.h b/include/Debug.h index 5ff165b..45bc62f 100644 --- a/include/Debug.h +++ b/include/Debug.h @@ -1,6 +1,6 @@ -#ifndef __DEBUG_H__ -#define __DEBUG_H__ - -// TODO: add assert macros and maybe some simple logging functionality - -#endif //__DEBUG_H__ +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +// TODO: add assert macros and maybe some simple logging functionality + +#endif //__DEBUG_H__ diff --git a/include/math/MathDefs.h b/include/math/MathDefs.h index fdc211a..a502437 100644 --- a/include/math/MathDefs.h +++ b/include/math/MathDefs.h @@ -1,15 +1,15 @@ -/* __ __ ___ _____ ____ - * \ \ / / / _ \ | __ \ | | - * \ \/\/ / / / \ \ | | / / | __| - * \_/\_/ /_/ \_\ |_| \_\ |_| - * Take it to the next Level - * - * 2009 Brian Ernst. - * See ReadMe.md for more license info. - */ -#ifndef __MATHDEFS_H__ -#define __MATHDEFS_H__ - - typedef float Scalar; - -#endif +/* __ __ ___ _____ ____ + * \ \ / / / _ \ | __ \ | | + * \ \/\/ / / / \ \ | | / / | __| + * \_/\_/ /_/ \_\ |_| \_\ |_| + * Take it to the next Level + * + * 2009 Brian Ernst. + * See ReadMe.md for more license info. + */ +#ifndef __MATHDEFS_H__ +#define __MATHDEFS_H__ + + typedef float Scalar; + +#endif diff --git a/include/math/Vector3.h b/include/math/Vector3.h index 60dda9b..28a69c2 100644 --- a/include/math/Vector3.h +++ b/include/math/Vector3.h @@ -1,205 +1,205 @@ -/* __ __ ___ _____ ____ - * \ \ / / / _ \ | __ \ | | - * \ \/\/ / / / \ \ | | / / | __| - * \_/\_/ /_/ \_\ |_| \_\ |_| - * Take it to the next Level - * - * 2009 Brian Ernst. - * See ReadMe.md for more license info. - */ -#ifndef __VECTOR3_H__ -#define __VECTOR3_H__ - -# include "Debug.h" -# include "math/MathDefs.h" - - template< typename BaseType > - class TVector3 - { - public: - - BaseType X, Y, Z; - - TVector3( void ); - TVector3( const TVector3& ); - TVector3( BaseType x, BaseType y, BaseType z ); - - virtual ~TVector3( void ) { } - - TVector3& operator=( const TVector3& ); - - // TODO: Implement and use epsilon comparison - bool operator==( const TVector3& ) const; - bool operator!=( const TVector3& ) const; - - TVector3 operator*( BaseType ) const; - TVector3 operator/( BaseType ) const; - TVector3 operator*( const TVector3& ) const; - TVector3 operator/( const TVector3& ) const; - TVector3 operator+( const TVector3& ) const; - TVector3 operator-( const TVector3& ) const; - - TVector3& operator*=( BaseType ); - TVector3& operator/=( BaseType ); - TVector3& operator*=( const TVector3& ); - TVector3& operator/=( const TVector3& ); - TVector3& operator+=( const TVector3& ); - TVector3& operator-=( const TVector3& ); - - // TODO: Add other helper functions - - bool IsZero( void ) const; - }; - - typedef TVector3< Scalar > Vec3f; - - - - template< typename BaseType > - inline TVector3< BaseType >::TVector3( void ) - { - } - - template< typename BaseType > - inline TVector3< BaseType >::TVector3( const TVector3& vect ) - : X( vect.X ) - , Y( vect.Y ) - , Z( vect.Z ) - { - } - - template< typename BaseType > - inline TVector3< BaseType >::TVector3( BaseType x, BaseType y, BaseType z ) - : X( x ) - , Y( y ) - , Z( z ) - { - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator=( const TVector3& vect ) - { -#ifdef _DEBUG - if ( this == &vect ) - { - return *this; - } -#endif - - X = vect.X; - Y = vect.Y; - Z = vect.Z; - - return *this; - } - - template< typename BaseType > - inline bool TVector3< BaseType >::operator==( const TVector3& vect ) const - { - return X == vect.X && Y == vect.Y && Z == vect.Z; - } - - template< typename BaseType > - inline bool TVector3< BaseType >::operator!=( const TVector3& vect ) const - { - return X != vect.X || Y != vect.Y || Z != vect.Z; - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator*( BaseType val ) const - { - return TVector3< BaseType >( X * val, Y * val, Z * val ); - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator/( BaseType val ) const - { - return TVector3< BaseType >( X / val, Y / val, Z / val ); - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator*( const TVector3& vect ) const - { - return TVector3< BaseType >( X * vect.X, Y * vect.Y, Z * vect.Z ); - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator/( const TVector3& vect ) const - { - return TVector3< BaseType >( X / vect.X, Y / vect.Y, Z / vect.Z ); - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator+( const TVector3& vect ) const - { - return TVector3< BaseType >( X + vect.X, Y + vect.Y, Z + vect.Z ); - } - - template< typename BaseType > - inline TVector3< BaseType > TVector3< BaseType >::operator-( const TVector3& vect ) const - { - return TVector3< BaseType >( X - vect.X, Y - vect.Y, Z - vect.Z ); - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator*=( BaseType val ) - { - X *= val; - Y *= val; - Z *= val; - return *this; - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator/=( BaseType val ) - { - X /= val; - Y /= val; - Z /= val; - return *this; - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator*=( const TVector3& vect ) - { - X *= vect.X; - Y *= vect.Y; - Z *= vect.Z; - return *this; - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator/=( const TVector3& vect ) - { - X /= vect.X; - Y /= vect.Y; - Z /= vect.Z; - return *this; - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator+=( const TVector3& vect ) - { - X += vect.X; - Y += vect.Y; - Z += vect.Z; - return *this; - } - - template< typename BaseType > - inline TVector3< BaseType >& TVector3< BaseType >::operator-=( const TVector3& vect ) - { - X -= vect.X; - Y -= vect.Y; - Z -= vect.Z; - return *this; - } - - template< typename BaseType > - inline bool TVector3< BaseType >::IsZero( void ) const - { - // TODO: Use epsilon - return X == 0 && Y == 0 && Z == 0; - } - -#endif +/* __ __ ___ _____ ____ + * \ \ / / / _ \ | __ \ | | + * \ \/\/ / / / \ \ | | / / | __| + * \_/\_/ /_/ \_\ |_| \_\ |_| + * Take it to the next Level + * + * 2009 Brian Ernst. + * See ReadMe.md for more license info. + */ +#ifndef __VECTOR3_H__ +#define __VECTOR3_H__ + +# include "Debug.h" +# include "math/MathDefs.h" + + template< typename BaseType > + class TVector3 + { + public: + + BaseType X, Y, Z; + + TVector3( void ); + TVector3( const TVector3& ); + TVector3( BaseType x, BaseType y, BaseType z ); + + virtual ~TVector3( void ) { } + + TVector3& operator=( const TVector3& ); + + // TODO: Implement and use epsilon comparison + bool operator==( const TVector3& ) const; + bool operator!=( const TVector3& ) const; + + TVector3 operator*( BaseType ) const; + TVector3 operator/( BaseType ) const; + TVector3 operator*( const TVector3& ) const; + TVector3 operator/( const TVector3& ) const; + TVector3 operator+( const TVector3& ) const; + TVector3 operator-( const TVector3& ) const; + + TVector3& operator*=( BaseType ); + TVector3& operator/=( BaseType ); + TVector3& operator*=( const TVector3& ); + TVector3& operator/=( const TVector3& ); + TVector3& operator+=( const TVector3& ); + TVector3& operator-=( const TVector3& ); + + // TODO: Add other helper functions + + bool IsZero( void ) const; + }; + + typedef TVector3< Scalar > Vec3f; + + + + template< typename BaseType > + inline TVector3< BaseType >::TVector3( void ) + { + } + + template< typename BaseType > + inline TVector3< BaseType >::TVector3( const TVector3& vect ) + : X( vect.X ) + , Y( vect.Y ) + , Z( vect.Z ) + { + } + + template< typename BaseType > + inline TVector3< BaseType >::TVector3( BaseType x, BaseType y, BaseType z ) + : X( x ) + , Y( y ) + , Z( z ) + { + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator=( const TVector3& vect ) + { +#ifdef _DEBUG + if ( this == &vect ) + { + return *this; + } +#endif + + X = vect.X; + Y = vect.Y; + Z = vect.Z; + + return *this; + } + + template< typename BaseType > + inline bool TVector3< BaseType >::operator==( const TVector3& vect ) const + { + return X == vect.X && Y == vect.Y && Z == vect.Z; + } + + template< typename BaseType > + inline bool TVector3< BaseType >::operator!=( const TVector3& vect ) const + { + return X != vect.X || Y != vect.Y || Z != vect.Z; + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator*( BaseType val ) const + { + return TVector3< BaseType >( X * val, Y * val, Z * val ); + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator/( BaseType val ) const + { + return TVector3< BaseType >( X / val, Y / val, Z / val ); + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator*( const TVector3& vect ) const + { + return TVector3< BaseType >( X * vect.X, Y * vect.Y, Z * vect.Z ); + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator/( const TVector3& vect ) const + { + return TVector3< BaseType >( X / vect.X, Y / vect.Y, Z / vect.Z ); + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator+( const TVector3& vect ) const + { + return TVector3< BaseType >( X + vect.X, Y + vect.Y, Z + vect.Z ); + } + + template< typename BaseType > + inline TVector3< BaseType > TVector3< BaseType >::operator-( const TVector3& vect ) const + { + return TVector3< BaseType >( X - vect.X, Y - vect.Y, Z - vect.Z ); + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator*=( BaseType val ) + { + X *= val; + Y *= val; + Z *= val; + return *this; + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator/=( BaseType val ) + { + X /= val; + Y /= val; + Z /= val; + return *this; + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator*=( const TVector3& vect ) + { + X *= vect.X; + Y *= vect.Y; + Z *= vect.Z; + return *this; + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator/=( const TVector3& vect ) + { + X /= vect.X; + Y /= vect.Y; + Z /= vect.Z; + return *this; + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator+=( const TVector3& vect ) + { + X += vect.X; + Y += vect.Y; + Z += vect.Z; + return *this; + } + + template< typename BaseType > + inline TVector3< BaseType >& TVector3< BaseType >::operator-=( const TVector3& vect ) + { + X -= vect.X; + Y -= vect.Y; + Z -= vect.Z; + return *this; + } + + template< typename BaseType > + inline bool TVector3< BaseType >::IsZero( void ) const + { + // TODO: Use epsilon + return X == 0 && Y == 0 && Z == 0; + } + +#endif diff --git a/tests/main.cpp b/tests/main.cpp index 99d4181..bae85b6 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,3 +1,6 @@ +#include +#include + #include using namespace igloo; @@ -8,6 +11,10 @@ using namespace igloo; int main( int argc, const char* argv[ ] ) { + const int returnValue = TestRunner::RunAllTests( argc, const_cast< char** >( argv ) ); - return TestRunner::RunAllTests( argc, const_cast< char** >( argv ) ); + std::cout << std::endl << "Press ENTER to continue" << std::endl; + std::cin.ignore( std::numeric_limits< std::streamsize >::max( ), '\n' ); + + return returnValue; } \ No newline at end of file