77 create(aLength, anIndexDataType);
88 m_external_data_flag =
false;
91 double half_length(aLength / 2.0);
93 m_local_min_corner =
VEC3(-half_length, -half_length, -half_length);
94 m_local_max_corner =
VEC3( half_length, half_length, half_length);
99 VEC3 top_far_left( -half_length, half_length, -half_length);
100 VEC3 top_near_left( -half_length, half_length, half_length);
101 VEC3 top_far_right( half_length, half_length, -half_length);
102 VEC3 top_near_right( half_length, half_length, half_length);
105 VEC3 bottom_far_left( top_far_left.
getX(), -top_far_left.
getY(), top_far_left.
getZ());
106 VEC3 bottom_near_left( top_near_left.
getX(), -top_near_left.
getY(), top_near_left.
getZ());
107 VEC3 bottom_far_right( top_far_right.
getX(), -top_far_right.
getY(), top_far_right.
getZ());
108 VEC3 bottom_near_right(top_near_right.
getX(), -top_near_right.
getY(), top_near_right.
getZ());
111 std::vector<T> p_vertex_set;
112 std::vector<T> p_normal_set;
113 std::vector<unsigned char> p_ubyte_index_set;
116 p_vertex_set.push_back(top_far_left.
getX());
117 p_vertex_set.push_back(top_far_left.
getY());
118 p_vertex_set.push_back(top_far_left.
getZ());
120 p_vertex_set.push_back(top_near_left.
getX());
121 p_vertex_set.push_back(top_near_left.
getY());
122 p_vertex_set.push_back(top_near_left.
getZ());
124 p_vertex_set.push_back(top_far_right.
getX());
125 p_vertex_set.push_back(top_far_right.
getY());
126 p_vertex_set.push_back(top_far_right.
getZ());
128 p_vertex_set.push_back(top_near_right.
getX());
129 p_vertex_set.push_back(top_near_right.
getY());
130 p_vertex_set.push_back(top_near_right.
getZ());
132 p_vertex_set.push_back(bottom_far_left.getX());
133 p_vertex_set.push_back(bottom_far_left.getY());
134 p_vertex_set.push_back(bottom_far_left.getZ());
136 p_vertex_set.push_back(bottom_near_left.getX());
137 p_vertex_set.push_back(bottom_near_left.getY());
138 p_vertex_set.push_back(bottom_near_left.getZ());
140 p_vertex_set.push_back(bottom_far_right.getX());
141 p_vertex_set.push_back(bottom_far_right.getY());
142 p_vertex_set.push_back(bottom_far_right.getZ());
144 p_vertex_set.push_back(bottom_near_right.getX());
145 p_vertex_set.push_back(bottom_near_right.getY());
146 p_vertex_set.push_back(bottom_near_right.getZ());
151 p_ubyte_index_set.push_back(1);
152 p_ubyte_index_set.push_back(2);
153 p_ubyte_index_set.push_back(0);
155 p_ubyte_index_set.push_back(2);
156 p_ubyte_index_set.push_back(1);
157 p_ubyte_index_set.push_back(3);
159 for (
unsigned int i = 0; i < 2; ++i)
161 p_normal_set.push_back(0);
162 p_normal_set.push_back(1);
163 p_normal_set.push_back(0);
167 p_ubyte_index_set.push_back(6);
168 p_ubyte_index_set.push_back(5);
169 p_ubyte_index_set.push_back(4);
171 p_ubyte_index_set.push_back(5);
172 p_ubyte_index_set.push_back(6);
173 p_ubyte_index_set.push_back(7);
175 for (
unsigned int i = 0; i < 2; ++i)
177 p_normal_set.push_back(0);
178 p_normal_set.push_back(-1);
179 p_normal_set.push_back(0);
183 p_ubyte_index_set.push_back(5);
184 p_ubyte_index_set.push_back(3);
185 p_ubyte_index_set.push_back(1);
187 p_ubyte_index_set.push_back(3);
188 p_ubyte_index_set.push_back(5);
189 p_ubyte_index_set.push_back(7);
191 for (
unsigned int i = 0; i < 2; ++i)
193 p_normal_set.push_back(0);
194 p_normal_set.push_back(0);
195 p_normal_set.push_back(1);
199 p_ubyte_index_set.push_back(2);
200 p_ubyte_index_set.push_back(4);
201 p_ubyte_index_set.push_back(0);
203 p_ubyte_index_set.push_back(4);
204 p_ubyte_index_set.push_back(2);
205 p_ubyte_index_set.push_back(6);
207 for (
unsigned int i = 0; i < 2; ++i)
209 p_normal_set.push_back(0);
210 p_normal_set.push_back(0);
211 p_normal_set.push_back(-1);
215 p_ubyte_index_set.push_back(5);
216 p_ubyte_index_set.push_back(0);
217 p_ubyte_index_set.push_back(4);
219 p_ubyte_index_set.push_back(0);
220 p_ubyte_index_set.push_back(5);
221 p_ubyte_index_set.push_back(1);
223 for (
unsigned int i = 0; i < 2; ++i)
225 p_normal_set.push_back(-1);
226 p_normal_set.push_back(0);
227 p_normal_set.push_back(0);
231 p_ubyte_index_set.push_back(2);
232 p_ubyte_index_set.push_back(7);
233 p_ubyte_index_set.push_back(6);
235 p_ubyte_index_set.push_back(7);
236 p_ubyte_index_set.push_back(2);
237 p_ubyte_index_set.push_back(3);
239 for (
unsigned int i = 0; i < 2; ++i)
241 p_normal_set.push_back(1);
242 p_normal_set.push_back(0);
243 p_normal_set.push_back(0);
249 std::vector<T> p_normal_set2;
251 for (
unsigned int vertex_id = 0; vertex_id < p_vertex_set.size() / 3; ++vertex_id)
257 unsigned int counter = 0;
259 for (
unsigned int face_id = 0; face_id < p_ubyte_index_set.size() / 3; ++face_id)
261 if (p_ubyte_index_set[face_id * 3] == vertex_id ||
262 p_ubyte_index_set[face_id * 3 + 1] == vertex_id ||
263 p_ubyte_index_set[face_id * 3 + 2] == vertex_id)
266 x += p_normal_set[face_id * 3];
267 y += p_normal_set[face_id * 3 + 1];
268 z += p_normal_set[face_id * 3 + 2];
279 p_normal_set2.push_back(x);
280 p_normal_set2.push_back(y);
281 p_normal_set2.push_back(z);
284 switch (anIndexDataType)
286 case GL_UNSIGNED_INT:
288 std::vector<GLuint> p_uint_index_set;
290 for (std::vector<GLubyte>::const_iterator ite(p_ubyte_index_set.begin());
291 ite != p_ubyte_index_set.end();
294 p_uint_index_set.push_back(*ite);
297 setInternalData(GL_TRIANGLES,
306 case GL_UNSIGNED_SHORT:
308 std::vector<GLushort> p_ushort_index_set;
310 for (std::vector<GLubyte>::const_iterator ite(p_ubyte_index_set.begin());
311 ite != p_ubyte_index_set.end();
314 p_ushort_index_set.push_back(*ite);
317 setInternalData(GL_TRIANGLES,
326 case GL_UNSIGNED_BYTE:
328 setInternalData(GL_TRIANGLES,
338 throw Exception(__FILE__, __FUNCTION__, __LINE__,
339 "Invalid data type.");
345 std::vector<T> p_vertex_set2;
346 std::vector<T> p_normal_set2;
349 for (std::vector<unsigned char>::const_iterator ite = p_ubyte_index_set.begin();
350 ite != p_ubyte_index_set.end();
353 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 0]);
354 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 1]);
355 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 2]);
357 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 0]);
358 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 1]);
359 p_normal_set2.push_back(p_normal_set[3 * (normal_id / 3) + 2]);
362 setInternalData(GL_TRIANGLES,
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.
CubeMesh is a class to handle 3D meshes of cubes.
PolygonMesh is a class to handle polygon (triangles) meshes.
Vec3< RATIONAL_NUMBER > VEC3
Type of data used to store 3D vectors.
CubeMesh(double aLength=1.0 *cm, int anIndexDataType=0)
Default constructor.