Compare commits

...

2 commits

Author SHA1 Message Date
e65b6b3f83
chore: remove glm dependency
Some checks failed
continuous-integration/drone/push Build is failing
2025-07-17 10:45:52 +03:30
f9ce347ca0
feat: initial math module implementation
refactor: replace glm with built-in math library
2025-07-17 10:44:00 +03:30
47 changed files with 564 additions and 194 deletions

View file

@ -25,7 +25,6 @@ class LightRecipe(ConanFile):
def requirements(self): def requirements(self):
self.requires("entt/3.15.0") self.requires("entt/3.15.0")
self.requires("glfw/3.4") self.requires("glfw/3.4")
self.requires("glm/1.0.1")
self.requires("stb/cci.20240531") self.requires("stb/cci.20240531")
self.requires("yaml-cpp/0.8.0") self.requires("yaml-cpp/0.8.0")
self.requires("lz4/1.10.0") self.requires("lz4/1.10.0")

View file

@ -40,7 +40,6 @@ endif()
add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD) add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
include_directories(${DEPENDENCIES_DIR}GLFW/include) include_directories(${DEPENDENCIES_DIR}GLFW/include)
include_directories(${DEPENDENCIES_DIR}glm/)
add_library(imgui STATIC ${IMGUI_FILES} ${IMGUI_BACKEND_FILES}) add_library(imgui STATIC ${IMGUI_FILES} ${IMGUI_BACKEND_FILES})
@ -49,6 +48,5 @@ target_link_libraries(
imgui imgui
PUBLIC glad PUBLIC glad
PUBLIC opengl::opengl PUBLIC opengl::opengl
PUBLIC glm::glm
PUBLIC glfw PUBLIC glfw
) )

View file

@ -3,6 +3,7 @@ add_subdirectory(./base)
add_subdirectory(./time) add_subdirectory(./time)
add_subdirectory(./logger) add_subdirectory(./logger)
add_subdirectory(./debug) add_subdirectory(./debug)
add_subdirectory(./math)
add_subdirectory(./asset_baker) add_subdirectory(./asset_baker)
add_subdirectory(./asset_parser) add_subdirectory(./asset_parser)

View file

@ -1,3 +1,3 @@
add_library_module(camera camera.cpp scene.cpp) add_library_module(camera camera.cpp scene.cpp)
target_link_libraries(camera PUBLIC glm::glm) target_link_libraries(camera PUBLIC math)

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/mat4.hpp>
#include <math/vec4.hpp>
namespace lt { namespace lt {
@ -9,26 +10,26 @@ class Camera
public: public:
Camera() = default; Camera() = default;
[[nodiscard]] auto get_projection() const -> const glm::mat4 & [[nodiscard]] auto get_projection() const -> const math::mat4 &
{ {
return m_projection; return m_projection;
} }
[[nodiscard]] auto get_background_color() const -> const glm::vec4 & [[nodiscard]] auto get_background_color() const -> const math::vec4 &
{ {
return m_background_color; return m_background_color;
} }
void set_background_color(const glm::vec4 &color) void set_background_color(const math::vec4 &color)
{ {
m_background_color = color; m_background_color = color;
} }
protected: protected:
glm::mat4 m_projection {}; math::mat4 m_projection;
private: private:
glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); math::vec4 m_background_color = math::vec4(1.0f, 0.0f, 0.0f, 1.0f);
}; };
} // namespace lt } // namespace lt

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <camera/scene.hpp> #include <camera/scene.hpp>
#include <glm/glm.hpp>
namespace lt { namespace lt {

View file

@ -1,11 +1,12 @@
#include <camera/scene.hpp> #include <camera/scene.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <math/algebra.hpp>
#include <math/trig.hpp>
namespace lt { namespace lt {
SceneCamera::SceneCamera() SceneCamera::SceneCamera()
: m_orthographic_specification { .size = 1000.0f, .near_plane = -1.0f, .far_plane = 10000.0f } : m_orthographic_specification { .size = 1000.0f, .near_plane = -1.0f, .far_plane = 10000.0f }
, m_perspective_specification { .vertical_fov = glm::radians(45.0f), , m_perspective_specification { .vertical_fov = math::radians(45.0f),
.near_plane = 0.01f, .near_plane = 0.01f,
.far_plane = 10000.0f } .far_plane = 10000.0f }
, m_aspect_ratio(16.0f / 9.0f) , m_aspect_ratio(16.0f / 9.0f)
@ -64,26 +65,19 @@ void SceneCamera::set_perspective_near_plane(float near_plane)
void SceneCamera::calculate_projection() void SceneCamera::calculate_projection()
{ {
// TODO(Light): implement ortho perspective
if (m_projection_type == ProjectionType::Orthographic) if (m_projection_type == ProjectionType::Orthographic)
{ {
m_projection = glm::ortho( // throw std::runtime_error { "ortho perspective not supported yet" };
-m_orthographic_specification.size * 0.5f * m_aspect_ratio,
m_orthographic_specification.size * 0.5f * m_aspect_ratio,
-m_orthographic_specification.size * 0.5f,
m_orthographic_specification.size * 0.5f,
m_orthographic_specification.far_plane,
m_orthographic_specification.near_plane
);
}
else // perspective
{
m_projection = glm::perspective(
m_perspective_specification.vertical_fov,
m_aspect_ratio,
m_perspective_specification.near_plane,
m_perspective_specification.far_plane
);
} }
// defaults to perspective for now...
m_projection = math::perspective(
m_perspective_specification.vertical_fov,
m_aspect_ratio,
m_perspective_specification.near_plane,
m_perspective_specification.far_plane
);
} }
} // namespace lt } // namespace lt

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/vec4.hpp>
#include <utility> #include <utility>
namespace lt { namespace lt {
@ -15,7 +15,7 @@ struct SpriteRendererComponent
SpriteRendererComponent( SpriteRendererComponent(
Ref<Texture> _texture, Ref<Texture> _texture,
const glm::vec4 &_tint = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f) const math::vec4 &_tint = math::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }
) )
: texture(std::move(std::move(_texture))) : texture(std::move(std::move(_texture)))
, tint(_tint) , tint(_tint)
@ -29,7 +29,7 @@ struct SpriteRendererComponent
Ref<Texture> texture; Ref<Texture> texture;
glm::vec4 tint {}; math::vec4 tint {};
}; };
} // namespace lt } // namespace lt

View file

