paella/Code/include/Skeleton/VectorFunctions.hpp

49 lines
968 B
C++

#ifndef VECTOR_FUNCTIONS_HPP
#define VECTOR_FUNCTIONS_HPP
#include <cmath>
#include <SFML/System/Vector3.hpp>
using sf::Vector3;
template <class T>
Vector3<T> makeVector(Vector3<T> const& from, Vector3<T> const& to)
{
return to - from;
}
template <class T>
double dotProduct(Vector3<T> const& v1, Vector3<T> const& v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
template <class T>
double norm2(Vector3<T> const& vecteur)
{
return dotProduct(vecteur, vecteur);
}
template <class T>
double norm(Vector3<T> const& vecteur)
{
return sqrt(norm2(vecteur));
}
template <class T>
void normalize(Vector3<T>& vecteur)
{
vecteur /= norm(vecteur);
}
template <class T>
Vector3<T> crossProduct(Vector3<T> const& v1, Vector3<T> const& v2)
{
return Vector3<T>{v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z,
v1.x * v2.y - v1.y * v2.x
};
}
#endif // VECTOR_FUNCTIONS_HPP