This commit is contained in:
18
include/maths/aspect_ratio.hpp
Normal file
18
include/maths/aspect_ratio.hpp
Normal 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
37
include/maths/pow2.hpp
Normal 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
|
||||
52
include/maths/transform.hpp
Normal file
52
include/maths/transform.hpp
Normal 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
|
||||
Reference in New Issue
Block a user