@ -1,10 +1,7 @@
#pragma once #pragma once
#define GLM_ENABLE_EXPERIMENTAL #include <math/mat4.hpp>
#include <math/vec3.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
namespace lt { namespace lt {
@ -13,9 +10,9 @@ struct TransformComponent
TransformComponent(const TransformComponent &) = default; TransformComponent(const TransformComponent &) = default;
TransformComponent( TransformComponent(
const glm::vec3 &_translation = glm::vec3(0.0f, 0.0f, 0.0f), const math::vec3 &_translation = math::vec3(0.0f, 0.0f, 0.0f),
const glm::vec3 &_scale = glm::vec3(1.0f, 1.0f, 1.0f), const math::vec3 &_scale = math::vec3(1.0f, 1.0f, 1.0f),
const glm::vec3 &_rotation = glm::vec3(0.0f, 0.0f, 0.0f) const math::vec3 &_rotation = math::vec3(0.0f, 0.0f, 0.0f)
) )
: translation(_translation) : translation(_translation)
@ -24,22 +21,23 @@ struct TransformComponent
{ {
} }
[[nodiscard]] auto get_transform() const -> glm::mat4 [[nodiscard]] auto get_transform() const -> math::mat4
{ {
return glm::translate(translation) * glm::rotate(rotation.z, glm::vec3(0.0f, 0.0f, 1.0f)) return math::translate(translation)
* glm::scale(scale); * math::rotate(rotation.z, math::vec3 { 0.0f, 0.0f, 1.0f }) //
* math::scale(scale);
} }
operator const glm::mat4() const operator const math::mat4() const
{ {
return get_transform(); return get_transform();
} }
glm::vec3 translation; math::vec3 translation;
glm::vec3 scale; math::vec3 scale;
glm::vec3 rotation; math::vec3 rotation;
}; };
} // namespace lt } // namespace lt

View file

