-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrimesh.cpp
More file actions
118 lines (96 loc) · 2.97 KB
/
trimesh.cpp
File metadata and controls
118 lines (96 loc) · 2.97 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "trimesh.h"
trimesh::trimesh(int _rows, int _cols, float _width, float _height, int _color)
{
rows = _rows + 1;
cols = _cols + 1;
width = _width;
height = _height;
color = _color;
//calculate height and width
float rowWidth = width / rows;
float colHeight = height / cols;
//color var
meshColor = ofColor();
//create verticies
for (int rowCount = 0; rowCount<rows; rowCount++)
{
for (int colCount = 0; colCount<cols; colCount++)
{
float y = rowCount * rowWidth * -1;
float x = colCount * colHeight;
mesh.addVertex(ofVec3f(x,y,0));
meshColor.setHsb(color,200,200,200);
mesh.addColor(meshColor);
}
}
/////////////////////////////////
//create index vector///////////
///////////////////////////////
vector<int> indices;
//location along the drawing path
int indexLocation = 0;
//two points per column, don't connect indexes
//on the last row
int rowSteps = rows - 1;
int colSteps = cols * 2;
//spacing switch keeps you in the correct place
//for counting spaces between indexes
int spacingSwitch = 0;
for (int row = 0; row<rowSteps; row++)
{
for (int col = 0; col<colSteps; col++)
{
//if this is the last index location
//write final location
if (col == colSteps - 1)
{
indices.push_back(indexLocation);
}
else
{
//if spacing switch is even increment index location forward
//by the number of columns, otherwise refer to next if statement
if (spacingSwitch%2 == 0)
{
indexLocation += cols;
indices.push_back(indexLocation);
}
else
{
//if row is even subtract from total columns
//else add to total colums for index number spacing
if (row%2 == 0)
{
indexLocation -= cols-1;
indices.push_back(indexLocation);
}
else
{
indexLocation -= cols+1;
indices.push_back(indexLocation);
}
}
}
spacingSwitch++;
}
}
/////////////////////////////////
//add indicies to mesh /////////
///////////////////////////////
//add 0,0,0 location manually
mesh.addIndex(0);
for (int i=0; i<indices.size(); i++)
{
mesh.addIndex(indices[i]);
}
//add to vbo
myVbo.setMesh(mesh, GL_DYNAMIC_DRAW);
}
void trimesh::update()
{
}
void trimesh::draw()
{
myVbo.drawElements(GL_TRIANGLE_STRIP, mesh.getNumIndices());
}
}