-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.cpp
More file actions
47 lines (37 loc) · 998 Bytes
/
grid.cpp
File metadata and controls
47 lines (37 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "grid.h"
using namespace std;
Grid::Grid(unsigned int size,float minval,float maxval) {
const float w = maxval-minval;
const float h = w;
const float stepW = w/(float)size;
const float stepH = h/(float)size;
const float startx = minval;
const float starty = minval;
for(unsigned int i=0;i<size;++i) {
for(unsigned int j=0;j<size;++j) {
const float currentx = startx+stepW*(float)j;
const float currenty = starty+stepH*(float)i;
_vertices.push_back(currentx);
_vertices.push_back(currenty);
_vertices.push_back(0.0f);
if(i>0 && j>0) {
int i1 = i*size+j;
int i2 = (i-1)*size+j;
int i3 = (i-1)*size+j-1;
int i4 = i*size+j-1;
_faces.push_back(i1);
_faces.push_back(i2);
_faces.push_back(i3);
_faces.push_back(i3);
_faces.push_back(i4);
_faces.push_back(i1);
}
}
}
_nbVertices = _vertices.size()/3;
_nbFaces = _faces.size()/3;
}
Grid::~Grid() {
_vertices.clear();
_faces.clear();
}