Adds Vector utils, specifically normalization
This commit is contained in:
parent
1b5bc82c1c
commit
84c7e9e3b3
2 changed files with 20 additions and 1 deletions
|
@ -44,7 +44,7 @@ set(SOURCES
|
|||
src/game/input/direction.cpp
|
||||
src/game/player/player.cpp
|
||||
src/game/player/player.hpp
|
||||
src/game/input/game_inputs.hpp src/game/world/world_view.cpp src/game/world/world_view.h src/utilities/smart_list.cpp src/utilities/smart_list.h)
|
||||
src/game/input/game_inputs.hpp src/game/world/world_view.cpp src/game/world/world_view.h src/utilities/smart_list.cpp src/utilities/smart_list.h src/utilities/vector_utils.hpp)
|
||||
|
||||
set(PHYSICS_00_SOURCES
|
||||
src/prototypes/physics_00.cpp)
|
||||
|
|
19
src/utilities/vector_utils.hpp
Normal file
19
src/utilities/vector_utils.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef HOLESOME_VECTOR_UTILS_HPP
|
||||
#define HOLESOME_VECTOR_UTILS_HPP
|
||||
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <valarray>
|
||||
|
||||
template<typename T>
|
||||
sf::Vector2<T> normalize(sf::Vector2<T> v)
|
||||
{
|
||||
auto length = std::sqrt(v.x * v.x + v.y * v.y);
|
||||
if (length != 0)
|
||||
{
|
||||
v.x /= length;
|
||||
v.y /= length;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif //HOLESOME_VECTOR_UTILS_HPP
|
Loading…
Reference in a new issue