-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj_file.cpp
More file actions
52 lines (45 loc) · 1.3 KB
/
Copy pathobj_file.cpp
File metadata and controls
52 lines (45 loc) · 1.3 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
#include <iostream>
#include <fstream>
#include <algorithm>
#include "geometrics.h"
#include "obj_file.h"
#include "world.h"
void Obj_File::read_obj()
{
ifstream my_obj(filename.c_str());
string line;
string line_desc;
while (getline(my_obj, line)) {
stringstream line_stream(line);
if (line_stream >> line_desc) {
if (line_desc == "v") {
read_v_line(line);
}
if (line_desc == "f") {
read_f_line(line);
}
}
}
}
void Obj_File::read_v_line(string line) {
stringstream line_stream(line);
char first;
double x, y, z;
line_stream >> first >> x >> y >> z;
World::points.push_back(new Point(x, y, z));
}
void Obj_File::read_f_line(string line) {
int v0a, v0b, v0c, v1a, v1b, v1c, v2a, v2b, v2c, v3a, v3b, v3c;
char first;
if (line.find("/") == string::npos) {
sscanf(line.c_str(), "%c %d %d %d", &first, &v0a, &v1a, &v2a);
Triangle *t = new Triangle(v0a-1, v1a-1, v2a-1);
World::polygons.push_back(t);
}
else {
sscanf(line.c_str(), "%c %d//%*d %d//%*d %d//%*d", &first, &v0a, &v1a, &v2a);
Triangle *t = new Triangle(v0a-1, v1a-1, v2a-1);
World::polygons.push_back(t);
// printf("Unsupported obj file\n");
}
}