From a706b9dffc85c0342611f8f3d236ba21b819bb14 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 19 Feb 2014 22:07:37 -0700 Subject: [PATCH] Apparently the github client missed the basic vector3 class, here it is. --- include/math/MathDefs.h | 15 +++ include/math/Vector3.h | 205 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) diff --git a/include/math/MathDefs.h b/include/math/MathDefs.h index e69de29..fdc211a 100644 --- a/include/math/MathDefs.h +++ b/include/math/MathDefs.h @@ -0,0 +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 diff --git a/include/math/Vector3.h b/include/math/Vector3.h index e69de29..bb14f65 100644 --- a/include/math/Vector3.h +++ b/include/math/Vector3.h @@ -0,0 +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