10 #include <SFML/System/Vector2.hpp> 13 constexpr
float PI = 3.14159265359f;
21 return value*(180.f/PI);
30 return value*(PI/180.f);
40 inline auto norm(
const sf::Vector2<T>& vector) ->
float {
41 return std::sqrt(vector.x*vector.x + vector.y*vector.y);
51 inline auto normal(
const sf::Vector2<T>& vector) -> sf::Vector2f {
52 return { -vector.y, vector.x };
63 template <
typename T,
typename S>
64 inline auto distance(
const sf::Vector2<T>& point1,
const sf::Vector2<S>& point2) ->
float {
65 return std::sqrt((point2.x-point1.x)*(point2.x-point1.x) + (point2.y-point1.y)*(point2.y-point1.y));
69 inline auto dot_product(
const sf::Vector2<T>& v1,
const sf::Vector2<T>& v2) -> T {
70 return v1.x * v2.x + v1.y * v2.y;
74 inline auto cross_product(
const sf::Vector2<T>& v1,
const sf::Vector2<T>& v2) -> T {
75 return v1.x * v2.y - v1.y * v2.x;
85 inline auto angle(
const sf::Vector2<T>& vector) ->
float {
86 return std::atan2(vector.y, vector.x);
97 inline auto angle(
const sf::Vector2<T>& v1,
const sf::Vector2<T>& v2) ->
float {
98 auto r = std::atan2(v2.y, v2.x) - std::atan2(v1.y, v1.x);
99 return (std::abs(r) > PI ? r - 2*PI*r/std::abs(r) : r);
109 template <
typename T>
110 inline auto operator*(
const sf::Vector2<T>& v1,
const sf::Vector2<T>& v2) -> sf::Vector2<T> {
111 return {v1.x*v2.x, v1.y*v2.y};
auto angle(const sf::Vector2< T > &vector) -> float
Returns the clockwise positive angle of a vector.
auto to_radian(float value) -> float
Converts a degree angle to radian.
auto distance(const sf::Vector2< T > &point1, const sf::Vector2< S > &point2) -> float
Calculates the distance between two points.
auto to_degree(float value) -> float
Converts a radian angle to degree.
auto normal(const sf::Vector2< T > &vector) -> sf::Vector2f
Calculates the normal of a vector.
auto norm(const sf::Vector2< T > &vector) -> float
Calculates the norm of a vector (its length)
auto operator*(const sf::Vector2< T > &v1, const sf::Vector2< T > &v2) -> sf::Vector2< T >
Does element wise multiplication between two vectors.