/
model.h
132 lines (90 loc) · 3.81 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
/************************************************************************/
/* */
/* This file is part of VDrift. */
/* */
/* VDrift is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* VDrift is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with VDrift. If not, see <http://www.gnu.org/licenses/>. */
/* */
/************************************************************************/
#ifndef _MODEL_H
#define _MODEL_H
#include "opengl_utility.h"
#include "vertexarray.h"
#include "mathvector.h"
#include "aabb.h"
/// Loading data into the mesh vertexarray is implemented by derived classes.
class MODEL
{
friend class joeserialize::Serializer;
public:
MODEL();
MODEL(const std::string & filepath, std::ostream & error_output);
virtual ~MODEL();
/// Returns true if the model format is capable of saving to a file.
virtual bool CanSave() const;
/// Optional capability.
virtual bool Save(const std::string & strFileName, std::ostream & error_output) const;
virtual bool Load(const std::string & strFileName, std::ostream & error_output, bool genlist);
bool Load(const VERTEXARRAY & varray, std::ostream & error_output, bool genlist);
bool Serialize(joeserialize::Serializer & s);
bool WriteToFile(const std::string & filepath);
bool ReadFromFile(const std::string & filepath, std::ostream & error_output, bool generatelistid=true);
void GenerateListID(std::ostream & error_output);
void GenerateVertexArrayObject(std::ostream & error_output);
bool HaveVertexArrayObject() const;
void ClearVertexArrayObject();
/// Returns true if we have a vertex array object and stores the VAO handle and element count in the provided arguments.
/// Returns false if we have no vertex array object.
bool GetVertexArrayObject(GLuint & vao_out, unsigned int & elementCount_out) const;
void GenerateMeshMetrics();
void ClearMeshData();
int GetListID() const;
float GetRadius() const;
float GetRadiusXZ() const;
MATHVECTOR <float, 3> GetCenter();
bool HaveMeshData() const;
bool HaveMeshMetrics() const;
bool HaveListID() const;
void Clear();
const VERTEXARRAY & GetVertexArray() const;
void SetVertexArray(const VERTEXARRAY & newmesh);
void BuildFromVertexArray(const VERTEXARRAY & newmesh);
bool Loaded();
void Translate(float x, float y, float z);
void Rotate(float a, float x, float y, float z);
void Scale(float x, float y, float z);
AABB <float> GetAABB() const;
protected:
/// To be filled by the derived classes.
VERTEXARRAY mesh;
private:
bool generatedlistid;
bool generatedmetrics;
int listid;
bool generatedvao;
/// VAO means vertex array object.
GLuint vao;
std::vector <GLuint> vbos;
GLuint elementVbo;
unsigned int elementCount;
// Metrics.
float radius;
float radiusxz;
MATHVECTOR <float, 3> bboxmin;
MATHVECTOR <float, 3> bboxmax;
void RequireMetrics() const;
void RequireListID() const;
void ClearListID();
void ClearMetrics();
};
#endif