• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PolyVoxCore/include/PolyVoxCore/Vector.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 Copyright (c) 2005-2009 David Williams
00003 
00004 This software is provided 'as-is', without any express or implied
00005 warranty. In no event will the authors be held liable for any damages
00006 arising from the use of this software.
00007 
00008 Permission is granted to anyone to use this software for any purpose,
00009 including commercial applications, and to alter it and redistribute it
00010 freely, subject to the following restrictions:
00011 
00012     1. The origin of this software must not be misrepresented; you must not
00013     claim that you wrote the original software. If you use this software
00014     in a product, an acknowledgment in the product documentation would be
00015     appreciated but is not required.
00016 
00017     2. Altered source versions must be plainly marked as such, and must not be
00018     misrepresented as being the original software.
00019 
00020     3. This notice may not be removed or altered from any source
00021     distribution.   
00022 *******************************************************************************/
00023 
00024 #ifndef __PolyVox_Vector_H__
00025 #define __PolyVox_Vector_H__
00026 
00027 #include "PolyVoxImpl/TypeDef.h"
00028 
00029 #include <cassert>
00030 #include <cmath>
00031 #include <cstring>
00032 #include <iostream>
00033 
00034 namespace PolyVox
00035 {
00061     template <uint32_t Size, typename Type>
00062     class Vector
00063     {
00064     public:
00066         Vector(Type x, Type y) throw();
00068         Vector(Type x, Type y, Type z) throw();
00070         Vector(Type x, Type y, Type z, Type w) throw();
00072         Vector(void) throw();
00074         Vector(const Vector<Size,Type>& vector) throw();
00076         template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector) throw();
00078         ~Vector(void) throw();
00079 
00081         Vector<Size,Type>& operator=(const Vector<Size,Type>& rhs) throw();
00083         bool operator==(const Vector<Size,Type>& rhs) const throw();
00085         bool operator!=(const Vector<Size,Type>& rhs) const throw();
00087         bool operator<(const Vector<Size,Type>& rhs) const throw();
00089         Vector<Size,Type>& operator+=(const Vector<Size,Type> &rhs) throw();
00091         Vector<Size,Type>& operator-=(const Vector<Size,Type> &rhs) throw();
00093         Vector<Size,Type>& operator*=(const Vector<Size,Type> &rhs) throw();
00095         Vector<Size,Type>& operator/=(const Vector<Size,Type> &rhs) throw();
00097         Vector<Size,Type>& operator*=(const Type& rhs) throw();
00099         Vector<Size,Type>& operator/=(const Type& rhs) throw();
00100 
00102         Type getElement(uint32_t index) const throw();
00104         Type getX(void) const throw();        
00106         Type getY(void) const throw();        
00108         Type getZ(void) const throw();        
00110         Type getW(void) const throw();      
00111 
00113         void setElement(uint32_t index, Type tValue) throw();
00115         void setElements(Type x, Type y) throw();
00117         void setElements(Type x, Type y, Type z) throw();
00119         void setElements(Type x, Type y, Type z, Type w) throw();
00121         void setX(Type tX) throw();
00123         void setY(Type tY) throw();
00125         void setZ(Type tZ) throw();
00127         void setW(Type tW) throw();
00128 
00130         double length(void) const throw();
00132         double lengthSquared(void) const throw();
00134         double angleTo(const Vector<Size,Type>& vector) const throw();
00136         Vector<Size,Type> cross(const Vector<Size,Type>& vector) const throw();
00138         Type dot(const Vector<Size,Type>& rhs) const throw();
00140         void normalise(void) throw();
00141 
00142     private:
00143         //Values for the vector
00144         Type m_tElements[Size];
00145     };
00146 
00147     //Non-member overloaded operators. 
00149     template <uint32_t Size,typename Type>
00150         Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
00152     template <uint32_t Size,typename Type>
00153         Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
00155     template <uint32_t Size,typename Type>
00156         Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
00158     template <uint32_t Size,typename Type>
00159         Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
00161     template <uint32_t Size,typename Type>
00162         Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
00164     template <uint32_t Size,typename Type>
00165         Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw();
00167     template <uint32_t Size, typename Type>
00168         std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector) throw();
00169 
00170     //Some handy typedefs
00172     typedef Vector<3,float> Vector3DFloat;
00174     typedef Vector<3,double> Vector3DDouble;
00176     typedef Vector<3,int8_t> Vector3DInt8;
00178     typedef Vector<3,uint8_t> Vector3DUint8;
00180     typedef Vector<3,int16_t> Vector3DInt16;
00182     typedef Vector<3,uint16_t> Vector3DUint16;
00184     typedef Vector<3,int32_t> Vector3DInt32;
00186     typedef Vector<3,uint32_t> Vector3DUint32;
00187 
00188 
00189 
00190 }//namespace PolyVox
00191 
00192 #include "PolyVoxCore/Vector.inl"
00193 
00194 #endif
00195 

Generated on Sat Nov 19 2011 00:27:31 for PolyVox by  doxygen 1.7.1