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
|
/*
model/fragment.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_FRAGMENT_H__
#define __INCLUDED_MODEL_FRAGMENT_H__
#include <list>
#include "math/axis.h"
#include "math/vector3f.h"
#include "math/vector2f.h"
#include "model/material.h"
namespace model
{
/// a fragment of a model, a pointer into a continuous part of the VertexArray containing tris or quads
class Fragment
{
public:
/// fragment primitive type: triangles or quads
enum Type {Triangles, Quads};
/// create a new fragment
Fragment(Type type, const Material *material);
/**
* @brief copy constructor
*/
Fragment(const Fragment &other);
/// add a vertex to the fragment
size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, bool detail);
/// add a vertex to the fragment
size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, math::Vector2f const &texcoord, bool detail);
/// the type of primitives this fragment consists of
inline Type type() const {
return fragment_type;
}
/// VertexArray index of the start of the fragment
inline size_t index() const {
return fragment_index;
}
/// number of structural vertices in the fragment
inline size_t structural_size() const {
return fragment_structural_size;
}
/// number of detail vertices in the fragment
inline size_t detail_size() const {
return fragment_detail_size;
}
/// material flags
inline const Material * material() const {
return fragment_material;
}
private:
Type fragment_type;
size_t fragment_index;
size_t fragment_structural_size;
size_t fragment_detail_size;
const Material * fragment_material;
};
/// a collection of fragments
/**
* a FragmentGroup contains the model fragments for one class in the .map file.
* worldspawn is a FragmentGroup
*/
class FragmentGroup
{
public:
enum Type {None = 0, Rotate = 1, Move = 3, Door = 2 };
/// type definition for a list of model fragments
typedef std::list<Fragment *> Fragments;
FragmentGroup();
~FragmentGroup();
/* ---- inspectors ----------------------------------------- */
inline const Type type() const {
return group_type;
}
inline const math::Vector3f &location() const {
return group_location;
}
/**
* @brief movement vector for moving groups
* For rotating groups, this is the rotation axis
*/
inline const math::Vector3f &movement() const {
return group_movement;
}
/**
* @brief local rotation matrix of the group
*/
inline const math::Axis & axis() const {
return group_axis;
}
inline const float speed() const {
return group_speed;
}
inline const float distance() const {
return group_distance;
}
inline const float scale() const {
return group_scale;
}
inline const bool engine() const {
return group_engine;
}
inline const size_t size() const {
return group_fragments.size();
}
inline const Fragments & fragments() const {
return group_fragments;
}
/* ---- mutators ------------------------------------------- */
inline void set_type(const Type type) {
group_type = type;
}
inline void set_engine(const bool engine) {
group_engine = engine;
}
inline void set_location(const math::Vector3f &location) {
group_location.assign(location);
}
inline void set_movement(const math::Vector3f &movement) {
group_movement.assign(movement);
}
/**
* @brief set the rotation axis
* set the local rotation matrix of the group
*/
inline void set_axis(const math::Axis &axis) {
group_axis.assign(axis);
}
/**
* @brief set movement speed
* For rotating groups this is the number of degrees per second
* For movers, this is the speed in units per second
*/
inline void set_speed(const float speed) {
group_speed = speed;
}
inline void set_distance(const float distance) {
group_distance = distance;
}
inline void set_scale(const float scale) {
group_scale = scale;
}
inline void add_fragment(Fragment *fragment) {
group_fragments.push_back(fragment);
}
void clear();
private:
Fragments group_fragments;
math::Vector3f group_location;
math::Axis group_axis;
Type group_type;
float group_speed;
float group_scale;
float group_distance;
bool group_engine;
math::Vector3f group_movement;
};
}
#endif // __INCLUDED_MODEL_FRAGMENT_H__
|