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
|
/*
model/collisionmesh.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_COLLISIONMESH_H__
#define __INCLUDED_MODEL_COLLISIONMESH_H__
#include "math/mathlib.h"
#include "model/fragment.h"
#include "BulletCollision/CollisionShapes/btTriangleMesh.h"
#include <string>
#include <map>
namespace model
{
/**
* @brief a collection of triangles, representing the collision geometry of a model
* A CollisionModel consists of a number of collisionmeshes.
* */
class CollisionMesh
{
public:
/// type definition for the collisionmesh registry
typedef std::list<CollisionMesh *> Registry;
CollisionMesh();
/// copy constructor
CollisionMesh(const CollisionMesh &other);
~CollisionMesh();
/* ---- inspectors ----------------------------------------- */
/**
* @brief the number of triangles in the collision mesh
*/
inline size_t size() const {
return collisionmesh_size;
}
/**
* @brief the bullet triangle mesh object
*/
inline btTriangleMesh *triangles() {
return collisionmesh_triangles;
}
/**
* @brief location of the mesh within the parent model
* location() is a point in collision model coordinate space
* that indicates the (0,0,0) location of this mesh.
* The worldspawn mesh should have location (0,0,0)
* */
inline const math::Vector3f &location() const {
return collisionmesh_location;
}
/**
* @brief transformation axis
* For normal groups, this is the rotation matrix of the mesh
* For rotating groups axis->forward() is the axis of the rotation.
* For movers, axis->forward() is the axis of movement.
* */
inline const math::Axis & axis() const {
return collisionmesh_axis;
}
inline const math::Vector3f &movement() const {
return collisionmesh_movement;
}
inline const float speed() const {
return collisionmesh_speed;
}
inline const float distance() const {
return collisionmesh_distance;
}
inline const float scale() const {
return collisionmesh_scale;
}
inline const FragmentGroup::Type type() const {
return collisionmesh_type;
}
/* ---- mutators ------------------------------------------- */
/**
* @brief change the group type
* */
inline void set_type(const FragmentGroup::Type type) {
collisionmesh_type = type;
}
inline void set_location(const math::Vector3f &location) {
collisionmesh_location.assign(location);
}
inline void set_axis(const math::Axis &axis) {
collisionmesh_axis.assign(axis);
}
inline void set_movement(const math::Vector3f &movement) {
collisionmesh_movement.assign(movement);
}
/**
* @brief apply FragmentGroup parameters to the mesh
* This method applies the fragmentgroups type, location, axis, movement, distance, speed and scale
* to the collision mesh
*/
void set_params(const FragmentGroup &group);
/**
* @brief movement speed
* For rotating meshes 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) {
collisionmesh_speed = speed;
}
inline void set_distance(const float distance) {
collisionmesh_distance = distance;
}
inline void set_scale(const float scale) {
collisionmesh_scale = scale;
}
/**
* @brief add a triangle to the collision mesh
*/
void add_triangle(const math::Vector3f & v0, const math::Vector3f & v1, const math::Vector3f & v2);
private:
/// the materials registry
static Registry collisionmesh_registry;
static bool collisionmesh_initialized;
size_t collisionmesh_size;
btTriangleMesh *collisionmesh_triangles;
FragmentGroup::Type collisionmesh_type;
math::Vector3f collisionmesh_location;
math::Axis collisionmesh_axis;
math::Vector3f collisionmesh_movement;
float collisionmesh_speed;
float collisionmesh_scale;
float collisionmesh_distance;
bool collisionmesh_owns_triangles;
};
} // namespace model
#endif // __INCLUDED_MODEL_COLLISIONMESH_H__
|