-
Notifications
You must be signed in to change notification settings - Fork 0
/
Off.cpp
112 lines (92 loc) · 1.81 KB
/
Off.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
#include "Off.h"
COff::COff()
{
}
COff::~COff()
{
}
bool COff::load(string path)
{
fstream file;
string token, token2, token3, v1, v2, v3;
vector<int> caras(3);
float vx, vy, vz;
file.open(path, std::ios::in);
file >> token;
if (token != "OFF")
{
file.close();
return false;
}
else
{
tipo = token;
file >> token;
file >> token2;
file >> token3;
mNumOfVertices = atoi(token.c_str());
mNumOfCaras = atoi(token2.c_str());
file >> v1;
file >> v2;
file >> v3;
vx = atof(v1.c_str());
vy = atof(v2.c_str());
vz = atof(v3.c_str());
xMin = xMax = vx;
yMin = yMax = vy;
zMin = zMax = vz;
mVertices.push_back(glm::vec3(vx, vy, vz));
for (int i = 0; i < mNumOfVertices-1; i++)
{
file >> v1;
file >> v2;
file >> v3;
/*glm::vec3 normalized = glm::normalize(glm::vec3((atof(v1.c_str())), (atof(v2.c_str())), (atof(v3.c_str()))));
mVertices.push_back(normalized);*/
vx = atof(v1.c_str());
vy = atof(v2.c_str());
vz = atof(v3.c_str());
mVertices.push_back(glm::vec3(vx,vy,vz));
if (vx <= xMin)
xMin = vx;
if (vy <= yMin)
yMin = vy;
if (vz <= zMin)
zMin = vz;
if (vx >= xMax)
xMax = vx;
if (vy >= yMax)
yMax = vy;
if (vz >= zMax)
zMax = vz;
}
for (int i = 0; i < mNumOfCaras; i++)
{
file >> token3;
int numofveccara = atoi(token3.c_str());
int j = 3;
file >> v1;
file >> v2;
file >> v3;
caras[0] = atoi(v1.c_str());
caras[1] = atoi(v2.c_str());
caras[2] = atoi(v3.c_str());
mCaras.push_back(caras);
if (numofveccara > 3)
{
while (j < numofveccara)
{
caras[1] = caras[2];
file >> v1;
caras[2] = atoi(v1.c_str());
mCaras.push_back(caras);
j++;
}
}
file.ignore(10000, '\n');
}
mNumOfCaras = mCaras.size();
file.close();
return true;
}
}