PolyVox  0.2.1
Open source voxel management library
Vector.h
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
24 #ifndef __PolyVox_Vector_H__
25 #define __PolyVox_Vector_H__
26 
27 #include "Impl/TypeDef.h"
28 
29 #include <cassert>
30 #include <cmath>
31 #include <cstring>
32 #include <iostream>
33 
34 namespace PolyVox
35 {
61  template <uint32_t Size, typename Type>
62  class Vector
63  {
64  public:
66  Vector(Type x, Type y);
68  Vector(Type x, Type y, Type z);
70  Vector(Type x, Type y, Type z, Type w);
72  Vector(void);
74  Vector(const Vector<Size,Type>& vector);
76  template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
78  ~Vector(void);
79 
83  bool operator==(const Vector<Size,Type>& rhs) const;
85  bool operator!=(const Vector<Size,Type>& rhs) const;
87  bool operator<(const Vector<Size,Type>& rhs) const;
97  Vector<Size,Type>& operator*=(const Type& rhs);
99  Vector<Size,Type>& operator/=(const Type& rhs);
100 
102  Type getElement(uint32_t index) const;
104  Type getX(void) const;
106  Type getY(void) const;
108  Type getZ(void) const;
110  Type getW(void) const;
111 
113  void setElement(uint32_t index, Type tValue);
115  void setElements(Type x, Type y);
117  void setElements(Type x, Type y, Type z);
119  void setElements(Type x, Type y, Type z, Type w);
121  void setX(Type tX);
123  void setY(Type tY);
125  void setZ(Type tZ);
127  void setW(Type tW);
128 
130  double length(void) const;
132  double lengthSquared(void) const;
134  double angleTo(const Vector<Size,Type>& vector) const;
136  Vector<Size,Type> cross(const Vector<Size,Type>& vector) const;
138  Type dot(const Vector<Size,Type>& rhs) const;
140  void normalise(void);
141 
142  private:
143  //Values for the vector
144  Type m_tElements[Size];
145  };
146 
147  //Non-member overloaded operators.
149  template <uint32_t Size,typename Type>
152  template <uint32_t Size,typename Type>
155  template <uint32_t Size,typename Type>
158  template <uint32_t Size,typename Type>
161  template <uint32_t Size,typename Type>
162  Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs);
164  template <uint32_t Size,typename Type>
165  Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs);
167  template <uint32_t Size, typename Type>
168  std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector);
169 
170  //Some handy typedefs
187 
188 
189 
190 }//namespace PolyVox
191 
192 #include "PolyVoxCore/Vector.inl"
193 
194 #endif
195