initial commit
All checks were successful
Build (Arch Linux) / build (push) Successful in 3m10s

This commit is contained in:
2025-04-16 01:58:29 +01:00
commit a8d8b9b9ab
116 changed files with 106633 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
#pragma once
#include <concepts>
namespace kuiper
{
namespace maths
{
template<typename T, typename V>
requires(std::floating_point<V> || std::integral<V>) && std::floating_point<T>
constexpr inline T aspect_ratio(V width, V height) {
return static_cast<T>(width) / static_cast<T>(height);
}
} // namespace maths
} // namespace kuiper

37
include/maths/pow2.hpp Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include <cstdint>
namespace kuiper
{
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
inline std::uint64_t next_pow2(std::uint64_t value) {
value--;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
value |= value >> 32;
value++;
value += (value == 0); // Case for if value == 0 (returns 0 as the next power of 2, which 0 is not)
return value;
}
inline std::uint32_t next_pow2(std::uint32_t value) {
value--;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
value++;
value += (value == 0);
return value;
}
} // namespace kuiper

View File

@@ -0,0 +1,52 @@
#pragma once
#include "glm/gtc/quaternion.hpp"
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/quaternion_float.hpp>
#include <glm/ext/quaternion_trigonometric.hpp>
#include <glm/mat4x4.hpp>
#include <glm/trigonometric.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
namespace kuiper
{
namespace maths
{
struct transform_quat {
glm::vec3 position = {0.0f, 0.0f, 0.0f};
glm::quat rotation = {1.0f, 0.0f, 0.0f, 0.0f};
glm::vec3 scale = {1.0f, 1.0f, 1.0f};
glm::mat4 to_mat4() const noexcept {
static constexpr glm::mat4 identity_mat = glm::mat4(1.0f);
const glm::mat4 tm = glm::translate(identity_mat, position);
const glm::mat4 rm = glm::mat4_cast(rotation);
const glm::mat4 sm = glm::scale(identity_mat, scale);
return tm * rm * sm;
}
};
struct transform_euler {
glm::vec3 position = {0.0f, 0.0f, 0.0f};
glm::vec3 rotation = {0.0f, 0.0f, 0.0f};
glm::vec3 scale = {1.0f, 1.0f, 1.0f};
glm::mat4 to_mat4() const noexcept {
static constexpr glm::mat4 identity_mat = glm::mat4(1.0f);
const glm::mat4 tm = glm::translate(identity_mat, position);
const glm::mat4 rm = glm::mat4_cast(glm::quat(rotation));
const glm::mat4 sm = glm::scale(identity_mat, scale);
return tm * rm * sm;
}
};
} // namespace maths
} // namespace kuiper