PolyVox  0.3.0-dev
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/ErrorHandling.h"
28 #include "Impl/TypeDef.h"
29 
31 
32 #include <cmath>
33 #include <cstring>
34 #include <iostream>
35 
36 namespace PolyVox
37 {
64  template <uint32_t Size, typename StorageType, typename OperationType>
65  class Vector
66  {
67  public:
69  Vector(void);
71  Vector(StorageType tFillValue);
73  Vector(StorageType x, StorageType y);
75  Vector(StorageType x, StorageType y, StorageType z);
77  Vector(StorageType x, StorageType y, StorageType z, StorageType w);
81  template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
83  ~Vector(void);
84 
92  POLYVOX_DEPRECATED bool operator<(const Vector<Size,StorageType,OperationType>& rhs) const;
102  Vector<Size,StorageType,OperationType>& operator*=(const StorageType& rhs);
104  Vector<Size,StorageType,OperationType>& operator/=(const StorageType& rhs);
105 
107  StorageType getElement(uint32_t index) const;
109  StorageType getX(void) const;
111  StorageType getY(void) const;
113  StorageType getZ(void) const;
115  StorageType getW(void) const;
116 
118  void setElement(uint32_t index, StorageType tValue);
120  void setElements(StorageType x, StorageType y);
122  void setElements(StorageType x, StorageType y, StorageType z);
124  void setElements(StorageType x, StorageType y, StorageType z, StorageType w);
126  void setX(StorageType tX);
128  void setY(StorageType tY);
130  void setZ(StorageType tZ);
132  void setW(StorageType tW);
133 
135  float length(void) const;
137  OperationType lengthSquared(void) const;
139  float angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
143  OperationType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
145  void normalise(void);
146 
147  private:
148  // Values for the vector
149  StorageType m_tElements[Size];
150  };
151 
152  // Non-member overloaded operators.
154  template <uint32_t Size,typename StorageType,typename OperationType>
157  template <uint32_t Size,typename StorageType,typename OperationType>
160  template <uint32_t Size,typename StorageType,typename OperationType>
163  template <uint32_t Size,typename StorageType,typename OperationType>
166  template <uint32_t Size,typename StorageType,typename OperationType>
169  template <uint32_t Size,typename StorageType,typename OperationType>
172  template <uint32_t Size, typename StorageType,typename OperationType>
173  std::ostream& operator<<(std::ostream& os, const Vector<Size,StorageType,OperationType>& vector);
174 
175  //Some handy typedefs
176 
193 
210 
227 
228 
229 }//namespace PolyVox
230 
231 #include "PolyVoxCore/Vector.inl"
232 
233 #endif
234