GlobeEngine
VBOVertex.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_VBOVertex_h
10 #define GlobeEngine_VBOVertex_h
11 
12 #include "OpenGL_Includes.h"
13 #include <vmmlib/vmmlib.hpp>
14 #include <iostream>
15 
16 namespace ge {
17  template <int D, class T> class VBOVertex
18  {
19  public:
21  for (int i=0;i<D;i++) {
22  this->data[i] = 0.0;
23  }
24  }
25  ~VBOVertex() { }
26 
27  T getArray(){
28  return data;
29  }
30 
31  friend std::ostream& operator<< (std::ostream &out, const VBOVertex< D, T> &vert) {
32  out << "("<< vert.data[0];
33  for (int i=1;i<D;i++) {
34  out << ", " << vert.data[i];
35  }
36  out << ")";
37  return out;
38  }
39 
40  /* is equal is coordinates are equal */
41  //bool operator==(const VBOVertex &other)const{
42  // memcmp(this->data, other->getArray(), sizeof(T) * D);
43  //}
44 
45 
46 
47  protected:
48  T data[D];
49  };
50 
51  template <class T> class Vertex2 : public VBOVertex< 2, T>
52  {
53  public:
54  Vertex2(){}
55  Vertex2(T _u, T _v){
56  this->data[0] = _u;
57  this->data[1] = _v;
58  }
59 
60  void set(T _u, T _v){
61  this->data[0] = _u;
62  this->data[1] = _v;
63  }
64 
65  /* smaller with x coordinate priority. */
66  bool operator<(const Vertex2 &other)const{
67  if(this->data[0] != other.x())
68  return this->data[0] < other.x();
69  return this->data[1] < other.y();
70  }
71 
72  /* is equal is coordinates are equal */
73  bool operator==(const Vertex2 &other)const{
74  return this->data[0] == other.x() && this->data[1] == other.y();
75  }
76 
77  T u() const { return this->data[0]; }
78  T v() const { return this->data[1]; }
79  T x() const { return this->data[0]; }
80  T y() const { return this->data[1]; }
81 
82  void u(T _u){ this->data[0] = _u; }
83  void x(T _x){ this->data[0] = _x; }
84  void v(T _v){ this->data[1] = _v; }
85  void y(T _y){ this->data[1] = _y; }
86  };
87 
96 
105 
114 
115  template <class T> class VBOVertex3 : public VBOVertex< 3, T>
116  {
117  public:
119  VBOVertex3(T _x, T _y, T _z){
120  this->data[0] = _x;
121  this->data[1] = _y;
122  this->data[2] = _z;
123  }
124 
125  void set(T _x, T _y, T _z){
126  this->data[0] = _x;
127  this->data[1] = _y;
128  this->data[2] = _z;
129  }
130 
131  T x() const { return this->data[0]; }
132  T y() const { return this->data[1]; }
133  T z() const { return this->data[2]; }
134  T r() const { return this->data[0]; }
135  T g() const { return this->data[1]; }
136  T b() const { return this->data[2]; }
137 
138  Vertex2<T> xy() const { return Vertex2<T>(this->data[0], this->data[1]); }
139  Vertex2<T> xz() const { return Vertex2<T>(this->data[0], this->data[2]); }
140  Vertex2<T> yz() const { return Vertex2<T>(this->data[1], this->data[2]); }
141 
142  void x(T _x){ this->data[0] = _x; }
143  void y(T _y){ this->data[1] = _y; }
144  void z(T _z){ this->data[2] = _z; }
145  void r(T _r){ this->data[0] = _r; }
146  void g(T _g){ this->data[1] = _g; }
147  void b(T _b){ this->data[2] = _b; }
148 
149  /* smaller with x coordinate priority. */
150  bool operator<(const VBOVertex3 &other)const{
151  if(this->data[0] != other.x())
152  return this->data[0] < other.x();
153  if(this->data[1] != other.y())
154  return this->data[1] < other.y();
155  return this->data[2] < other.z();
156  }
157 
158  /* is equal is coordinates are equal */
159  bool operator==(const VBOVertex3 &other) const{
160  return this->data[0] == other.x() && this->data[1] == other.y() && this->data[2] == other.z();
161  }
162 
163  /* convert vmml vector 3f ot VBOVertex 3f seems to not work */
164  VBOVertex3<T>& operator=(const vmml::Vector3f& other) const {
165  this->data[0] = other.x();
166  this->data[1] = other.y();
167  this->data[2] = other.z();
168  return this;
169  }
170 
171  /* is equal when coordinates are equal */
172  bool isAlmostEqual(const VBOVertex3 &other)const{
173  return (this->data[0] - other.x() <= 0.00001) && (this->data[1] - other.y() <= 0.00001) && (this->data[2] - other.z() <= 0.00001);
174  }
175 
177  {
178  bool operator()(const VBOVertex3 &a, const VBOVertex3 &b)
179  {
180  return (a.x() - b.x() <= 0.00001) && (a.y() - b.y() <= 0.00001) && (a.z() - b.z() <= 0.00001);
181  }
182  };
183  };
184 
194 
204 
207 
217 
227 
228  template <class T> class VBOVertex4 : public VBOVertex< 4, T>
229  {
230  public:
232  VBOVertex4(T _x, T _y, T _z, T _w){
233  this->data[0] = _x;
234  this->data[1] = _y;
235  this->data[2] = _z;
236  this->data[3] = _w;
237  }
238 
239  void set(T _x, T _y, T _z, T _w){
240  this->data[0] = _x;
241  this->data[1] = _y;
242  this->data[2] = _z;
243  this->data[3] = _w;
244  }
245 
246  T x() const { return this->data[0]; }
247  T y() const { return this->data[1]; }
248  T z() const { return this->data[2]; }
249  T w() const { return this->data[3]; }
250  T r() const { return this->data[0]; }
251  T g() const { return this->data[1]; }
252  T b() const { return this->data[2]; }
253  T a() const { return this->data[3]; }
254 
255  void x(T _x){ this->data[0] = _x; }
256  void y(T _y){ this->data[1] = _y; }
257  void z(T _z){ this->data[2] = _z; }
258  void w(T _w){ this->data[3] = _w; }
259  void r(T _r){ this->data[0] = _r; }
260  void g(T _g){ this->data[1] = _g; }
261  void b(T _b){ this->data[2] = _b; }
262  void a(T _a){ this->data[3] = _a; }
263 
264  /* smaller with x coordinate priority. */
265  bool operator<(const VBOVertex4 &other)const{
266  if(this->data[0] != other.x())
267  return this->data[0] < other.x();
268  if(this->data[1] != other.y())
269  return this->data[1] < other.y();
270  if(this->data[2] != other.z())
271  return this->data[1] < other.z();
272  return this->data[3] < other.w();
273  }
274 
275  /* is equal is coordinates are equal */
276  bool operator==(const VBOVertex4 &other)const{
277  return this->data[0] == other.x() && this->data[1] == other.y() && this->data[2] == other.z()&& this->data[3] == other.w();
278  }
279 
280  };
281 
291 
301 
310 }
311 #endif
Vertex2< GLfloat > TexCoord2f
Definition: VBOVertex.h:112
VBOVertex4< GLboolean > Vertex4boolean
Definition: VBOVertex.h:292
T y() const
Definition: VBOVertex.h:247
void x(T _x)
Definition: VBOVertex.h:142
VBOVertex3< T > & operator=(const vmml::Vector3f &other) const
Definition: VBOVertex.h:164
VBOVertex4< GLushort > Color4us
Definition: VBOVertex.h:305
bool operator()(const VBOVertex3 &a, const VBOVertex3 &b)
Definition: VBOVertex.h:178
Vertex2< GLdouble > Vertex2d
Definition: VBOVertex.h:95
void v(T _v)
Definition: VBOVertex.h:84
T b() const
Definition: VBOVertex.h:136
T x() const
Definition: VBOVertex.h:79
Vertex2< GLushort > TexCoord2us
Definition: VBOVertex.h:109
void set(T _x, T _y, T _z)
Definition: VBOVertex.h:125
VBOVertex4< GLuint > VBOVertex4ui
Definition: VBOVertex.h:288
VBOVertex4< GLint > Color4i
Definition: VBOVertex.h:306
Vertex2< GLfloat > Vertex2f
Definition: VBOVertex.h:94
VBOVertex4< GLint > VBOVertex4i
Definition: VBOVertex.h:287
VBOVertex4< GLdouble > VBOVertex4d
Definition: VBOVertex.h:290
VBOVertex4< GLboolean > VBOVertex4boolean
Definition: VBOVertex.h:282
VBOVertex3< GLboolean > Vertex3boolean
Definition: VBOVertex.h:195
VBOVertex4< GLfloat > Color4f
Definition: VBOVertex.h:308
Vertex2< T > xy() const
Definition: VBOVertex.h:138
VBOVertex3< GLboolean > VBOVertex3boolean
Definition: VBOVertex.h:185
VBOVertex3< GLboolean > Color3boolean
Definition: VBOVertex.h:208
VBOVertex3< GLshort > VBOVertex3s
Definition: VBOVertex.h:188
Vertex2< T > yz() const
Definition: VBOVertex.h:140
void r(T _r)
Definition: VBOVertex.h:259
Vertex2< GLfloat > Color2f
Definition: VBOVertex.h:103
VBOVertex4< GLshort > Color4s
Definition: VBOVertex.h:304
VBOVertex3< GLint > Vertex3i
Definition: VBOVertex.h:200
VBOVertex3< GLdouble > VBOVertex3d
Definition: VBOVertex.h:193
Vertex2< GLshort > TexCoord2s
Definition: VBOVertex.h:108
Definition: VBOVertex.h:17
void y(T _y)
Definition: VBOVertex.h:143
VBOVertex4< GLbyte > Vertex4b
Definition: VBOVertex.h:293
VBOVertex3< GLboolean > TexCoord3boolean
Definition: VBOVertex.h:218
VBOVertex3< GLdouble > Vertex3d
Definition: VBOVertex.h:203
Vertex2< GLint > TexCoord2i
Definition: VBOVertex.h:110
VBOVertex3< GLbyte > TexCoord3b
Definition: VBOVertex.h:219
void x(T _x)
Definition: VBOVertex.h:255
VBOVertex4< GLbyte > VBOVertex4b
Definition: VBOVertex.h:283
VBOVertex4< GLuint > Color4ui
Definition: VBOVertex.h:307
VBOVertex3< GLubyte > Color3ub
Definition: VBOVertex.h:210
T y() const
Definition: VBOVertex.h:80
VBOVertex()
Definition: VBOVertex.h:20
void z(T _z)
Definition: VBOVertex.h:144
VBOVertex3< GLint > VBOVertex3i
Definition: VBOVertex.h:190
VBOVertex3< GLdouble > Vertexd
Definition: VBOVertex.h:206
Vertex2< GLubyte > Vertex2ub
Definition: VBOVertex.h:89
void g(T _g)
Definition: VBOVertex.h:260
VBOVertex4< GLshort > VBOVertex4s
Definition: VBOVertex.h:285
VBOVertex3()
Definition: VBOVertex.h:118
void b(T _b)
Definition: VBOVertex.h:147
void r(T _r)
Definition: VBOVertex.h:145
VBOVertex4< GLfloat > VBOVertex4f
Definition: VBOVertex.h:289
T g() const
Definition: VBOVertex.h:135
VBOVertex4()
Definition: VBOVertex.h:231
Vertex2< GLbyte > TexCoord2b
Definition: VBOVertex.h:106
VBOVertex4(T _x, T _y, T _z, T _w)
Definition: VBOVertex.h:232
VBOVertex3< GLushort > Vertex3us
Definition: VBOVertex.h:199
VBOVertex3< GLbyte > Color3b
Definition: VBOVertex.h:209
VBOVertex3< GLfloat > Vertexf
Definition: VBOVertex.h:205
T b() const
Definition: VBOVertex.h:252
VBOVertex3(T _x, T _y, T _z)
Definition: VBOVertex.h:119
Vertex2()
Definition: VBOVertex.h:54
VBOVertex3< GLbyte > Vertex3b
Definition: VBOVertex.h:196
VBOVertex3< GLubyte > VBOVertex3ub
Definition: VBOVertex.h:187
VBOVertex4< GLushort > Vertex4us
Definition: VBOVertex.h:296
Vertex2< GLuint > Color2ui
Definition: VBOVertex.h:102
void set(T _x, T _y, T _z, T _w)
Definition: VBOVertex.h:239
bool operator<(const VBOVertex4 &other) const
Definition: VBOVertex.h:265
T y() const
Definition: VBOVertex.h:132
VBOVertex4< GLfloat > Vertex4f
Definition: VBOVertex.h:299
VBOVertex3< GLfloat > Color3f
Definition: VBOVertex.h:215
void x(T _x)
Definition: VBOVertex.h:83
VBOVertex3< GLbyte > VBOVertex3b
Definition: VBOVertex.h:186
void b(T _b)
Definition: VBOVertex.h:261
T x() const
Definition: VBOVertex.h:246
VBOVertex3< GLint > TexCoord3i
Definition: VBOVertex.h:223
void y(T _y)
Definition: VBOVertex.h:256
VBOVertex3< GLshort > TexCoord3s
Definition: VBOVertex.h:221
VBOVertex4< GLdouble > Vertex4d
Definition: VBOVertex.h:300
T z() const
Definition: VBOVertex.h:133
VBOVertex3< GLshort > Vertex3s
Definition: VBOVertex.h:198
T getArray()
Definition: VBOVertex.h:27
void y(T _y)
Definition: VBOVertex.h:85
Vertex2< GLuint > TexCoord2ui
Definition: VBOVertex.h:111
VBOVertex4< GLubyte > VBOVertex4ub
Definition: VBOVertex.h:284
T x() const
Definition: VBOVertex.h:131
VBOVertex3< GLdouble > TexCoord3d
Definition: VBOVertex.h:226
bool isAlmostEqual(const VBOVertex3 &other) const
Definition: VBOVertex.h:172
VBOVertex3< GLushort > TexCoord3us
Definition: VBOVertex.h:222
T data[D]
Definition: VBOVertex.h:48
void w(T _w)
Definition: VBOVertex.h:258
VBOVertex3< GLint > Color3i
Definition: VBOVertex.h:213
Vertex2< T > xz() const
Definition: VBOVertex.h:139
T a() const
Definition: VBOVertex.h:253
Vertex2< GLubyte > Color2ub
Definition: VBOVertex.h:98
Vertex2< GLshort > Vertex2s
Definition: VBOVertex.h:90
Definition: VBOVertex.h:115
Vertex2< GLushort > Color2us
Definition: VBOVertex.h:100
Vertex2< GLint > Color2i
Definition: VBOVertex.h:101
VBOVertex4< GLushort > VBOVertex4us
Definition: VBOVertex.h:286
void a(T _a)
Definition: VBOVertex.h:262
void z(T _z)
Definition: VBOVertex.h:257
VBOVertex3< GLubyte > TexCoord3ub
Definition: VBOVertex.h:220
VBOVertex3< GLushort > VBOVertex3us
Definition: VBOVertex.h:189
bool operator<(const Vertex2 &other) const
Definition: VBOVertex.h:66
Vertex2(T _u, T _v)
Definition: VBOVertex.h:55
Definition: VBOVertex.h:176
Vertex2< GLdouble > Color2d
Definition: VBOVertex.h:104
VBOVertex3< GLfloat > Vertex3f
Definition: VBOVertex.h:202
VBOVertex3< GLushort > Color3us
Definition: VBOVertex.h:212
bool operator==(const VBOVertex4 &other) const
Definition: VBOVertex.h:276
VBOVertex3< GLfloat > TexCoord3f
Definition: VBOVertex.h:225
VBOVertex3< GLuint > VBOVertex3ui
Definition: VBOVertex.h:191
void g(T _g)
Definition: VBOVertex.h:146
Vertex2< GLuint > Vertex2ui
Definition: VBOVertex.h:93
VBOVertex3< GLfloat > VBOVertex3f
Definition: VBOVertex.h:192
VBOVertex4< GLubyte > Vertex4ub
Definition: VBOVertex.h:294
VBOVertex3< GLuint > TexCoord3ui
Definition: VBOVertex.h:224
Definition: AvalancheTrainingSimulationEngine.h:28
T w() const
Definition: VBOVertex.h:249
void set(T _u, T _v)
Definition: VBOVertex.h:60
Vertex2< GLdouble > TexCoord2d
Definition: VBOVertex.h:113
Vertex2< GLbyte > Vertex2b
Definition: VBOVertex.h:88
VBOVertex4< GLdouble > Color4d
Definition: VBOVertex.h:309
bool operator==(const Vertex2 &other) const
Definition: VBOVertex.h:73
Definition: VBOVertex.h:51
T r() const
Definition: VBOVertex.h:250
VBOVertex4< GLshort > Vertex4s
Definition: VBOVertex.h:295
T u() const
Definition: VBOVertex.h:77
VBOVertex3< GLubyte > Vertex3ub
Definition: VBOVertex.h:197
bool operator<(const VBOVertex3 &other) const
Definition: VBOVertex.h:150
VBOVertex3< GLdouble > Color3d
Definition: VBOVertex.h:216
Definition: VBOVertex.h:228
T v() const
Definition: VBOVertex.h:78
VBOVertex4< GLbyte > Color4b
Definition: VBOVertex.h:302
bool operator==(const VBOVertex3 &other) const
Definition: VBOVertex.h:159
Vertex2< GLint > Vertex2i
Definition: VBOVertex.h:92
T g() const
Definition: VBOVertex.h:251
~VBOVertex()
Definition: VBOVertex.h:25
VBOVertex4< GLint > Vertex4i
Definition: VBOVertex.h:297
Vertex2< GLshort > Color2s
Definition: VBOVertex.h:99
VBOVertex3< GLshort > Color3s
Definition: VBOVertex.h:211
VBOVertex3< GLuint > Color3ui
Definition: VBOVertex.h:214
Vertex2< GLbyte > Color2b
Definition: VBOVertex.h:97
void u(T _u)
Definition: VBOVertex.h:82
VBOVertex3< GLuint > Vertex3ui
Definition: VBOVertex.h:201
T z() const
Definition: VBOVertex.h:248
Vertex2< GLubyte > TexCoord2ub
Definition: VBOVertex.h:107
VBOVertex4< GLubyte > Color4ub
Definition: VBOVertex.h:303
VBOVertex4< GLuint > Vertex4ui
Definition: VBOVertex.h:298
T r() const
Definition: VBOVertex.h:134
Vertex2< GLushort > Vertex2us
Definition: VBOVertex.h:91