Move through course, sprite and input
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
29
LightYearsEngine/include/framework/MathUtility.h
Normal file
29
LightYearsEngine/include/framework/MathUtility.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
namespace ly {
|
||||
sf::Vector2f RotationToVector(float rotation);
|
||||
float DegreesToRadians(float degrees);
|
||||
float RadiansToDegrees(float radians);
|
||||
|
||||
template<typename T>
|
||||
float GetVectorLength(const sf::Vector2<T>& vector) {
|
||||
return std::sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sf::Vector2<T>& ScaleVector(sf::Vector2<T>& vectorToScale, float scaleAmount) {
|
||||
vectorToScale.x *= scaleAmount;
|
||||
vectorToScale.y *= scaleAmount;
|
||||
return vectorToScale;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sf::Vector2<T>& Normalize(sf::Vector2<T> &vector) {
|
||||
float vectorLength = GetVectorLength<T>(vector);
|
||||
if (vectorLength == 0.f) return sf::Vector2<T>{};
|
||||
|
||||
ScaleVector(vector, 1.f/vectorLength);
|
||||
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user