Compare commits

..

No commits in common. "f9dc00712da03bd31943bc3e09c0a8483a29a414" and "4da6167836bda01e0ce9231a0915bca5a0233efb" have entirely different histories.

3 changed files with 8 additions and 63 deletions

View file

@ -53,7 +53,7 @@ void Model3D::draw_model()
for (uint32_t i = 0;i<face_count;i++) for (uint32_t i = 0;i<face_count;i++)
{ {
Vec3i& face = faces[i]; Vec3i face = faces[i];
Vec3i* face_texture; Vec3i* face_texture;
if (is_textured) if (is_textured)
@ -68,7 +68,7 @@ void Model3D::draw_model()
if (is_textured) if (is_textured)
{ {
Vec2f& vertex_texture = texture_coordinates[face_texture->coordinates[j]]; Vec2f vertex_texture = texture_coordinates[face_texture->coordinates[j]];
glTexCoord2f(vertex_texture.x,vertex_texture.y); glTexCoord2f(vertex_texture.x,vertex_texture.y);
} }
glVertex3f(vertex.x,vertex.y,vertex.z); glVertex3f(vertex.x,vertex.y,vertex.z);

View file

@ -18,7 +18,7 @@ struct CoordinatesVector
/// Computes the euclidean norm of the vector. /// Computes the euclidean norm of the vector.
/// \return The magnitude. /// \return The magnitude.
double magnitude() const double magnitude()
{ {
// TODO : Save magnitude if the vector has not been modified. // TODO : Save magnitude if the vector has not been modified.
double sum_of_squares = 0; double sum_of_squares = 0;
@ -29,12 +29,10 @@ struct CoordinatesVector
return sqrt(sum_of_squares); 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. /// Normalizes the vector using its euclidean norm.
/// \return Nothing, the vector is normalized in-place. /// \return Nothing, the vector is normalized in-place.
template <typename U = T> typename std::enable_if<std::is_floating_point<T>::value,void>::type
typename std::enable_if<std::is_floating_point<U>::value,void>::type
normalize() normalize()
{ {
double norm = magnitude(); double norm = magnitude();
@ -44,19 +42,6 @@ struct CoordinatesVector
} }
} }
template <typename U = T>
typename std::enable_if<std::is_arithmetic<U>::value,T>::type
dot_product(const CoordinatesVector<T,N>& operand) const
{
T result = 0;
for (unsigned int i = 0;i<N;i++)
{
result += coordinates[i]*operand.coordinates[i];
}
return result;
}
// Use SFINAE to declare the function if and only if the type is arithmetic // Use SFINAE to declare the function if and only if the type is arithmetic
template <typename Scalar> template <typename Scalar>
typename std::enable_if<std::is_arithmetic<Scalar>::value,CoordinatesVector<T,N>>::type typename std::enable_if<std::is_arithmetic<Scalar>::value,CoordinatesVector<T,N>>::type
@ -119,17 +104,6 @@ struct Vec2 : public CoordinatesVector<T,2>
Vec2() = default; Vec2() = default;
Vec2(T x_axis, T y_axis)
{
x = x_axis;
y = y_axis;
}
Vec2(const Vec2<T>& original): x(CoordinatesVector<T,2>::coordinates[0]), y(CoordinatesVector<T,2>::coordinates[1])
{
std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector<T,2>::coordinates));
}
// Cast-copy constructor in order to use the operators of the mother class. // Cast-copy constructor in order to use the operators of the mother class.
Vec2(const CoordinatesVector<T,2>& origin) Vec2(const CoordinatesVector<T,2>& origin)
{ {
@ -159,39 +133,15 @@ struct Vec3 : CoordinatesVector<T,3>
Vec3() = default; Vec3() = default;
Vec3(T x_axis, T y_axis, T z_axis)
{
x = x_axis;
y = y_axis;
z = z_axis;
}
Vec3(const Vec3<T>& original): x(CoordinatesVector<T,3>::coordinates[0]), y(CoordinatesVector<T,3>::coordinates[1]), z(CoordinatesVector<T,3>::coordinates[2])
{
std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector<T,3>::coordinates));
}
// Cast-copy constructor in order to use the operators of the mother class. // Cast-copy constructor in order to use the operators of the mother class.
Vec3(const CoordinatesVector<T,3>& original) Vec3(const CoordinatesVector<T,3>& origin)
{ {
if (this != &original) if (this != &origin)
{ {
std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector<T,3>::coordinates)); std::copy(std::begin(origin.coordinates),std::end(origin.coordinates),std::begin(CoordinatesVector<T,2>::coordinates));
} }
} }
template <typename U = T>
typename std::enable_if<std::is_arithmetic<U>::value,Vec3<T>>::type
cross_product(const Vec3<T>& operand) const
{
Vec3<T> 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<T>& original) Vec3& operator=(const Vec3<T>& original)
{ {
if (this != &original) if (this != &original)

View file

@ -21,11 +21,6 @@ void manage_inputs()
{ {
glClearColor(0.5,0,0,1); glClearColor(0.5,0,0,1);
} }
else if (KeyStateManager::is_key_pressed(0x1B))
{
glutDestroyWindow(glutGetWindow());
exit(EXIT_SUCCESS);
}
else else
{ {
glClearColor(0,0,0,1); glClearColor(0,0,0,1);