79 create(aWidth, aHeight, aDepth, anIndexDataType);
92 m_external_data_flag =
false;
95 double half_width(aWidth / 2.0);
96 double half_height(aHeight / 2.0);
97 double half_depth(aDepth / 2.0);
99 m_local_min_corner =
VEC3(-half_width, -half_height, -half_depth);
100 m_local_max_corner =
VEC3( half_width, half_height, half_depth);
105 VEC3 top_far_left( -half_width, half_height, -half_depth);
106 VEC3 top_near_left( -half_width, half_height, half_depth);
107 VEC3 top_far_right( half_width, half_height, -half_depth);
108 VEC3 top_near_right( half_width, half_height, half_depth);
111 VEC3 bottom_far_left( top_far_left.
getX(), -top_far_left.
getY(), top_far_left.
getZ());
112 VEC3 bottom_near_left( top_near_left.
getX(), -top_near_left.
getY(), top_near_left.
getZ());
113 VEC3 bottom_far_right( top_far_right.
getX(), -top_far_right.
getY(), top_far_right.
getZ());
114 VEC3 bottom_near_right(top_near_right.
getX(), -top_near_right.
getY(), top_near_right.
getZ());
117 std::vector<T> p_vertex_set;
118 std::vector<T> p_normal_set;
119 std::vector<unsigned char> p_ubyte_index_set;
122 p_vertex_set.push_back(top_far_left.
getX());
123 p_vertex_set.push_back(top_far_left.
getY());
124 p_vertex_set.push_back(top_far_left.
getZ());
126 p_vertex_set.push_back(top_near_left.
getX());
127 p_vertex_set.push_back(top_near_left.
getY());
128 p_vertex_set.push_back(top_near_left.
getZ());
130 p_vertex_set.push_back(top_far_right.
getX());
131 p_vertex_set.push_back(top_far_right.
getY());
132 p_vertex_set.push_back(top_far_right.
getZ());
134 p_vertex_set.push_back(top_near_right.
getX());
135 p_vertex_set.push_back(top_near_right.
getY());
136 p_vertex_set.push_back(top_near_right.
getZ());
138 p_vertex_set.push_back(bottom_far_left.getX());
139 p_vertex_set.push_back(bottom_far_left.getY());
140 p_vertex_set.push_back(bottom_far_left.getZ());
142 p_vertex_set.push_back(bottom_near_left.getX());
143 p_vertex_set.push_back(bottom_near_left.getY());
144 p_vertex_set.push_back(bottom_near_left.getZ());
146 p_vertex_set.push_back(bottom_far_right.getX());
147 p_vertex_set.push_back(bottom_far_right.getY());
148 p_vertex_set.push_back(bottom_far_right.getZ());
150 p_vertex_set.push_back(bottom_near_right.getX());
151 p_vertex_set.push_back(bottom_near_right.getY());
152 p_vertex_set.push_back(bottom_near_right.getZ());
157 p_ubyte_index_set.push_back(1);
158 p_ubyte_index_set.push_back(2);
159 p_ubyte_index_set.push_back(0);
161 p_ubyte_index_set.push_back(2);
162 p_ubyte_index_set.push_back(1);
163 p_ubyte_index_set.push_back(3);
165 for (
unsigned int i = 0; i < 2; ++i)
167 p_normal_set.push_back(0);
168 p_normal_set.push_back(1);
169 p_normal_set.push_back(0);
173 p_ubyte_index_set.push_back(6);
174 p_ubyte_index_set.push_back(5);
175 p_ubyte_index_set.push_back(4);
177 p_ubyte_index_set.push_back(5);
178 p_ubyte_index_set.push_back(6);
179 p_ubyte_index_set.push_back(7);
181 for (
unsigned int i = 0; i < 2; ++i)
183 p_normal_set.push_back(0);
184 p_normal_set.push_back(-1);
185 p_normal_set.push_back(0);
189 p_ubyte_index_set.push_back(5);
190 p_ubyte_index_set.push_back(3);
191 p_ubyte_index_set.push_back(1);
193 p_ubyte_index_set.push_back(3);
194 p_ubyte_index_set.push_back(5);
195 p_ubyte_index_set.push_back(7);
197 for (
unsigned int i = 0; i < 2; ++i)
199 p_normal_set.push_back(0);
200 p_normal_set.push_back(0);
201 p_normal_set.push_back(1);
205 p_ubyte_index_set.push_back(2);
206 p_ubyte_index_set.push_back(4);
207 p_ubyte_index_set.push_back(0);
209 p_ubyte_index_set.push_back(4);
210 p_ubyte_index_set.push_back(2);
211 p_ubyte_index_set.push_back(6);
213 for (
unsigned int i = 0; i < 2; ++i)
215 p_normal_set.push_back(0);
216 p_normal_set.push_back(0);
217 p_normal_set.push_back(-1);
221 p_ubyte_index_set.push_back(5);
222 p_ubyte_index_set.push_back(0);
223 p_ubyte_index_set.push_back(4);
225 p_ubyte_index_set.push_back(0);
226 p_ubyte_index_set.push_back(5);
227 p_ubyte_index_set.push_back(1);
229 for (
unsigned int i = 0; i < 2; ++i)
231 p_normal_set.push_back(-1);
232 p_normal_set.push_back(0);
233 p_normal_set.push_back(0);
237 p_ubyte_index_set.push_back(2);
238 p_ubyte_index_set.push_back(7);
239 p_ubyte_index_set.push_back(6);
241 p_ubyte_index_set.push_back(7);
242 p_ubyte_index_set.push_back(2);
243 p_ubyte_index_set.push_back(3);
245 for (
unsigned int i = 0; i < 2; ++i)
247 p_normal_set.push_back(1);
248 p_normal_set.push_back(0);
249 p_normal_set.push_back(0);
255 std::vector<T> p_normal_set2;
257 for (
unsigned int vertex_id = 0; vertex_id < p_vertex_set.size() / 3; ++vertex_id)
263 unsigned int counter = 0;
265 for (
unsigned int face_id = 0; face_id < p_ubyte_index_set.size() / 3; ++face_id)
267 if (p_ubyte_index_set[face_id * 3] == vertex_id ||
268 p_ubyte_index_set[face_id * 3 + 1] == vertex_id ||
269 p_ubyte_index_set[face_id * 3 + 2] == vertex_id)
272 x += p_normal_set[face_id * 3];
273 y += p_normal_set[face_id * 3 + 1];
274 z += p_normal_set[face_id * 3 + 2];
285 p_normal_set2.push_back(x);
286 p_normal_set2.push_back(y);
287 p_normal_set2.push_back(z);
290 switch (anIndexDataType)
292 case GL_UNSIGNED_INT:
294 std::vector<GLuint> p_uint_index_set;
296 for (std::vector<GLubyte>::const_iterator ite(p_ubyte_index_set.begin());
297 ite != p_ubyte_index_set.end();
300 p_uint_index_set.push_back(*ite);
303 setInternalData(GL_TRIANGLES,
312 case GL_UNSIGNED_SHORT:
314 std::vector<GLushort> p_ushort_index_set;
316 for (std::vector<GLubyte>::const_iterator ite(p_ubyte_index_set.begin());
317 ite != p_ubyte_index_set.end();
320 p_ushort_index_set.push_back(*ite);
323 setInternalData(GL_TRIANGLES,
332 case GL_UNSIGNED_BYTE:
334 setInternalData(GL_TRIANGLES,
344 throw Exception(__FILE__, __FUNCTION__, __LINE__,
345 "Invalid data type.");
351 std::vector<T> p_vertex_set2;
352 std::vector<T> p_normal_set2;
355 for (std::vector<unsigned char>::const_iterator ite = p_ubyte_index_set.begin();
356 ite != p_ubyte_index_set.end();
359 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 0]);
360 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 1]);
361 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 2]);
363 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 0]);
364 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 1]);
365 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 2]);
368 setInternalData(GL_TRIANGLES,
CuboidMesh(double aWidth=1.0 *cm, double aHeight=1.0 *cm, double aDepth=1.0 *cm, int anIndexDataType=0)
Default constructor.
T getX() const
Accessor on the position along the x-axis.
T getZ() const
Accessor on the position along the z-axis.
Exception is a class to handle exceptions.
T getY() const
Accessor on the position along the y-axis.
void create(double aWidth=1.0 *cm, double aHeight=1.0 *cm, double aDepth=1.0 *cm, int anIndexDataType=0)
Create a new cuboid.
PolygonMesh is a class to handle polygon (triangles) meshes.
Vec3< RATIONAL_NUMBER > VEC3
Type of data used to store 3D vectors.