diff --git a/src/DataHandling/Model3D.cpp b/src/DataHandling/Model3D.cpp index 185eb13..b46e711 100644 --- a/src/DataHandling/Model3D.cpp +++ b/src/DataHandling/Model3D.cpp @@ -55,36 +55,24 @@ void Model3D::draw_model() { Vec3i face = faces[i]; - Vec3i face_texture; + Vec3i* face_texture; if (is_textured) { - face_texture = face_textures[i]; + face_texture = &face_textures[i]; } - // FIXME : Find a better way to draw the three vertices - Vec3f vertex = vertices[face.x]; - if (is_textured) + // Draw each vertex and texture it if needed + for (int j = 0; j < 3; j++) { - Vec2f vertex_texture = texture_coordinates[face_texture.x]; - glTexCoord2f(vertex_texture.x,vertex_texture.y); - } - glVertex3f(vertex.x,vertex.y,vertex.z); + Vec3f& vertex = vertices[face.coordinates[j]]; - vertex = vertices[face.y]; - if (is_textured) - { - Vec2f vertex_texture = texture_coordinates[face_texture.y]; - glTexCoord2f(vertex_texture.x,vertex_texture.y); + if (is_textured) + { + Vec2f vertex_texture = texture_coordinates[face_texture->coordinates[j]]; + glTexCoord2f(vertex_texture.x,vertex_texture.y); + } + glVertex3f(vertex.x,vertex.y,vertex.z); } - glVertex3f(vertex.x,vertex.y,vertex.z); - - vertex = vertices[face.z]; - if (is_textured) - { - Vec2f vertex_texture = texture_coordinates[face_texture.z]; - glTexCoord2f(vertex_texture.x,vertex_texture.y); - } - glVertex3f(vertex.x,vertex.y,vertex.z); } glEnd(); diff --git a/src/types.h b/src/types.h index e052454..6c3349e 100644 --- a/src/types.h +++ b/src/types.h @@ -7,14 +7,33 @@ #include +/// Group of coordinates with the input operator overloaded. +/// \tparam T Content of the vector +/// \tparam N Number of coordinates +template +struct CoordinatesVector +{ + T coordinates[N]; + + friend std::fstream& operator>>(std::fstream& stream, CoordinatesVector& vector) + { + for (unsigned int i = 0;i> vector.coordinates[i]; + } + return stream; + } +}; + template -struct Vec2 +struct CoordinatesVector { - T x; - T y; + T coordinates[2]; + T& x = coordinates[0]; + T& y = coordinates[1]; - friend std::fstream& operator>>(std::fstream& stream, Vec2& vec2) + friend std::fstream& operator>>(std::fstream& stream, CoordinatesVector& vec2) { stream >> vec2.x >> vec2.y; return stream; @@ -22,13 +41,15 @@ struct Vec2 }; template -struct Vec3 +struct CoordinatesVector { - T x; - T y; - T z; + T coordinates[3]; - friend std::fstream& operator>>(std::fstream& stream, Vec3& vec3) + T& x = coordinates[0]; + T& y = coordinates[1]; + T& z = coordinates[2]; + + friend std::fstream& operator>>(std::fstream& stream, CoordinatesVector& vec3) { stream >> vec3.x >> vec3.y >> vec3.z; return stream; @@ -37,11 +58,11 @@ struct Vec3 // Define aliases for common types -typedef Vec2 Vec2i; -typedef Vec2 Vec2f; +typedef CoordinatesVector Vec2i; +typedef CoordinatesVector Vec2f; -typedef Vec3 Vec3i; -typedef Vec3 Vec3f; +typedef CoordinatesVector Vec3i; +typedef CoordinatesVector Vec3f; #endif //TESTS_OPENGL_TYPES_H