00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00144 Type m_tElements[Size];
00145 };
00146
00147
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
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 }
00191
00192 #include "PolyVoxCore/Vector.inl"
00193
00194 #endif
00195