Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: c15213ca7c3e1fb2003d2b34eeef62d654ae310a (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
   model/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_MODEL_MODEL_H__
#define __INCLUDED_MODEL_MODEL_H__

#include <string>
#include <list>
#include <map>

#include "math/mathlib.h"

#include "model/collisionmodel.h"
#include "model/tags.h"
#include "model/fragment.h"

/// classes representing 3D geometry
namespace model
{

/// scaling factor when loading model geometry
const float SCALE = 1.0f / 1024.0f;

const float ANGLEUP = -1.0f;
const float ANGLEDOWN = -2.0f;

/// a 3D model contains a list of faces
class Model
{
public:
	/// type definition for the model registry
	typedef std::map<std::string, Model*> Registry;

	/// type definition for a list of model fragments
	typedef std::list<Fragment *> Fragments;

	/// type definition for a list of model light tags
	typedef std::list<Light *> Lights;

	/// type definition for a list of model flare tags
	typedef std::list<Flare *> Flares;

	/// type definition for a list of model dock tags
	typedef std::list<Dock *> Docks;

	/// type definition for a list of model particle system tags
	typedef std::list<Particles *> ParticleSystems;

	/// type definition for a list of model sound tags
	typedef std::list<Sound *> Sounds;

	/// type definition for a list of FragmentGroups
	typedef std::list<FragmentGroup *> Groups;

	/// create a model with a name
	Model(const std::string & name);

	/// delete the model, and all fragments, lights, etc
	~Model();

	/// the name of the model
	inline const std::string & name() const {
		return model_name;
	}

	/// radius
	inline float radius() const {
		return model_radius;
	}

	/// additional model fragment groups
	inline Groups & groups() {
		return model_groups;
	}

	inline CollisionModel *collisionmodel() {
		return model_collisionmodel;
	}
	
	/// list of model light tags
	inline Lights & lights() {
		return model_lights;
	}

	/// list of model dock tags
	inline Docks & docks() {
		return model_docks;
	}

	/// list of model flare tags
	inline Flares & flares() {
		return model_flares;
	}

	/// list of model sound tags
	inline Sounds & sounds() {
		return model_sounds;
	}

	/// list of model particle system tags
	inline ParticleSystems & particles() {
		return model_particles;
	}

	inline const math::BoundingBox3f & box() const {
		return model_box;
	}

	/// engine sound loop for this model
	inline unsigned int enginesound() const {
		return model_enginesound;
	}

	/// impulse sound set for this model
	inline unsigned int impulsesound() const {
		return model_impulsesound;
	}

	/// engine color for this model
	inline const math::Color & enginecolor() const {
		return model_enginecolor;
	}
	
	/// original model origin
	inline const math::Vector3f & origin() const {
		return model_origin;
	}
	
	/// add a light tag to the model
	void add_light(Light *light);

	/// add a particle system tag to the model
	void add_particles(Particles *particles);

	/// add a flare tag to the model
	void add_flare(Flare *flare);

	/// add a docking location tag to the model
	void add_dock(Dock *dock);

	/// add a sound tag to the model
	void add_sound(Sound *sound);

	/// add a fragment group to the model
	void add_group(FragmentGroup *group);

	/// set model radius
	void set_radius(const float radius);
	
	/// set collision model
	void set_collisionmodel(CollisionModel *collisionmodel);
	
	/// set model origin
	void set_origin(const math::Vector3f &origin);
	
	math::Vector3f		model_origin;
	math::BoundingBox3f	model_box;

	unsigned int		model_enginesound;
	unsigned int		model_impulsesound;

	math::Color		model_enginecolor;

	/// total number of  triangles
	size_t			model_tris_count;
	/// number of detail triangles
	size_t			model_tris_detail_count;
	/// total number of quads
	size_t			model_quad_count;
	/// number of detail quads
	size_t			model_quad_detail_count;

	/* ---- static functions for the Model registry -------------------- */

	/// the model registry
	static inline Registry & registry() {
		return model_registry;
	}

	/// get name model, returns 0 if not found
	static Model *find(const std::string & name);

	/// get named model from the registry and load it if necessary
	static Model *load(const std::string & name);

	/// clear the model registry
	static void clear();

	/// list the content of the model registry
	static void list();

	/// list one model
	static void list_model(Model *model);


private:
	std::string		model_name;
	Docks			model_docks;
	Flares			model_flares;
	Sounds			model_sounds;
	Lights			model_lights;
	ParticleSystems		model_particles;
	Groups			model_groups;
	float			model_radius;
	static Registry 	model_registry;
	CollisionModel		*model_collisionmodel;
};

}

#endif // __INCLUDED_MODEL_MODEL_H__