-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.h
145 lines (120 loc) · 3 KB
/
Model.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// Model.h
// RealtimeRending
//
// Created by Philipp Lensing on 23.10.14.
// Copyright (c) 2014 Philipp Lensing. All rights reserved.
//
#ifndef __RealtimeRending__Model__
#define __RealtimeRending__Model__
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <vector>
#include <limits>
#include <stdio.h>
#include "ShaderProgram.h"
#include "Material.h"
#include "Vector.h"
#include "Color.h"
#include "global.h"
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
#define GL_DEBUG
#ifdef GL_DEBUG
#define CHECKGL CheckGLErrors();
#else
#define CHECKGL ;
#endif
void CheckGLErrors();
using namespace std;
struct Usemtl
{
string mtl;
unsigned int byCount;
};
struct MyFace
{
unsigned int pidx[4], tidx[4];
bool hasTextureCoords = true;
};
struct Vertex
{
Vertex();
Vertex( const Vector& p, const Vector& n, float TexS, float TexT);
Vector Position;
Vector Normal;
float TexcoordS;
float TexcoordT;
};
class BoundingBox
{
public:
BoundingBox();
BoundingBox( const Vector& min, const Vector& max);
void calculateAllPoints();
Vector Min;
// Vector BaseMin;
Vector Max;
// Vector BaseMax;
Vector allPoints[8];
Vector allPointsBase[8];
};
class BoundingSphere
{
public:
BoundingSphere();
BoundingSphere(const Vector ¢er, const float &radius);
Vector Center;
Vector BaseCenter;
float Radius;
};
class Model
{
public:
Model();
~Model();
const BoundingBox& boundingBox() const;
const BoundingSphere& boundingSphere() const;
bool load( const char* Filename, bool FitSize=true);
bool load( const char* Filename, const char* VertexShader, const char* FragmentShader, bool FitSize=true);
bool loadMtl(string filename, string path);
void buildVerteciesForTexture();
void drawLines() const;
void drawTriangles() const;
void drawBounding() const;
// projectOnVector(const Vector& v);
// Hilfsfunktionen
vector<string> & split(const string &s, char delim, vector<string> &elems);
vector<string> split(const string &s, char delim);
//vector<Vector*> getAllNormals();
void createFace(string line);
void createVertices();
void calcBounding(const Vector& a, const Vector& b, const Vector& c);
void calcSphere();
void scale();
void convertToFloat(vector<float>& color, const vector<string> &splitted);
void drawSphere();
protected:
Material* m_pMaterials;
unsigned int m_MaterialCount;
Vertex* m_pVertices;
unsigned int m_VertexCount;
BoundingBox m_Box;
BoundingSphere m_Sphere;
Usemtl* m_pMaterialsAt;
unsigned int m_MaterialAtCount;
GLuint vertexBuffer;
GLuint indexBuffer;
vector<GLuint> indizes;
vector<unsigned int> mtlChange;
vector<Vector*> my_vertices;
//vector<Vector*> my_normals;
vector<Vector*> my_texture_points;
vector<MyFace*> faces;
vector<Material*> mtl;
private:
ShaderProgram sp;
};
#endif /* defined(__RealtimeRending__Model__) */