voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
vector3int.hpp
1 #ifndef BLUB_MATH_VECTOR3TEMPLATE_HPP
2 #define BLUB_MATH_VECTOR3TEMPLATE_HPP
3 
4 #include "blub/math/math.hpp"
5 #include "blub/math/vector3.hpp"
6 #include "blub/serialization/access.hpp"
7 #include "blub/serialization/nameValuePair.hpp"
8 
9 
10 namespace blub
11 {
12 
13 template <typename valueType, valueType valueDefault>
14 class vector3Template
15 {
16 public:
17  typedef valueType t_valueType;
18  typedef vector3Template<t_valueType, valueDefault> t_thisClass;
19 
20  vector3Template()
21  : x(valueDefault)
22  , y(valueDefault)
23  , z(valueDefault)
24  {
25  ;
26  }
27 
28  // not possible because of hash && multiple linking options
29  // vector3Template(const valueType& value)
30 
31  vector3Template(const valueType& x_, const valueType& y_, const valueType& z_)
32  : x(x_)
33  , y(y_)
34  , z(z_)
35  {
36  ;
37  }
38 
39  vector3Template(const t_thisClass& copy)
40  : x(copy.x)
41  , y(copy.y)
42  , z(copy.z)
43  {
44  ;
45  }
46 
47  vector3Template(const valueType& val)
48  : x(val)
49  , y(val)
50  , z(val)
51  {
52  ;
53  }
54 
55  vector3Template(const vector3& cast)
56  : x(cast.x)
57  , y(cast.y)
58  , z(cast.z)
59  {
60  ;
61  }
62 
63  bool operator == (const t_thisClass& other) const
64  {
65  return other.x == x && other.y == y && other.z == z;
66  }
67 
68  bool operator != (const t_thisClass& other) const
69  {
70  return other.x != x && other.y != y && other.z != z;
71  }
72 
73  bool operator <= (const t_thisClass& other) const
74  {
75  return x <= other.x && y <= other.y && z <= other.z;
76  }
77 
78  bool operator < (const t_thisClass& other) const
79  {
80  return x < other.x && y < other.y && z < other.z;
81  }
82 
83  bool operator >= (const t_thisClass& other) const
84  {
85  return x >= other.x && y >= other.y && z >= other.z;
86  }
87 
88  bool operator > (const t_thisClass& other) const
89  {
90  return x > other.x && y > other.y && z > other.z;
91  }
92 
93  t_thisClass operator * (const t_thisClass& other) const
94  {
95  return t_thisClass(other.x*x, other.y*y, other.z*z);
96  }
97 
98  t_thisClass operator * (const int32& other) const
99  {
100  return t_thisClass(other*x, other*y, other*z);
101  }
102 
103  t_thisClass operator + (const t_thisClass& other) const
104  {
105  return t_thisClass(other.x+x, other.y+y, other.z+z);
106  }
107 
108  t_thisClass operator - (const t_thisClass& other) const
109  {
110  return t_thisClass(x-other.x, y-other.y, z-other.z);
111  }
112 
113  t_thisClass operator - (void) const
114  {
115  return t_thisClass(-x, -y, -z);
116  }
117 
118  t_thisClass operator / (const t_thisClass& other) const
119  {
120  return t_thisClass(x/other.x, y/other.y, z/other.z);
121  }
122 
123  t_thisClass operator / (const t_valueType& other) const
124  {
125  return t_thisClass(x/other, y/other, z/other);
126  }
127 
128  t_thisClass operator % (const t_thisClass& other) const
129  {
130  return t_thisClass(x % other.x, y % other.y, z % other.z);
131  }
132 
133  t_thisClass operator % (const t_valueType& other) const
134  {
135  return t_thisClass(x % other, y % other, z % other);
136  }
137 
138  valueType operator [] (const blub::uint8& index) const
139  {
140  BASSERT(index < 3);
141  return *((&x) + index);
142  }
143 
144  t_thisClass getMinimum(const t_thisClass& other)
145  {
146  return t_thisClass(math::min(other.x, x), math::min(other.y, y), math::min(other.z, z));
147  }
148 
149  t_thisClass getMaximum(const t_thisClass& other)
150  {
151  return t_thisClass(math::max(other.x, x), math::max(other.y, y), math::max(other.z, z));
152  }
153 
154 
155 private:
156  BLUB_SERIALIZATION_ACCESS
157 
158  template <class formatType>
159  void serialize(formatType & readWrite, const uint32& version)
160  {
161  (void)version;
162 
163  readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(x);
164  readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(y);
165  readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(z);
166  }
167 
168 
169 public:
170  valueType x;
171  valueType y;
172  valueType z;
173 };
174 
175 
176 template <typename valueType, valueType valueDefault>
177 std::ostream &operator<<(std::ostream &os, const vector3Template<valueType, valueDefault>& toCast)
178 {
179  return os << "(" << toCast.x << "," << toCast.y << "," << toCast.z << ")";
180 }
181 
182 template <typename valueType, valueType valueDefault>
183 std::size_t hash_value(const vector3Template<valueType, valueDefault>& value)
184 {
185  std::size_t result(value.x);
186  boost::hash_combine(result, value.y);
187  boost::hash_combine(result, value.z);
188 
189  return result;
190 }
191 
192 
193 }
194 
195 
196 #endif // BLUB_MATH_VECTOR3TEMPLATE_HPP
Definition: deadlineTimer.hpp:10