First commit

This commit is contained in:
2025-11-17 03:42:30 -05:00
commit d0f9669b8b
41 changed files with 36106 additions and 0 deletions

13
src/util/map_.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <map>
namespace game::util::map
{
template <typename T0, typename T1> T1* find(std::map<T0, T1>& map, T0 key)
{
auto it = map.find(key);
if (it != map.end()) return &it->second;
return nullptr;
}
}

41
src/util/math_.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "math_.h"
#include "glm/ext/matrix_transform.hpp"
using namespace glm;
namespace game::util::math
{
mat4 quad_model_get(vec2 size, vec2 position, vec2 pivot, vec2 scale, float rotation)
{
vec2 scaleAbsolute = glm::abs(scale);
vec2 scaleSign = glm::sign(scale);
vec2 pivotScaled = pivot * scaleAbsolute;
vec2 sizeScaled = size * scaleAbsolute;
mat4 model(1.0f);
model = glm::translate(model, vec3(position - pivotScaled, 0.0f));
model = glm::translate(model, vec3(pivotScaled, 0.0f));
model = glm::scale(model, vec3(scaleSign, 1.0f));
model = glm::rotate(model, glm::radians(rotation), vec3(0, 0, 1));
model = glm::translate(model, vec3(-pivotScaled, 0.0f));
model = glm::scale(model, vec3(sizeScaled, 1.0f));
return model;
}
mat4 quad_model_parent_get(vec2 position, vec2 pivot, vec2 scale, float rotation)
{
vec2 scaleSign = glm::sign(scale);
vec2 scaleAbsolute = glm::abs(scale);
float handedness = (scaleSign.x * scaleSign.y) < 0.0f ? -1.0f : 1.0f;
mat4 local(1.0f);
local = glm::translate(local, vec3(pivot, 0.0f));
local = glm::scale(local, vec3(scaleSign, 1.0f));
local = glm::rotate(local, glm::radians(rotation) * handedness, vec3(0, 0, 1));
local = glm::translate(local, vec3(-pivot, 0.0f));
local = glm::scale(local, vec3(scaleAbsolute, 1.0f));
return glm::translate(mat4(1.0f), vec3(position, 0.0f)) * local;
}
}

19
src/util/math_.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "glm/ext/matrix_float4x4.hpp"
#include "glm/ext/vector_float2.hpp"
namespace game::util::math
{
glm::mat4 quad_model_get(glm::vec2, glm::vec2, glm::vec2, glm::vec2, float);
glm::mat4 quad_model_parent_get(glm::vec2 position, glm::vec2 pivot, glm::vec2, float);
template <typename T> constexpr T percent_to_unit(T value) { return value / 100.0f; }
template <typename T> constexpr T unit_to_percent(T value) { return value * 100.0f; }
constexpr std::array<float, 16> uv_vertices_get(glm::vec2 uvMin, glm::vec2 uvMax)
{
return {0.0f, 0.0f, uvMin.x, uvMin.y, 1.0f, 0.0f, uvMax.x, uvMin.y,
1.0f, 1.0f, uvMax.x, uvMax.y, 0.0f, 1.0f, uvMin.x, uvMax.y};
}
}

13
src/util/unordered_map_.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <unordered_map>
namespace game::util::unordered_map
{
template <typename T0, typename T1> T1* find(std::unordered_map<T0, T1>& map, T0 key)
{
auto it = map.find(key);
if (it != map.end()) return &it->second;
return nullptr;
}
}

17
src/util/vector_.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include <vector>
namespace game::util::vector
{
template <typename T> bool in_bounds(std::vector<T>& vector, int index)
{
return (index >= 0 && index < vector.size());
}
template <typename T> T* find(std::vector<T>& vector, int index)
{
if (!in_bounds(vector, index)) return nullptr;
return &vector[index];
}
}