Added 2D Vector structure
This commit is contained in:
parent
44b415cbaa
commit
471a6ce36d
|
@ -10,4 +10,6 @@ target_include_directories(${PNAME} PRIVATE
|
|||
|
||||
target_link_libraries(${PNAME} PRIVATE
|
||||
${CMAKE_BINARY_DIR}/3rdparty/SDL/SDL2d.lib
|
||||
)
|
||||
)
|
||||
|
||||
add_subdirectory(structures)
|
|
@ -1,3 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include "SDL.h"
|
||||
#include "structures/Vector2.hpp"
|
3
SDLU/structures/CMakeLists.txt
Normal file
3
SDLU/structures/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
target_sources(${PNAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Vector2.hpp
|
||||
)
|
46
SDLU/structures/Vector2.hpp
Normal file
46
SDLU/structures/Vector2.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @file Vector2.hpp
|
||||
* @brief Provides a structure for simple vector calculations
|
||||
* @author Lauchmelder23
|
||||
* @date 16.05.2020
|
||||
*/
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
template<
|
||||
typename T,
|
||||
typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type
|
||||
> struct Vector2
|
||||
{
|
||||
T x; ///< x component
|
||||
T y; ///< y component
|
||||
|
||||
/// Initializes a zero vector
|
||||
Vector2() :
|
||||
x(0), y(0)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
/// Initializes a vector with default values
|
||||
Vector2(T x, T y) :
|
||||
x(x), y(y)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
/// Copies the components of a vector
|
||||
Vector2(const Vector2<T>& other) :
|
||||
x(other.x), y(other.y)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vector2<unsigned int> Vector2u, Vec2u;
|
||||
typedef Vector2<int> Vector2i, Vec2i;
|
||||
typedef Vector2<float> Vector2f, Vec2f;
|
||||
typedef Vector2<double> Vector2d, Vec2d;
|
||||
}
|
|
@ -1,6 +1,11 @@
|
|||
#include "header.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
sdlu::Vector2f vec(.4f, -2.3f);
|
||||
std::cout << "Vector2f: " << vec.x << ", " << vec.y << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue