diff --git a/src/DataHandling/Model3D.cpp b/src/DataHandling/Model3D.cpp index b46e711..bc9fafd 100644 --- a/src/DataHandling/Model3D.cpp +++ b/src/DataHandling/Model3D.cpp @@ -53,7 +53,7 @@ void Model3D::draw_model() for (uint32_t i = 0;icoordinates[j]]; + Vec2f& vertex_texture = texture_coordinates[face_texture->coordinates[j]]; glTexCoord2f(vertex_texture.x,vertex_texture.y); } glVertex3f(vertex.x,vertex.y,vertex.z); diff --git a/src/Vectors.h b/src/Vectors.h index e9c5a5b..29bdf82 100644 --- a/src/Vectors.h +++ b/src/Vectors.h @@ -18,7 +18,7 @@ struct CoordinatesVector /// Computes the euclidean norm of the vector. /// \return The magnitude. - double magnitude() + double magnitude() const { // TODO : Save magnitude if the vector has not been modified. double sum_of_squares = 0; @@ -29,10 +29,12 @@ struct CoordinatesVector return sqrt(sum_of_squares); } - // Use SFINAE to allow normalization of floating point + // Use SFINAE to allow normalization of floating point. + // The template argument is used to force substitution and thus checking the enable_if. /// Normalizes the vector using its euclidean norm. /// \return Nothing, the vector is normalized in-place. - typename std::enable_if::value,void>::type + template + typename std::enable_if::value,void>::type normalize() { double norm = magnitude(); @@ -42,6 +44,19 @@ struct CoordinatesVector } } + + template + typename std::enable_if::value,T>::type + dot_product(const CoordinatesVector& operand) const + { + T result = 0; + for (unsigned int i = 0;i typename std::enable_if::value,CoordinatesVector>::type @@ -104,6 +119,17 @@ struct Vec2 : public CoordinatesVector Vec2() = default; + Vec2(T x_axis, T y_axis) + { + x = x_axis; + y = y_axis; + } + + Vec2(const Vec2& original): x(CoordinatesVector::coordinates[0]), y(CoordinatesVector::coordinates[1]) + { + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); + } + // Cast-copy constructor in order to use the operators of the mother class. Vec2(const CoordinatesVector& origin) { @@ -133,15 +159,39 @@ struct Vec3 : CoordinatesVector Vec3() = default; - // Cast-copy constructor in order to use the operators of the mother class. - Vec3(const CoordinatesVector& origin) + Vec3(T x_axis, T y_axis, T z_axis) { - if (this != &origin) + x = x_axis; + y = y_axis; + z = z_axis; + } + + Vec3(const Vec3& original): x(CoordinatesVector::coordinates[0]), y(CoordinatesVector::coordinates[1]), z(CoordinatesVector::coordinates[2]) + { + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); + } + + // Cast-copy constructor in order to use the operators of the mother class. + Vec3(const CoordinatesVector& original) + { + if (this != &original) { - std::copy(std::begin(origin.coordinates),std::end(origin.coordinates),std::begin(CoordinatesVector::coordinates)); + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); } } + template + typename std::enable_if::value,Vec3>::type + cross_product(const Vec3& operand) const + { + Vec3 normal_vector{0,0,0}; + normal_vector.x = y*operand.z - z*operand.y; + normal_vector.y = z*operand.x - x*operand.z; + normal_vector.z = x*operand.y - y*operand.x; + + return normal_vector; + } + Vec3& operator=(const Vec3& original) { if (this != &original) diff --git a/src/main.cpp b/src/main.cpp index 3195bc4..c36a79c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,11 @@ void manage_inputs() { glClearColor(0.5,0,0,1); } + else if (KeyStateManager::is_key_pressed(0x1B)) + { + glutDestroyWindow(glutGetWindow()); + exit(EXIT_SUCCESS); + } else { glClearColor(0,0,0,1);