blob: 013edcc5d781e7a7de96272457685b954671a244 (
plain)
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
|
/*
render/model.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CORE_MODEL_H__
#define __INCLUDED_CORE_MODEL_H__
#include <vector>
#include <map>
#include <list>
#include "math/mathlib.h"
#include "math/plane3f.h"
#include "core/entity.h"
namespace core
{
/// one face (polygon) of a model
class Face {
public:
Face(math::Vector3f const & normal, math::Color const *color=0);
~Face();
/// the normal of this face
inline math::Vector3f const & normal() const { return face_normal; };
/// the color of this face
inline math::Color const *color() const { return face_color; };
/// add a vertex to the face
void add_vertex(math::Vector3f const &vertex);
/// face vertexes
std::vector<math::Vector3f *> face_vertex;
private:
math::Vector3f face_normal;
math::Color *face_color;
};
/// a spacecraft engine
class Engine
{
public:
Engine(math::Vector3f const & location);
~Engine();
inline math::Vector3f const & location() const
{
return engine_location;
}
private:
math::Vector3f engine_location;
};
/// an exterior light
class Light
{
public:
Light(math::Vector3f const & location, math::Color const & color);
~Light();
inline math::Vector3f const & location() const { return light_location; }
inline math::Color const & color() const { return light_color; };
private:
math::Vector3f light_location;
math::Color light_color;
};
/// a 3D model contains a list of faces
class Model
{
public:
/// load a model from disk
Model(std::string const & name);
~Model();
/// the name of the model
inline std::string const & name() const
{
return model_name;
}
/// the Model registry
static std::map<std::string, Model*> registry;
/* ---- static functions for the Model registry -------------------- */
/// get name model, returns 0 if not found
static Model *find(std::string const & name);
/// get named model from the registry and load it if necessary
static Model *get(std::string const & name);
/// clear the model registry
static void clear();
/// list the content of the model registry
static void list();
/// list of Faces
std::list<Face *> model_face;
/// list of Engines
std::list<Engine *> model_engine;
/// list of Lights
std::list<Light *> model_light;
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
void add_engine(Engine *engine);
void add_face(Face *face);
void add_light(Light *light);
std::string model_name;
float model_scale;
bool model_valid;
};
}
#endif // __INCLUDED_RENDER_MODEL_H__
|