@ -3,7 +3,6 @@
#include <ecs/components/transform.hpp> #include <ecs/components/transform.hpp>
#include <ecs/uuid.hpp> #include <ecs/uuid.hpp>
#include <entt/entt.hpp> #include <entt/entt.hpp>
#include <glm/glm.hpp>
namespace lt { namespace lt {

View file

@ -2,7 +2,6 @@
#include <ecs/components.hpp> #include <ecs/components.hpp>
#include <ecs/entity.hpp> #include <ecs/entity.hpp>
#include <ecs/scene.hpp> #include <ecs/scene.hpp>
#include <glm/glm.hpp>
#include <renderer/renderer.hpp> #include <renderer/renderer.hpp>
namespace lt { namespace lt {

View file

@ -2,14 +2,16 @@
#include <camera/component.hpp> #include <camera/component.hpp>
#include <ecs/components.hpp> #include <ecs/components.hpp>
#include <ecs/serializer.hpp> #include <ecs/serializer.hpp>
#include <math/vec3.hpp>
#include <math/vec4.hpp>
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
namespace YAML { namespace YAML {
template<> template<>
struct convert<glm::vec3> struct convert<lt::math::vec3>
{ {
static auto encode(const glm::vec3 &rhs) -> Node static auto encode(const lt::math::vec3 &rhs) -> Node
{ {
auto node = Node {}; auto node = Node {};
node.push_back(rhs.x); node.push_back(rhs.x);
@ -18,7 +20,7 @@ struct convert<glm::vec3>
return node; return node;
} }
static auto decode(const Node &node, glm::vec3 &rhs) -> bool static auto decode(const Node &node, lt::math::vec3 &rhs) -> bool
{ {
if (!node.IsSequence() || node.size() != 3) if (!node.IsSequence() || node.size() != 3)
{ {
@ -33,9 +35,9 @@ struct convert<glm::vec3>
}; };
template<> template<>
struct convert<glm::vec4> struct convert<lt::math::vec4>
{ {
static auto encode(const glm::vec4 &rhs) -> Node static auto encode(const lt::math::vec4 &rhs) -> Node
{ {
auto node = Node {}; auto node = Node {};
node.push_back(rhs.x); node.push_back(rhs.x);
@ -45,7 +47,7 @@ struct convert<glm::vec4>
return node; return node;
} }
static auto decode(const Node &node, glm::vec4 &rhs) -> bool static auto decode(const Node &node, lt::math::vec4 &rhs) -> bool
{ {
if (!node.IsSequence() || node.size() != 4) if (!node.IsSequence() || node.size() != 4)
{ {
@ -63,14 +65,14 @@ struct convert<glm::vec4>
namespace lt { namespace lt {
auto operator<<(YAML::Emitter &out, const glm::vec3 &v) -> YAML::Emitter & auto operator<<(YAML::Emitter &out, const math::vec3 &v) -> YAML::Emitter &
{ {
out << YAML::Flow; out << YAML::Flow;
out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq; out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq;
return out; return out;
} }
auto operator<<(YAML::Emitter &out, const glm::vec4 &v) -> YAML::Emitter & auto operator<<(YAML::Emitter &out, const math::vec4 &v) -> YAML::Emitter &
{ {
out << YAML::Flow; out << YAML::Flow;
out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq; out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq;
@ -156,9 +158,10 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool
.get_component<TransformComponent>(); .get_component<TransformComponent>();
entityTransforomComponent.translation = transformComponent["Translation"] entityTransforomComponent.translation = transformComponent["Translation"]
.as<glm::vec3>(); .as<math::vec3>();
entityTransforomComponent.rotation = transformComponent["Rotation"].as<glm::vec3>(); entityTransforomComponent.rotation = transformComponent["Rotation"]
entityTransforomComponent.scale = transformComponent["Scale"].as<glm::vec3>(); .as<math::vec3>();
entityTransforomComponent.scale = transformComponent["Scale"].as<math::vec3>();
} }
/* #TEMPORARY SOLUTION# */ /* #TEMPORARY SOLUTION# */
@ -168,7 +171,7 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool
auto &entitySpriteRendererComponent = deserializedEntity auto &entitySpriteRendererComponent = deserializedEntity
.add_component<SpriteRendererComponent>(); .add_component<SpriteRendererComponent>();
entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"] entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"]
.as<glm::vec4>(); .as<math::vec4>();
auto texturePath = spriteRendererComponent["Texture"].as<std::string>(); auto texturePath = spriteRendererComponent["Texture"].as<std::string>();
@ -213,7 +216,7 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool
); );
entityCameraComponent.camera.set_background_color( entityCameraComponent.camera.set_background_color(
cameraSpecifications["BackgroundColor"].as<glm::vec4>() cameraSpecifications["BackgroundColor"].as<math::vec4>()
); );
entityCameraComponent.isPrimary = cameraComponent["IsPrimary"].as<bool>(); entityCameraComponent.isPrimary = cameraComponent["IsPrimary"].as<bool>();

View file

@ -1,2 +1,2 @@
add_library_module(input input.cpp) add_library_module(input input.cpp)
target_link_libraries(input PUBLIC glm::glm imgui logger) target_link_libraries(input PUBLIC math imgui logger)

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp>
#include <input/events/event.hpp> #include <input/events/event.hpp>
#include <math/vec2.hpp>
#include <sstream> #include <sstream>
namespace lt { namespace lt {
@ -13,7 +13,7 @@ public:
{ {
} }
[[nodiscard]] auto get_position() const -> const glm::vec2 & [[nodiscard]] auto get_position() const -> const math::vec2 &
{ {
return m_position; return m_position;
} }
@ -46,7 +46,7 @@ public:
} }
private: private:
const glm::vec2 m_position; const math::vec2 m_position;
}; };
class WheelScrolledEvent: public Event class WheelScrolledEvent: public Event

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp>
#include <input/events/event.hpp> #include <input/events/event.hpp>
#include <math/vec2.hpp>
#include <sstream> #include <sstream>
namespace lt { namespace lt {
@ -32,7 +32,7 @@ public:
{ {
} }
[[nodiscard]] auto get_position() const -> const glm::ivec2 & [[nodiscard]] auto get_position() const -> const math::ivec2 &
{ {
return m_position; return m_position;
} }
@ -56,7 +56,7 @@ public:
} }
private: private:
const glm::ivec2 m_position; const math::ivec2 m_position;
}; };
class WindowResizedEvent: public Event class WindowResizedEvent: public Event
@ -66,7 +66,7 @@ public:
{ {
} }
[[nodiscard]] auto get_size() const -> const glm::uvec2 & [[nodiscard]] auto get_size() const -> const math::uvec2 &
{ {
return m_size; return m_size;
} }
@ -89,7 +89,7 @@ public:
} }
private: private:
const glm::uvec2 m_size; const math::uvec2 m_size;
}; };
class WindowLostFocusEvent: public Event class WindowLostFocusEvent: public Event

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <glm/glm.hpp> #include <math/vec2.hpp>
namespace lt { namespace lt {
@ -36,7 +36,7 @@ public:
return instance().m_mouse_buttons[code]; return instance().m_mouse_buttons[code];
} }
static auto get_mouse_position(int /*code*/) -> const glm::vec2 & static auto get_mouse_position(int /*code*/) -> const math::vec2 &
{ {
return instance().m_mouse_position; return instance().m_mouse_position;
} }
@ -66,9 +66,9 @@ private:
std::array<bool, 8> m_mouse_buttons {}; std::array<bool, 8> m_mouse_buttons {};
glm::vec2 m_mouse_position; math::vec2 m_mouse_position;
glm::vec2 m_mouse_delta; math::vec2 m_mouse_delta;
float m_mouse_wheel_delta {}; float m_mouse_wheel_delta {};

View file

@ -36,8 +36,8 @@ void Input::restart_input_state()
m_keyboad_keys.fill(false); m_keyboad_keys.fill(false);
m_mouse_buttons.fill(false); m_mouse_buttons.fill(false);
m_mouse_position = glm::vec2(0.0f); m_mouse_position = math::vec2(0.0f);
m_mouse_delta = glm::vec2(0.0f); m_mouse_delta = math::vec2(0.0f);
m_mouse_wheel_delta = 0.0f; m_mouse_wheel_delta = 0.0f;
} }

View file

@ -0,0 +1 @@
add_library_module(math)

View file

@ -0,0 +1,57 @@
#pragma once
#include <math/mat4.hpp>
namespace lt::math {
/**
* let...
* a = h / w ==> for aspect ratio adjustment
* f = 1 / tan(fov / 2) ==> for field of view
*
* zdiff = zfar-znear
* A = (zfar / zdiff) - (zfar / zdiff * znear) ==> for normalization
*
* given a 3d position vector xyz, we need to do the following operations to achieve
* perspective projection:
* x afx
* y --> fy
* z Az - Aznear
*
* such calculation can be embdedded in a matrix as:
* [x] [y] [z] [w]
*
* | af | 0 | 0 | 0 |
* ----------------------------------
* | 0 | f | 0 | 0 |
* ----------------------------------
* | 0 | 0 | A | A*znear|
* ----------------------------------
* | 0 | 0 | 1 | 0 |
*
* the 1 at [z][3] is to save the Z axis into the resulting W for perspective division.
*
* thanks to pikuma: https://www.youtube.com/watch?v=EqNcqBdrNyI
*/
template<typename T>
constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far)
{
const T half_fov_tan = std::tan(field_of_view / static_cast<T>(2));
auto result = mat4_impl<T> { T { 0 } };
result[0][0] = T { 1 } / (aspect_ratio * half_fov_tan);
result[1][1] = T { 1 } / (half_fov_tan);
result[2][2] = -(z_far + z_near) / (z_far - z_near);
result[2][3] = -T { 1 };
result[3][2] = -(T { 2 } * z_far * z_near) / (z_far - z_near);
return result;
}
} // namespace lt::math

View file

@ -0,0 +1,109 @@
#pragma once
#include <math/vec3.hpp>
#include <math/vec4.hpp>
namespace lt::math {
template<typename T = float>
struct mat4_impl
{
using Column_T = vec4_impl<T>;
explicit mat4_impl(T scalar = 0)
: values(
{
Column_T { scalar },
Column_T { scalar },
Column_T { scalar },
Column_T { scalar },
}
)
{
}
// clang-format off
mat4_impl(
const T& x0, const T& y0, const T& z0, const T& w0,
const T& x1, const T& y1, const T& z1, const T& w1,
const T& x2, const T& y2, const T& z2, const T& w2,
const T& x3, const T& y3, const T& z3, const T& w3
)
// clang-format on
: values({ { x0, x1, x2, x3 }, { y0, y1, y2, y3 }, { z0, z1, z2, z3 }, { w0, w1, w2, w3 } })
{
}
mat4_impl(
const Column_T &column_x,
const Column_T &column_y,
const Column_T &column_z,
const Column_T &column_w
)
: values({ column_x, column_y, column_z, column_w })
{
}
[[nodiscard]] constexpr auto identity() -> mat4_impl<T>
{
return mat4_impl<T> {
{ 1 }, {}, {}, {}, //
{}, { 1 }, {}, {}, //
{}, {}, { 1 }, {}, //
{}, {}, {}, { 1 }, //
};
}
[[nodiscard]] auto operator[](size_t idx) -> Column_T &
{
return values[idx];
}
[[nodiscard]] auto operator[](size_t idx) const -> const Column_T &
{
return values[idx];
}
[[nodiscard]] auto operator*(const mat4_impl<T> &other) const -> mat4_impl<T>
{
return mat4_impl<T> {};
}
[[nodiscard]] auto operator*(const vec4_impl<T> &other) const -> vec4_impl<T>
{
return vec4_impl<T> {};
}
std::array<Column_T, 4> values; // NOLINT
};
template<typename T>
[[nodiscard]] inline auto translate(const vec3_impl<T> &value) -> mat4_impl<T>
{
return mat4_impl<T> {};
}
template<typename T>
[[nodiscard]] inline auto rotate(float value, const vec3_impl<T> &xyz) -> mat4_impl<T>
{
return mat4_impl<T> {};
}
template<typename T>
[[nodiscard]] inline auto scale(const vec3_impl<T> &value) -> mat4_impl<T>
{
return mat4_impl<T> {};
}
template<typename T>
[[nodiscard]] inline auto inverse(const mat4_impl<T> &value) -> mat4_impl<T>
{
return mat4_impl<T> {};
}
using mat4 = mat4_impl<float>;
using imat4 = mat4_impl<int32_t>;
using umat4 = mat4_impl<uint32_t>;
} // namespace lt::math

View file

@ -0,0 +1,26 @@
#pragma once
namespace lt::math {
[[nodiscard]] constexpr auto radians(float degrees) -> float
{
return degrees * 0.01745329251994329576923690768489f;
}
[[nodiscard]] constexpr auto radians(double degrees) -> double
{
return degrees * 0.01745329251994329576923690768489;
}
[[nodiscard]] constexpr auto degrees(float radians) -> float
{
return radians * 57.295779513082320876798154814105f;
}
[[nodiscard]] constexpr auto degrees(double radians) -> double
{
return radians * 57.295779513082320876798154814105;
}
} // namespace lt::math

View file

@ -0,0 +1,56 @@
#pragma once
namespace lt::math {
template<typename T = float>
struct vec2_impl
{
vec2_impl(): x(), y()
{
}
explicit vec2_impl(T scalar): x(scalar), y(scalar)
{
}
vec2_impl(T x, T y): x(x), y(y)
{
}
[[nodiscard]] auto operator*(const vec2_impl<T> &other) const -> vec2_impl
{
return {
x * other.x,
y * other.y,
};
}
[[nodiscard]] auto operator-(const vec2_impl<T> &other) const -> vec2_impl
{
return {
x - other.x,
y - other.y,
};
}
[[nodiscard]] auto operator*(float scalar) const -> vec2_impl
{
return {
x * scalar,
y * scalar,
};
}
T x; // NOLINT
T y; // NOLINT
};
using vec2 = vec2_impl<float>;
using ivec2 = vec2_impl<int32_t>;
using uvec2 = vec2_impl<uint32_t>;
} // namespace lt::math

View file

@ -0,0 +1,53 @@
#pragma once
#include <math/vec2.hpp>
namespace lt::math {
template<typename T = float>
struct vec3_impl
{
vec3_impl(): x(), y(), z()
{
}
explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar)
{
}
vec3_impl(T x, T y, T z): x(x), y(y), z(z)
{
}
[[nodiscard]] auto operator-(const vec3_impl<T> &other) const -> vec3_impl
{
return {
x - other.x,
y - other.y,
z - other.z,
};
}
[[nodiscard]] auto operator*(const vec3_impl<T> &other) const -> vec3_impl
{
return {
x * other.x,
y * other.y,
z * other.z,
};
}
T x; // NOLINT
T y; // NOLINT
T z; // NOLINT
};
using vec3 = vec3_impl<float>;
using ivec3 = vec3_impl<int32_t>;
using uvec3 = vec3_impl<uint32_t>;
} // namespace lt::math

View file

@ -0,0 +1,78 @@
#pragma once
#include <array>
namespace lt::math {
template<typename T = float>
struct vec4_impl
{
vec4_impl(): x(), y(), z(), w()
{
}
explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar)
{
}
vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w)
{
}
[[nodiscard]] auto operator-(const vec4_impl<T> &other) const -> vec4_impl
{
return {
x - other.x,
y - other.y,
z - other.z,
w - other.w,
};
}
[[nodiscard]] auto operator[](size_t idx) -> T &
{
return values[idx];
}
[[nodiscard]] auto operator[](size_t idx) const -> const T &
{
return values[idx];
}
// NOLINTNEXTLINE
union
{
struct
{
T x;
T y;
T z;
T w;
};
struct
{
T r;
T g;
T b;
T a;
};
struct
{
std::array<T, 4> values;
};
};
};
using vec4 = vec4_impl<float>;
using ivec4 = vec4_impl<int32_t>;
using uvec4 = vec4_impl<uint32_t>;
} // namespace lt::math

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <app/layer.hpp> #include <app/layer.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <imgui.h> #include <imgui.h>
#include <math/vec2.hpp>
#include <mirror/panel/asset_browser.hpp> #include <mirror/panel/asset_browser.hpp>
#include <mirror/panel/properties.hpp> #include <mirror/panel/properties.hpp>
#include <mirror/panel/scene_hierarchy.hpp> #include <mirror/panel/scene_hierarchy.hpp>
@ -36,7 +36,7 @@ public:
private: private:
std::string m_scene_dir; std::string m_scene_dir;
glm::vec2 m_direction; math::vec2 m_direction;
float m_speed = 1000.0f; float m_speed = 1000.0f;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <ecs/entity.hpp> #include <ecs/entity.hpp>
#include <math/vec3.hpp>
#include <mirror/panel/panel.hpp> #include <mirror/panel/panel.hpp>
namespace lt { namespace lt {
@ -17,7 +18,7 @@ public:
private: private:
void draw_vec3_control( void draw_vec3_control(
const std::string &label, const std::string &label,
glm::vec3 &values, math::vec3 &values,
float reset_value = 0.0f, float reset_value = 0.0f,
float column_width = 100.0f float column_width = 100.0f
); );

View file

@ -6,6 +6,7 @@
#include <ecs/serializer.hpp> #include <ecs/serializer.hpp>
#include <input/input.hpp> #include <input/input.hpp>
#include <input/key_codes.hpp> #include <input/key_codes.hpp>
#include <math/vec4.hpp>
#include <mirror/editor_layer.hpp> #include <mirror/editor_layer.hpp>
#include <renderer/framebuffer.hpp> #include <renderer/framebuffer.hpp>
#include <renderer/graphics_context.hpp> #include <renderer/graphics_context.hpp>
@ -44,7 +45,7 @@ EditorLayer::EditorLayer(const std::string &name)
auto entity = Entity { m_scene->create_entity("Awesomeface", {}) }; auto entity = Entity { m_scene->create_entity("Awesomeface", {}) };
entity.add_component<SpriteRendererComponent>( entity.add_component<SpriteRendererComponent>(
AssetManager::get_texture("Awesomeface"), AssetManager::get_texture("Awesomeface"),
glm::vec4 { 0.0f, 1.0f, 1.0f, 1.0f } math::vec4 { 0.0f, 1.0f, 1.0f, 1.0f }
); );
} }
else else
@ -96,7 +97,8 @@ void EditorLayer::on_update(float delta_time)
} }
auto &translation = m_camera_entity.get_component<TransformComponent>().translation; auto &translation = m_camera_entity.get_component<TransformComponent>().translation;
translation += glm::vec3 { m_direction * m_speed * delta_time, 0.0f }; auto velocity = m_direction * m_speed * delta_time;
translation = translation * math::vec3 { velocity.x, velocity.y, 0.0f };
if (Input::get_keyboard_key(Key::Escape)) if (Input::get_keyboard_key(Key::Escape))
{ {
@ -122,7 +124,12 @@ void EditorLayer::on_user_interface_update()
if (m_available_content_region_prev.x != available_region.x if (m_available_content_region_prev.x != available_region.x
|| m_available_content_region_prev.y != available_region.y) || m_available_content_region_prev.y != available_region.y)
{ {
m_framebuffer->resize({ available_region.x, available_region.y }); m_framebuffer->resize(
math::uvec2 {
static_cast<uint32_t>(available_region.x),
static_cast<uint32_t>(available_region.y),
}
);
auto &camera = m_camera_entity.get_component<CameraComponent>().camera; auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
camera.set_viewport_size( camera.set_viewport_size(
static_cast<uint32_t>(available_region.x), static_cast<uint32_t>(available_region.x),

View file

@ -1,6 +1,7 @@
#include <app/application.hpp> #include <app/application.hpp>
#include <app/entrypoint.hpp> #include <app/entrypoint.hpp>
#include <app/layer_stack.hpp> #include <app/layer_stack.hpp>
#include <math/vec2.hpp>
#include <mirror/editor_layer.hpp> #include <mirror/editor_layer.hpp>
#include <window/window.hpp> #include <window/window.hpp>
@ -14,7 +15,7 @@ public:
get_window().set_properties( get_window().set_properties(
Window::Properties { Window::Properties {
.title = "Mirror", .title = "Mirror",
.size = glm::uvec2(1280u, 720u), .size = math::uvec2(1280u, 720u),
.vsync = true, .vsync = true,
} }
); );

View file

@ -1,10 +1,9 @@
#include <asset_manager/asset_manager.hpp> #include <asset_manager/asset_manager.hpp>
#include <camera/component.hpp> #include <camera/component.hpp>
#include <ecs/components.hpp> #include <ecs/components.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h> #include <imgui_internal.h>
#include <math/trig.hpp>
#include <mirror/panel/properties.hpp> #include <mirror/panel/properties.hpp>
namespace lt { namespace lt {
@ -21,7 +20,7 @@ void PropertiesPanel::on_user_interface_update()
auto buffer = std::array<char, 256> {}; auto buffer = std::array<char, 256> {};
memset(buffer.data(), 0, buffer.size()); memset(buffer.data(), 0, buffer.size());
std::strncpy(buffer.data(), tagComponent.tag.c_str(), buffer.size()); strncpy(buffer.data(), tagComponent.tag.c_str(), buffer.size());
if (ImGui::InputText("##Tag", buffer.data(), buffer.size())) if (ImGui::InputText("##Tag", buffer.data(), buffer.size()))
{ {
@ -147,13 +146,13 @@ void PropertiesPanel::on_user_interface_update()
auto near_plane = float {}; auto near_plane = float {};
auto far_plane = float {}; auto far_plane = float {};
vertical_fov = glm::degrees(camera.get_perspective_vertical_fov()); vertical_fov = math::degrees(camera.get_perspective_vertical_fov());
near_plane = camera.get_perspective_near_plane(); near_plane = camera.get_perspective_near_plane();
far_plane = camera.get_perspective_far_plane(); far_plane = camera.get_perspective_far_plane();
if (ImGui::DragFloat("Vertical FOV", &vertical_fov)) if (ImGui::DragFloat("Vertical FOV", &vertical_fov))
{ {
camera.set_perspective_vertical_fov(glm::radians(vertical_fov)); camera.set_perspective_vertical_fov(math::radians(vertical_fov));
} }
if (ImGui::DragFloat("Near Plane", &near_plane)) if (ImGui::DragFloat("Near Plane", &near_plane))
@ -182,7 +181,7 @@ void PropertiesPanel::set_entity_context(const Entity &entity)
void PropertiesPanel::draw_vec3_control( void PropertiesPanel::draw_vec3_control(
const std::string &label, const std::string &label,
glm::vec3 &values, math::vec3 &values,
float reset_value, float reset_value,
float column_width float column_width
) )

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <math/vec2.hpp>
#include <glm/glm.hpp> #include <math/vec4.hpp>
namespace lt { namespace lt {
@ -25,11 +25,11 @@ public:
const Ref<SharedContext> &sharedContext const Ref<SharedContext> &sharedContext
) -> Ref<Framebuffer>; ) -> Ref<Framebuffer>;
virtual void bind_as_target(const glm::vec4 &clearColor) = 0; virtual void bind_as_target(const math::vec4 &clearColor) = 0;
virtual void bind_as_resource() = 0; virtual void bind_as_resource() = 0;
virtual void resize(const glm::uvec2 &size) = 0; virtual void resize(const math::uvec2 &size) = 0;
virtual auto get_color_attachment() -> void * = 0; virtual auto get_color_attachment() -> void * = 0;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <math/vec2.hpp>
#include <math/vec4.hpp>
#include <renderer/framebuffer.hpp> #include <renderer/framebuffer.hpp>
namespace lt { namespace lt {
@ -12,11 +13,11 @@ public:
~glFramebuffer() override; ~glFramebuffer() override;
void bind_as_target(const glm::vec4 &clearColor) override; void bind_as_target(const math::vec4 &clearColor) override;
void bind_as_resource() override; void bind_as_resource() override;
void resize(const glm::uvec2 &size) override; void resize(const math::uvec2 &size) override;
auto get_color_attachment() -> void * override auto get_color_attachment() -> void * override
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <math/vec4.hpp>
#include <renderer/render_command.hpp> #include <renderer/render_command.hpp>
struct GLFWwindow; struct GLFWwindow;
@ -14,7 +14,7 @@ public:
void swap_buffers() override; void swap_buffers() override;
void clear_back_buffer(const glm::vec4 &clearColor) override; void clear_back_buffer(const math::vec4 &clearColor) override;
void draw(unsigned int count) override; void draw(unsigned int count) override;

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/vec4.hpp>
#include <renderer/programs/renderer_program.hpp> #include <renderer/programs/renderer_program.hpp>
namespace lt { namespace lt {
@ -19,9 +19,9 @@ public:
~QuadRendererProgram() override = default; ~QuadRendererProgram() override = default;
struct QuadVertexData struct QuadVertexData
{ {
glm::vec4 position; math::vec4 position;
glm::vec4 tint; math::vec4 tint;
}; };
QuadRendererProgram( QuadRendererProgram(

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/vec2.hpp>
#include <math/vec4.hpp>
#include <renderer/programs/renderer_program.hpp> #include <renderer/programs/renderer_program.hpp>
namespace lt { namespace lt {
@ -19,9 +20,9 @@ public:
struct TextureVertexData struct TextureVertexData
{ {
glm::vec4 position; math::vec4 position;
glm::vec2 texcoord; math::vec2 texcoord;
}; };
TextureRendererProgram( TextureRendererProgram(

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/vec2.hpp>
#include <math/vec4.hpp>
#include <renderer/programs/renderer_program.hpp> #include <renderer/programs/renderer_program.hpp>
#include <span> #include <span>
@ -19,11 +20,11 @@ public:
~TintedTextureRendererProgram() override = default; ~TintedTextureRendererProgram() override = default;
struct TintedTextureVertexData struct TintedTextureVertexData
{ {
glm::vec4 position; math::vec4 position;
glm::vec4 tint; math::vec4 tint;
glm::vec2 texcoord; math::vec2 texcoord;
}; };
TintedTextureRendererProgram( TintedTextureRendererProgram(

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <math/vec4.hpp>
#include <glm/glm.hpp>
struct GLFWwindow; struct GLFWwindow;
@ -23,7 +22,7 @@ public:
virtual void swap_buffers() = 0; virtual void swap_buffers() = 0;
virtual void clear_back_buffer(const glm::vec4 &clearColor) = 0; virtual void clear_back_buffer(const math::vec4 &clearColor) = 0;
virtual void draw(unsigned int count) = 0; virtual void draw(unsigned int count) = 0;

View file

@ -1,6 +1,9 @@
#pragma once #pragma once
// //
#include <math/mat4.hpp>
#include <math/vec3.hpp>
#include <math/vec4.hpp>
#include <renderer/blender.hpp> #include <renderer/blender.hpp>
#include <renderer/buffers.hpp> #include <renderer/buffers.hpp>
#include <renderer/render_command.hpp> #include <renderer/render_command.hpp>
@ -48,47 +51,51 @@ public:
) -> Scope<Renderer>; ) -> Scope<Renderer>;
static void draw_quad( static void draw_quad(
const glm::vec3 &position, const math::vec3 &position,
const glm::vec2 &size, const math::vec2 &size,
const glm::vec4 &tint, const math::vec4 &tint,
Ref<Texture> texture Ref<Texture> texture
) )
{ {
s_context->draw_quad_impl(position, size, tint, std::move(texture)); s_context->draw_quad_impl(position, size, tint, std::move(texture));
} }
static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint) static void draw_quad(
const math::vec3 &position,
const math::vec2 &size,
const math::vec4 &tint
)
{ {
s_context->draw_quad_impl(position, size, tint); s_context->draw_quad_impl(position, size, tint);
} }
static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture) static void draw_quad(const math::vec3 &position, const math::vec2 &size, Ref<Texture> texture)
{ {
s_context->draw_quad_impl(position, size, std::move(texture)); s_context->draw_quad_impl(position, size, std::move(texture));
} }
static void draw_quad( static void draw_quad(
const glm::mat4 &transform, const math::mat4 &transform,
const glm::vec4 &tint, const math::vec4 &tint,
const Ref<Texture> &texture const Ref<Texture> &texture
) )
{ {
s_context->draw_quad_impl(transform, tint, texture); s_context->draw_quad_impl(transform, tint, texture);
} }
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint) static void draw_quad(const math::mat4 &transform, const math::vec4 &tint)
{ {
s_context->draw_quad_impl(transform, tint); s_context->draw_quad_impl(transform, tint);
} }
static void draw_quad(const glm::mat4 &transform, const Ref<Texture> &texture) static void draw_quad(const math::mat4 &transform, const Ref<Texture> &texture)
{ {
s_context->draw_quad_impl(transform, texture); s_context->draw_quad_impl(transform, texture);
} }
static void begin_scene( static void begin_scene(
Camera *camera, Camera *camera,
const glm::mat4 &cameraTransform, const math::mat4 &cameraTransform,
const Ref<Framebuffer> &targetFrameBuffer = nullptr const Ref<Framebuffer> &targetFrameBuffer = nullptr
) )
{ {
@ -134,29 +141,29 @@ private:
); );
void draw_quad_impl( void draw_quad_impl(
const glm::vec3 &position, const math::vec3 &position,
const glm::vec2 &size, const math::vec2 &size,
const glm::vec4 &tint, const math::vec4 &tint,
Ref<Texture> texture Ref<Texture> texture
); );
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint); void draw_quad_impl(const math::vec3 &position, const math::vec2 &size, const math::vec4 &tint);
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture); void draw_quad_impl(const math::vec3 &position, const math::vec2 &size, Ref<Texture> texture);
void draw_quad_impl( void draw_quad_impl(
const glm::mat4 &transform, const math::mat4 &transform,
const glm::vec4 &tint, const math::vec4 &tint,
const Ref<Texture> &texture const Ref<Texture> &texture
); );
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint); void draw_quad_impl(const math::mat4 &transform, const math::vec4 &tint);
void draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &texture); void draw_quad_impl(const math::mat4 &transform, const Ref<Texture> &texture);
void begin_scene_impl( void begin_scene_impl(
Camera *camera, Camera *camera,
const glm::mat4 &cameraTransform, const math::mat4 &cameraTransform,
const Ref<Framebuffer> &targetFrameBuffer = nullptr const Ref<Framebuffer> &targetFrameBuffer = nullptr
); );

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <glm/glm.hpp>
namespace Assets { namespace Assets {
class TextAsset; class TextAsset;

View file

@ -1,5 +1,4 @@
#include <glad/gl.h> #include <glad/gl.h>
#include <glm/glm.hpp>
#include <renderer/gl/framebuffers.hpp> #include <renderer/gl/framebuffers.hpp>
namespace lt { namespace lt {
@ -20,7 +19,7 @@ glFramebuffer::~glFramebuffer()
// glDeleteTextures(1, &m_depth_stencil_attachment_id); // glDeleteTextures(1, &m_depth_stencil_attachment_id);
} }
void glFramebuffer::bind_as_target(const glm::vec4 &clearColor) void glFramebuffer::bind_as_target(const math::vec4 &clearColor)
{ {
// #todo: use viewport instead of default x=0, y=0 // #todo: use viewport instead of default x=0, y=0
glBindFramebuffer(GL_FRAMEBUFFER, m_buffer_id); glBindFramebuffer(GL_FRAMEBUFFER, m_buffer_id);
@ -35,7 +34,7 @@ void glFramebuffer::bind_as_resource()
log_err("NO_IMPLEMENT!"); log_err("NO_IMPLEMENT!");
} }
void glFramebuffer::resize(const glm::uvec2 &size) void glFramebuffer::resize(const math::uvec2 &size)
{ {
if (m_buffer_id) if (m_buffer_id)
{ {

View file

@ -15,7 +15,7 @@ void glRenderCommand::swap_buffers()
glfwSwapBuffers(m_window_handle); glfwSwapBuffers(m_window_handle);
} }
void glRenderCommand::clear_back_buffer(const glm::vec4 &clearColor) void glRenderCommand::clear_back_buffer(const math::vec4 &clearColor)
{ {
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View file

@ -1,8 +1,5 @@
#include <asset_parser/assets/text.hpp> #include <asset_parser/assets/text.hpp>
#include <glad/gl.h> #include <glad/gl.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/matrix.hpp>
#include <renderer/gl/shader.hpp> #include <renderer/gl/shader.hpp>
namespace lt { namespace lt {

View file

@ -1,8 +1,5 @@
#include <camera/scene.hpp> #include <camera/scene.hpp>
#include <debug/assertions.hpp> #include <debug/assertions.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/matrix.hpp>
#include <input/events/window.hpp> #include <input/events/window.hpp>
#include <renderer/blender.hpp> #include <renderer/blender.hpp>
#include <renderer/buffers.hpp> #include <renderer/buffers.hpp>
@ -49,7 +46,7 @@ Renderer::Renderer(
m_view_projection_buffer = ConstantBuffer::create( m_view_projection_buffer = ConstantBuffer::create(
ConstantBufferIndex::ViewProjection, ConstantBufferIndex::ViewProjection,
sizeof(glm::mat4), sizeof(math::mat4),
shared_context shared_context
); );
@ -77,69 +74,63 @@ void Renderer::on_window_resize(const WindowResizedEvent &event)
//======================================== DRAW_QUAD ========================================// //======================================== DRAW_QUAD ========================================//
/* tinted textures */ /* tinted textures */
void Renderer::draw_quad_impl( void Renderer::draw_quad_impl(
const glm::vec3 &position, const math::vec3 &position,
const glm::vec2 &size, const math::vec2 &size,
const glm::vec4 &tint, const math::vec4 &tint,
Ref<Texture> texture Ref<Texture> texture
) )
{ {
draw_quad( draw_quad(
glm::translate(glm::mat4(1.0f), position) math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }),
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }),
tint, tint,
std::move(texture) texture
); );
} }
/* tint */ /* tint */
void Renderer::draw_quad_impl( void Renderer::draw_quad_impl(
const glm::vec3 &position, const math::vec3 &position,
const glm::vec2 &size, const math::vec2 &size,
const glm::vec4 &tint const math::vec4 &tint
) )
{ {
draw_quad( draw_quad(math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }), tint);
glm::translate(glm::mat4(1.0f), position)
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }),
tint
);
} }
/* texture */ /* texture */
void Renderer::draw_quad_impl( void Renderer::draw_quad_impl(
const glm::vec3 &position, const math::vec3 &position,
const glm::vec2 &size, const math::vec2 &size,
Ref<Texture> texture Ref<Texture> texture
) )
{ {
draw_quad( draw_quad(
glm::translate(glm::mat4(1.0f), position) math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }),
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }), texture
std::move(texture)
); );
} }
//======================================== DRAW_QUAD ========================================// //======================================== DRAW_QUAD ========================================//
//==================== DRAW_QUAD_TINT ====================// //==================== DRAW_QUAD_TINT ====================//
void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint) void Renderer::draw_quad_impl(const math::mat4 &transform, const math::vec4 &tint)
{ {
auto map = std::span<QuadRendererProgram::QuadVertexData> { m_quad_renderer.get_map_current(), auto map = std::span<QuadRendererProgram::QuadVertexData> { m_quad_renderer.get_map_current(),
4 }; 4 };
// top left // top left
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); map[0].position = transform * math::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
map[0].tint = tint; map[0].tint = tint;
// top right // top right
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); map[1].position = transform * math::vec4(0.5f, -0.5f, 0.0f, 1.0f);
map[1].tint = tint; map[1].tint = tint;
// bottom right // bottom right
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); map[2].position = transform * math::vec4(0.5f, 0.5f, 0.0f, 1.0f);
map[2].tint = tint; map[2].tint = tint;
// bottom left // bottom left
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); map[3].position = transform * math::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
map[3].tint = tint; map[3].tint = tint;
// advance // advance
@ -150,7 +141,7 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
} }
} }
void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &texture) void Renderer::draw_quad_impl(const math::mat4 &transform, const Ref<Texture> &texture)
{ {
ensure(texture, "Texture passed to renderer::draw_quad_impl"); ensure(texture, "Texture passed to renderer::draw_quad_impl");
@ -161,19 +152,19 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &te
}; };
// top left // top left
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); map[0].position = transform * math::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
map[0].texcoord = { 0.0f, 0.0f }; map[0].texcoord = { 0.0f, 0.0f };
// top right // top right
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); map[1].position = transform * math::vec4(0.5f, -0.5f, 0.0f, 1.0f);
map[1].texcoord = { 1.0f, 0.0f }; map[1].texcoord = { 1.0f, 0.0f };
// bottom right // bottom right
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); map[2].position = transform * math::vec4(0.5f, 0.5f, 0.0f, 1.0f);
map[2].texcoord = { 1.0f, 1.0f }; map[2].texcoord = { 1.0f, 1.0f };
// bottom left // bottom left
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); map[3].position = transform * math::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
map[3].texcoord = { 0.0f, 1.0f }; map[3].texcoord = { 0.0f, 1.0f };
// advance // advance
@ -185,8 +176,8 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &te
} }
void Renderer::draw_quad_impl( void Renderer::draw_quad_impl(
const glm::mat4 &transform, const math::mat4 &transform,
const glm::vec4 &tint, const math::vec4 &tint,
const Ref<Texture> &texture const Ref<Texture> &texture
) )
{ {
@ -199,22 +190,22 @@ void Renderer::draw_quad_impl(
}; };
// top left // top left
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f); map[0].position = transform * math::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
map[0].tint = tint; map[0].tint = tint;
map[0].texcoord = { 0.0f, 0.0f }; map[0].texcoord = { 0.0f, 0.0f };
// top right // top right
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f); map[1].position = transform * math::vec4(0.5f, -0.5f, 0.0f, 1.0f);
map[1].tint = tint; map[1].tint = tint;
map[1].texcoord = { 1.0f, 0.0f }; map[1].texcoord = { 1.0f, 0.0f };
// bottom right // bottom right
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f); map[2].position = transform * math::vec4(0.5f, 0.5f, 0.0f, 1.0f);
map[2].tint = tint; map[2].tint = tint;
map[2].texcoord = { 1.0f, 1.0f }; map[2].texcoord = { 1.0f, 1.0f };
// bottom left // bottom left
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f); map[3].position = transform * math::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
map[3].tint = tint; map[3].tint = tint;
map[3].texcoord = { 0.0f, 1.0f }; map[3].texcoord = { 0.0f, 1.0f };
@ -234,7 +225,7 @@ void Renderer::end_frame()
m_render_command->swap_buffers(); m_render_command->swap_buffers();
m_render_command->clear_back_buffer( m_render_command->clear_back_buffer(
m_default_framebuffer_camera ? m_default_framebuffer_camera->get_background_color() : m_default_framebuffer_camera ? m_default_framebuffer_camera->get_background_color() :
glm::vec4(0.0f) math::vec4(0.0f)
); );
m_default_framebuffer_camera = nullptr; m_default_framebuffer_camera = nullptr;
@ -242,7 +233,7 @@ void Renderer::end_frame()
void Renderer::begin_scene_impl( void Renderer::begin_scene_impl(
Camera *camera, Camera *camera,
const glm::mat4 &cameraTransform, const math::mat4 &cameraTransform,
const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */ const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */
) )
{ {
@ -260,8 +251,8 @@ void Renderer::begin_scene_impl(
} }
// update view projection buffer // update view projection buffer
auto *map = (glm::mat4 *)m_view_projection_buffer->map(); auto *map = (math::mat4 *)m_view_projection_buffer->map();
map[0] = camera->get_projection() * glm::inverse(cameraTransform); map[0] = camera->get_projection() * math::inverse(cameraTransform);
m_view_projection_buffer->un_map(); m_view_projection_buffer->un_map();
// map renderers // map renderers

View file

@ -5,8 +5,6 @@ else()
endif() endif()
target_link_libraries(window PUBLIC target_link_libraries(window PUBLIC
glm::glm
PRIVATE PRIVATE
glfw glfw
logger logger

View file

@ -32,7 +32,7 @@ public:
void set_title(const std::string &title) override; void set_title(const std::string &title) override;
void set_size(const glm::uvec2 &size) override; void set_size(const math::uvec2 &size) override;
void set_v_sync(bool vsync, bool toggle = false) override; void set_v_sync(bool vsync, bool toggle = false) override;

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <math/vec2.hpp>
namespace lt { namespace lt {
@ -14,7 +14,7 @@ public:
{ {
std::string title; std::string title;
glm::uvec2 size; math::uvec2 size;
bool vsync, visible; bool vsync, visible;
}; };
@ -41,7 +41,7 @@ public:
virtual void set_title(const std::string &title) = 0; virtual void set_title(const std::string &title) = 0;
virtual void set_size(const glm::uvec2 &size) = 0; virtual void set_size(const math::uvec2 &size) = 0;
void close() void close()
{ {
@ -62,7 +62,7 @@ public:
return m_properties.title; return m_properties.title;
} }
[[nodiscard]] auto get_size() const -> const glm::uvec2 & [[nodiscard]] auto get_size() const -> const math::uvec2 &
{ {
return m_properties.size; return m_properties.size;
} }

View file

@ -85,7 +85,7 @@ void lWindow::set_title(const std::string &title)
glfwSetWindowTitle(m_handle, title.c_str()); glfwSetWindowTitle(m_handle, title.c_str());
} }
void lWindow::set_size(const glm::uvec2 &size) void lWindow::set_size(const math::uvec2 &size)
{ {
m_properties.size = size; m_properties.size = size;
glfwSetWindowSize(m_handle, static_cast<int>(size.x), static_cast<int>(size.y)); glfwSetWindowSize(m_handle, static_cast<int>(size.x), static_cast<int>(size.y));

View file

@ -1,5 +1,4 @@
find_package(glfw3 REQUIRED) find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(stb REQUIRED) find_package(stb REQUIRED)
find_package(yaml-cpp REQUIRED) find_package(yaml-cpp REQUIRED)
find_package(EnTT REQUIRED) find_package(EnTT REQUIRED)