-
Notifications
You must be signed in to change notification settings - Fork 0
/
NA_ObjLoader.cpp
97 lines (78 loc) · 1.87 KB
/
NA_ObjLoader.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
// unused and incomplete code
#include "stdafx.h"
#include "NA_ObjLoader.h"
#include <fstream>
#include <iostream>
#include <string> // std::getLine
#include <vector>
using std::vector;
NA_ObjLoader na_objLoader; // access with extern NA_ObjLoader na_objLoader
NA_ObjLoader::NA_ObjLoader()
{
}
NA_ObjLoader::~NA_ObjLoader()
{
}
// https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from
#include <direct.h>
#define GetCurrentDir _getcwd
bool NA_ObjLoader::load(string fileName, NA_Obj* objOut)
{
// http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/
// check for valid output
if (objOut == NULL)
{
std::cout << "NA_ObjLoader::load - pointer to output is NULL\n";
return false;
}
// open the file
std::ifstream objFile;
objFile.open(fileName);
if (!objFile.is_open())
{
std::cout << "Failed to open file " << GetCurrentDir(NULL, 0) << "/" << fileName << "\n"; //BUG: no matter what I point this too it fails to open
return false;
}
// load file via iostream into std::vector
std::vector<string> temp;
while (!objFile.eof())
{
string line;
objFile >> line;
std::cout << line;
temp.push_back(line); //TODO: check that this copies line and doesn't just reference it
}
objFile.close();
// seperate components based of first char of line into 3 seperate std::vectors
// pack std::vectors into NA_Obj (convert to arrays first?)
return true;
}
NA_Obj::NA_Obj()
{
}
NA_Obj::~NA_Obj()
{
if (vertex != NULL)
{
delete vertex;
vertex = NULL;
vertexCount = 0;
}
if (normal != NULL)
{
delete normal;
normal = NULL;
normalCount = 0;
}
if (face != NULL)
{
delete face;
face = NULL;
faceCount = 0;
}
}
NA_Tri NA_Obj::getFace(int faceID)
{
//TODO: NA_Obj::getFace
return NA_Tri();
}