-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathObjModelLoader.h
More file actions
130 lines (117 loc) · 3.34 KB
/
ObjModelLoader.h
File metadata and controls
130 lines (117 loc) · 3.34 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
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
/**
* Class Name: ObjModelLoader
*
* Version: 1.0
* Date: March 28, 2015
*
* Author: Mohammad Zunayed Hassan
* Email: ZunayedHassanBD@gmail.com
*
* Last Updated:
*
* Changes History:
*/
#ifndef OBJMODELLOADER_H
#define OBJMODELLOADER_H
#include <iostream>
#include <cstdlib>
#include <vector>
#include <fstream>
#include <sstream>
#include <cmath>
#ifdef __APPLE__
#include <GLUT/gl.h>
#else
#include <GL/gl.h>
#endif
using namespace std;
/**
* Loads model from Wavefront Obj file (*.obj). Using triangles and normals
* as static object. No texture mapping.
*
* Warning: OBJ files must be triangulated. Non triangulated objects wont
* work! You can use Blender to triangulate.
*
* Exporting as Obj File on Blender:
* (a) Open Blender program. Create your model.
* (b) File -> Export -> Wavefront (.obj)
* (c) Now at the left side panel on "Export Obj" section check on
* "Triangulate Faces".
* (d) Click on "Export OBJ" button. It produce two files. For
* example: cube.obj and cube.mtl. We will only need the *.obj
* file only.
*
* Sample Usage:
* ObjModelLoader *mesh = NULL;
* mesh = new ObjModelLoader("C:\\data\\filename.obj");
*
* mesh->Draw();
*
*/
class ObjModelLoader
{
public:
/**
* Constructor
* @param string filename
* File name of the *.obj file with path.
* Example: "C:\\data\\cube.obj"
*/
ObjModelLoader(string filename);
/**
* Destructor
*/
~ObjModelLoader();
/**
* Draws model from *.obj file.
*/
void Draw();
private:
string filename = "";
vector<vector<float>*> *vertices = new vector<vector<float>*>;
vector<vector<int>*> *faces = new vector<vector<int>*>;
/**
* Split string to individual strings according to given option
*
* @param string text
* Text to be splitted
*
* char delimeter
* Separator for the string
*
* @return vector<string>*
* vector of strings
*
* @example
* If text = "Hello World", delimeter = ' '
* Then { "Hello", "World" }
*/
vector<string>* GetSplittedStrings(string text, char delimeter);
/**
* Converts string to float value
*
* @param string text
* Text to be converted
*
* @return float
* Converter value
*
* @example
* If text = "1.5"
* Then 1.5f
*/
float GetFloatFromString(string text);
/**
* Calculates normal from given points
*
* @param float *coord1, float *coord2, float *coord3
* 3 points of the triangle plane to be calculated
* for normal
*
* @return float*
* Array of float where normal points are located
* x, y, z coordinate.
*/
float* GetNormal(float *coord1, float *coord2, float *coord3);
};
#endif // OBJMODELLOADER_H