-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphObject.cpp
188 lines (152 loc) · 3.78 KB
/
GraphObject.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "GraphObject.h"
#include <cstring>
using namespace std;
int Model::retVertCount()
{
return wierzcholki.size();
}
int Model::retElemCount()
{
return 3*trojkaty.size();
}
glm::vec3 Model::wyznaczVertNormal(int abc, Vertex & vert_buf)
{
int norm;
float nx = 0.0, ny = 0.0, nz = 0.0;
glm::vec3 vnorm;
int count = 0;
typedef vector<Triangle>::iterator Iter;
Iter iter = trojkaty.begin();
while (iter != trojkaty.end())
{
if (iter->a == abc || iter->b == abc || iter->c == abc) {
norm = iter->normalna;
glm::vec3 vn = normalne[norm];
nx+= vn.x;
ny+= vn.y;
nz+= vn.z;
count++;
}
iter++;
}
if (count)
{
vnorm.x = nx / count;
vnorm.y = ny / count;
vnorm.z = nz / count;
}
vert_buf.nx = vnorm.x;
vert_buf.ny = vnorm.y;
vert_buf.nz = vnorm.z;
return vnorm;
}
void Model::wyznaczAllVertNormal()
{
int abc;
typedef map<int, Vertex>::iterator Iter;
Iter iter = wierzcholki.begin();
while (iter != wierzcholki.end())
{
int abc = iter->first;
Vertex & vert = iter->second;
glm::vec3 wynik = wyznaczVertNormal(abc, vert);
// cout << "abc:" << abc << ", vert:"<<vert << ", norm( x:" <<wynik.x<<" y:" <<wynik.y<<" z:"<<wynik.z<<")"<<endl;
iter++;
}
}
int Model::retBufVert(Vertex * bufor)
{
int ile = 0;
typedef map<int, Vertex>::iterator Iter;
Iter iter = wierzcholki.begin();
while (iter != wierzcholki.end())
{
int pos = iter->first;
Vertex vert = iter->second;
/*
bufor[ile++] = vert.x;
bufor[ile++] = vert.y;
bufor[ile++] = vert.z;
bufor[ile++] = vert.r;
bufor[ile++] = vert.g;
bufor[ile++] = vert.b;
*/
bufor[ile++] = vert;
iter++;
}
return ile;
}
int Model::retBufElem(GLint * bufor)
{
int ile = 0;
typedef vector<Triangle>::iterator Iter;
Iter iter = trojkaty.begin();
while (iter != trojkaty.end())
{
bufor[ile++] = iter->a;
bufor[ile++] = iter->b;
bufor[ile++] = iter->c;
iter++;
}
return ile;
}
int Model::retBufCount()
{
bufCount = trojkaty.size()*3;
return bufCount;
}
int Model::retBuf(Vertex * bufor)
{
bufCount = 0;
typedef vector<Triangle>::iterator Iter;
Iter iter = trojkaty.begin();
int i = 0;
while (iter != trojkaty.end())
{
Triangle & triangle = *iter;
int a,b,c;
a= triangle.a;
b= triangle.b;
c= triangle.c;
bufCount += 3;
bufor[i++] = wierzcholki[a];
bufor[i - 1].kolor = triangle.kolor;
bufor[i - 1].nx = normalne[triangle.normalna].x;
bufor[i - 1].ny = normalne[triangle.normalna].y;
bufor[i - 1].nz = normalne[triangle.normalna].z;
bufor[i++] = wierzcholki[b];
bufor[i - 1].kolor = triangle.kolor;
bufor[i - 1].nx = normalne[triangle.normalna].x;
bufor[i - 1].ny = normalne[triangle.normalna].y;
bufor[i - 1].nz = normalne[triangle.normalna].z;
bufor[i++] = wierzcholki[c];
bufor[i - 1].kolor = triangle.kolor;
bufor[i - 1].nx = normalne[triangle.normalna].x;
bufor[i - 1].ny = normalne[triangle.normalna].y;
bufor[i - 1].nz = normalne[triangle.normalna].z;
iter++;
}
return bufCount;
}
int Model::retBufVerticesOnly(Vertex * bufor)
{
memcpy(bufor, &Vertices[0], Vertices.size()*sizeof(Vertex));
// bufor = &Vertices[0];
}
void Model::ustawKolorAllVert(Kolor kol)
{
typedef map<int, Vertex>::iterator Iter;
Iter iter = wierzcholki.begin();
while (iter != wierzcholki.end())
{
int pos = iter->first;
Vertex & vert = iter->second;
vert.kolor = kol;
iter++;
}
for (int i = 0; i < trojkaty.size(); i++)
{
Triangle & tr = trojkaty[i];
tr.kolor = kol;
}
}