-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.cpp
47 lines (35 loc) · 802 Bytes
/
model.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
#include <fstream>
#include "model.h"
#include "vector3.h"
Model::Model(const char *filename, float scaleAmount){
fstream file;
file.open(filename);
while(file.good()){
string input;
Vector3 vertex;
file >> input;
if(input == "v"){
file >> vertex.x;
file >> vertex.y;
file >> vertex.z;
vertex.scale(scaleAmount);
vertices.push_back(vertex);
center.add(vertex);
}
else if(input == "f"){
file >> vertex.x;
file >> vertex.y;
file >> vertex.z;
//vertex indices start from 1, so we need to decrement the index by 1
vertex.add(-1);
faces.push_back(vertex);
}
}
center.divide((float)vertices.size());
file.close();
}
void Model::mesh(){
for(auto it : faces){
triangles.push_back({vertices[it.x], vertices[it.y], vertices[it.z]});
}
}