feat: initial math module implementation
refactor: replace glm with built-in math library
This commit is contained in:
parent
d6b7c774bd
commit
f9ce347ca0
43 changed files with 564 additions and 188 deletions
|
@ -3,6 +3,7 @@ add_subdirectory(./base)
|
|||
add_subdirectory(./time)
|
||||
add_subdirectory(./logger)
|
||||
add_subdirectory(./debug)
|
||||
add_subdirectory(./math)
|
||||
|
||||
add_subdirectory(./asset_baker)
|
||||
add_subdirectory(./asset_parser)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
add_library_module(camera camera.cpp scene.cpp)
|
||||
|
||||
target_link_libraries(camera PUBLIC glm::glm)
|
||||
target_link_libraries(camera PUBLIC math)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/mat4.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
@ -9,26 +10,26 @@ class Camera
|
|||
public:
|
||||
Camera() = default;
|
||||
|
||||
[[nodiscard]] auto get_projection() const -> const glm::mat4 &
|
||||
[[nodiscard]] auto get_projection() const -> const math::mat4 &
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void set_background_color(const glm::vec4 &color)
|
||||
void set_background_color(const math::vec4 &color)
|
||||
{
|
||||
m_background_color = color;
|
||||
}
|
||||
|
||||
protected:
|
||||
glm::mat4 m_projection {};
|
||||
math::mat4 m_projection;
|
||||
|
||||
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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <camera/scene.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include <camera/scene.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <math/algebra.hpp>
|
||||
#include <math/trig.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
SceneCamera::SceneCamera()
|
||||
: 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,
|
||||
.far_plane = 10000.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()
|
||||
{
|
||||
// TODO(Light): implement ortho perspective
|
||||
if (m_projection_type == ProjectionType::Orthographic)
|
||||
{
|
||||
m_projection = glm::ortho(
|
||||
-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
|
||||
);
|
||||
// throw std::runtime_error { "ortho perspective not supported yet" };
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace lt {
|
||||
|
@ -15,7 +15,7 @@ struct SpriteRendererComponent
|
|||
|
||||
SpriteRendererComponent(
|
||||
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)))
|
||||
, tint(_tint)
|
||||
|
@ -29,7 +29,7 @@ struct SpriteRendererComponent
|
|||
|
||||
Ref<Texture> texture;
|
||||
|
||||
glm::vec4 tint {};
|
||||
math::vec4 tint {};
|
||||
};
|
||||
|
||||
} // namespace lt
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/transform.hpp>
|
||||
#include <math/mat4.hpp>
|
||||
#include <math/vec3.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
@ -13,9 +10,9 @@ struct TransformComponent
|
|||
TransformComponent(const TransformComponent &) = default;
|
||||
|
||||
TransformComponent(
|
||||
const glm::vec3 &_translation = glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
const glm::vec3 &_scale = glm::vec3(1.0f, 1.0f, 1.0f),
|
||||
const glm::vec3 &_rotation = glm::vec3(0.0f, 0.0f, 0.0f)
|
||||
const math::vec3 &_translation = math::vec3(0.0f, 0.0f, 0.0f),
|
||||
const math::vec3 &_scale = math::vec3(1.0f, 1.0f, 1.0f),
|
||||
const math::vec3 &_rotation = math::vec3(0.0f, 0.0f, 0.0f)
|
||||
)
|
||||
|
||||
: 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))
|
||||
* glm::scale(scale);
|
||||
return math::translate(translation)
|
||||
* 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();
|
||||
}
|
||||
|
||||
glm::vec3 translation;
|
||||
math::vec3 translation;
|
||||
|
||||
glm::vec3 scale;
|
||||
math::vec3 scale;
|
||||
|
||||
glm::vec3 rotation;
|
||||
math::vec3 rotation;
|
||||
};
|
||||
|
||||
} // namespace lt
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <ecs/components/transform.hpp>
|
||||
#include <ecs/uuid.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <ecs/components.hpp>
|
||||
#include <ecs/entity.hpp>
|
||||
#include <ecs/scene.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <renderer/renderer.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
#include <camera/component.hpp>
|
||||
#include <ecs/components.hpp>
|
||||
#include <ecs/serializer.hpp>
|
||||
#include <math/vec3.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
namespace YAML {
|
||||
|
||||
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 {};
|
||||
node.push_back(rhs.x);
|
||||
|
@ -18,7 +20,7 @@ struct convert<glm::vec3>
|
|||
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)
|
||||
{
|
||||
|
@ -33,9 +35,9 @@ struct convert<glm::vec3>
|
|||
};
|
||||
|
||||
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 {};
|
||||
node.push_back(rhs.x);
|
||||
|
@ -45,7 +47,7 @@ struct convert<glm::vec4>
|
|||
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)
|
||||
{
|
||||
|
@ -63,14 +65,14 @@ struct convert<glm::vec4>
|
|||
|
||||
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::BeginSeq << v.x << v.y << v.z << YAML::EndSeq;
|
||||
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::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>();
|
||||
|
||||
entityTransforomComponent.translation = transformComponent["Translation"]
|
||||
.as<glm::vec3>();
|
||||
entityTransforomComponent.rotation = transformComponent["Rotation"].as<glm::vec3>();
|
||||
entityTransforomComponent.scale = transformComponent["Scale"].as<glm::vec3>();
|
||||
.as<math::vec3>();
|
||||
entityTransforomComponent.rotation = transformComponent["Rotation"]
|
||||
.as<math::vec3>();
|
||||
entityTransforomComponent.scale = transformComponent["Scale"].as<math::vec3>();
|
||||
}
|
||||
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
@ -168,7 +171,7 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool
|
|||
auto &entitySpriteRendererComponent = deserializedEntity
|
||||
.add_component<SpriteRendererComponent>();
|
||||
entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"]
|
||||
.as<glm::vec4>();
|
||||
.as<math::vec4>();
|
||||
|
||||
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(
|
||||
cameraSpecifications["BackgroundColor"].as<glm::vec4>()
|
||||
cameraSpecifications["BackgroundColor"].as<math::vec4>()
|
||||
);
|
||||
|
||||
entityCameraComponent.isPrimary = cameraComponent["IsPrimary"].as<bool>();
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
add_library_module(input input.cpp)
|
||||
target_link_libraries(input PUBLIC glm::glm imgui logger)
|
||||
target_link_libraries(input PUBLIC math imgui logger)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <input/events/event.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const glm::vec2 m_position;
|
||||
const math::vec2 m_position;
|
||||
};
|
||||
|
||||
class WheelScrolledEvent: public Event
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <input/events/event.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const glm::ivec2 m_position;
|
||||
const math::ivec2 m_position;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const glm::uvec2 m_size;
|
||||
const math::uvec2 m_size;
|
||||
};
|
||||
|
||||
class WindowLostFocusEvent: public Event
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
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;
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ private:
|
|||
|
||||
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 {};
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ void Input::restart_input_state()
|
|||
m_keyboad_keys.fill(false);
|
||||
m_mouse_buttons.fill(false);
|
||||
|
||||
m_mouse_position = glm::vec2(0.0f);
|
||||
m_mouse_delta = glm::vec2(0.0f);
|
||||
m_mouse_position = math::vec2(0.0f);
|
||||
m_mouse_delta = math::vec2(0.0f);
|
||||
m_mouse_wheel_delta = 0.0f;
|
||||
}
|
||||
|
||||
|
|
1
modules/math/CMakeLists.txt
Normal file
1
modules/math/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
add_library_module(math)
|
57
modules/math/include/math/algebra.hpp
Normal file
57
modules/math/include/math/algebra.hpp
Normal 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
|
109
modules/math/include/math/mat4.hpp
Normal file
109
modules/math/include/math/mat4.hpp
Normal 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
|
26
modules/math/include/math/trig.hpp
Normal file
26
modules/math/include/math/trig.hpp
Normal 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
|
56
modules/math/include/math/vec2.hpp
Normal file
56
modules/math/include/math/vec2.hpp
Normal 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
|
53
modules/math/include/math/vec3.hpp
Normal file
53
modules/math/include/math/vec3.hpp
Normal 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
|
78
modules/math/include/math/vec4.hpp
Normal file
78
modules/math/include/math/vec4.hpp
Normal 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
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <app/layer.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <imgui.h>
|
||||
#include <math/vec2.hpp>
|
||||
#include <mirror/panel/asset_browser.hpp>
|
||||
#include <mirror/panel/properties.hpp>
|
||||
#include <mirror/panel/scene_hierarchy.hpp>
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
private:
|
||||
std::string m_scene_dir;
|
||||
|
||||
glm::vec2 m_direction;
|
||||
math::vec2 m_direction;
|
||||
|
||||
float m_speed = 1000.0f;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <ecs/entity.hpp>
|
||||
#include <math/vec3.hpp>
|
||||
#include <mirror/panel/panel.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -17,7 +18,7 @@ public:
|
|||
private:
|
||||
void draw_vec3_control(
|
||||
const std::string &label,
|
||||
glm::vec3 &values,
|
||||
math::vec3 &values,
|
||||
float reset_value = 0.0f,
|
||||
float column_width = 100.0f
|
||||
);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <ecs/serializer.hpp>
|
||||
#include <input/input.hpp>
|
||||
#include <input/key_codes.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <mirror/editor_layer.hpp>
|
||||
#include <renderer/framebuffer.hpp>
|
||||
#include <renderer/graphics_context.hpp>
|
||||
|
@ -44,7 +45,7 @@ EditorLayer::EditorLayer(const std::string &name)
|
|||
auto entity = Entity { m_scene->create_entity("Awesomeface", {}) };
|
||||
entity.add_component<SpriteRendererComponent>(
|
||||
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
|
||||
|
@ -96,7 +97,8 @@ void EditorLayer::on_update(float delta_time)
|
|||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -122,7 +124,12 @@ void EditorLayer::on_user_interface_update()
|
|||
if (m_available_content_region_prev.x != available_region.x
|
||||
|| 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;
|
||||
camera.set_viewport_size(
|
||||
static_cast<uint32_t>(available_region.x),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <app/application.hpp>
|
||||
#include <app/entrypoint.hpp>
|
||||
#include <app/layer_stack.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <mirror/editor_layer.hpp>
|
||||
#include <window/window.hpp>
|
||||
|
||||
|
@ -14,7 +15,7 @@ public:
|
|||
get_window().set_properties(
|
||||
Window::Properties {
|
||||
.title = "Mirror",
|
||||
.size = glm::uvec2(1280u, 720u),
|
||||
.size = math::uvec2(1280u, 720u),
|
||||
.vsync = true,
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include <asset_manager/asset_manager.hpp>
|
||||
#include <camera/component.hpp>
|
||||
#include <ecs/components.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <math/trig.hpp>
|
||||
#include <mirror/panel/properties.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -21,7 +20,7 @@ void PropertiesPanel::on_user_interface_update()
|
|||
|
||||
auto buffer = std::array<char, 256> {};
|
||||
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()))
|
||||
{
|
||||
|
@ -147,13 +146,13 @@ void PropertiesPanel::on_user_interface_update()
|
|||
auto near_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();
|
||||
far_plane = camera.get_perspective_far_plane();
|
||||
|
||||
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))
|
||||
|
@ -182,7 +181,7 @@ void PropertiesPanel::set_entity_context(const Entity &entity)
|
|||
|
||||
void PropertiesPanel::draw_vec3_control(
|
||||
const std::string &label,
|
||||
glm::vec3 &values,
|
||||
math::vec3 &values,
|
||||
float reset_value,
|
||||
float column_width
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
@ -25,11 +25,11 @@ public:
|
|||
const Ref<SharedContext> &sharedContext
|
||||
) -> 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 resize(const glm::uvec2 &size) = 0;
|
||||
virtual void resize(const math::uvec2 &size) = 0;
|
||||
|
||||
virtual auto get_color_attachment() -> void * = 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <math/vec2.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/framebuffer.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -12,11 +13,11 @@ public:
|
|||
|
||||
~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 resize(const glm::uvec2 &size) override;
|
||||
void resize(const math::uvec2 &size) override;
|
||||
|
||||
auto get_color_attachment() -> void * override
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/render_command.hpp>
|
||||
|
||||
struct GLFWwindow;
|
||||
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/programs/renderer_program.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -19,9 +19,9 @@ public:
|
|||
~QuadRendererProgram() override = default;
|
||||
struct QuadVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
math::vec4 position;
|
||||
|
||||
glm::vec4 tint;
|
||||
math::vec4 tint;
|
||||
};
|
||||
|
||||
QuadRendererProgram(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/programs/renderer_program.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -19,9 +20,9 @@ public:
|
|||
|
||||
struct TextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
math::vec4 position;
|
||||
|
||||
glm::vec2 texcoord;
|
||||
math::vec2 texcoord;
|
||||
};
|
||||
|
||||
TextureRendererProgram(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/programs/renderer_program.hpp>
|
||||
#include <span>
|
||||
|
||||
|
@ -19,11 +20,11 @@ public:
|
|||
~TintedTextureRendererProgram() override = default;
|
||||
struct TintedTextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
math::vec4 position;
|
||||
|
||||
glm::vec4 tint;
|
||||
math::vec4 tint;
|
||||
|
||||
glm::vec2 texcoord;
|
||||
math::vec2 texcoord;
|
||||
};
|
||||
|
||||
TintedTextureRendererProgram(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
|
@ -23,7 +22,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
//
|
||||
#include <math/mat4.hpp>
|
||||
#include <math/vec3.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <renderer/blender.hpp>
|
||||
#include <renderer/buffers.hpp>
|
||||
#include <renderer/render_command.hpp>
|
||||
|
@ -48,47 +51,51 @@ public:
|
|||
) -> Scope<Renderer>;
|
||||
|
||||
static void draw_quad(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint,
|
||||
const math::vec3 &position,
|
||||
const math::vec2 &size,
|
||||
const math::vec4 &tint,
|
||||
Ref<Texture> 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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
static void draw_quad(
|
||||
const glm::mat4 &transform,
|
||||
const glm::vec4 &tint,
|
||||
const math::mat4 &transform,
|
||||
const math::vec4 &tint,
|
||||
const Ref<Texture> &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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void begin_scene(
|
||||
Camera *camera,
|
||||
const glm::mat4 &cameraTransform,
|
||||
const math::mat4 &cameraTransform,
|
||||
const Ref<Framebuffer> &targetFrameBuffer = nullptr
|
||||
)
|
||||
{
|
||||
|
@ -134,29 +141,29 @@ private:
|
|||
);
|
||||
|
||||
void draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint,
|
||||
const math::vec3 &position,
|
||||
const math::vec2 &size,
|
||||
const math::vec4 &tint,
|
||||
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(
|
||||
const glm::mat4 &transform,
|
||||
const glm::vec4 &tint,
|
||||
const math::mat4 &transform,
|
||||
const math::vec4 &tint,
|
||||
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(
|
||||
Camera *camera,
|
||||
const glm::mat4 &cameraTransform,
|
||||
const math::mat4 &cameraTransform,
|
||||
const Ref<Framebuffer> &targetFrameBuffer = nullptr
|
||||
);
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Assets {
|
||||
|
||||
class TextAsset;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <glad/gl.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <renderer/gl/framebuffers.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
@ -20,7 +19,7 @@ glFramebuffer::~glFramebuffer()
|
|||
// 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
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_buffer_id);
|
||||
|
@ -35,7 +34,7 @@ void glFramebuffer::bind_as_resource()
|
|||
log_err("NO_IMPLEMENT!");
|
||||
}
|
||||
|
||||
void glFramebuffer::resize(const glm::uvec2 &size)
|
||||
void glFramebuffer::resize(const math::uvec2 &size)
|
||||
{
|
||||
if (m_buffer_id)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ void glRenderCommand::swap_buffers()
|
|||
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);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include <asset_parser/assets/text.hpp>
|
||||
#include <glad/gl.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <renderer/gl/shader.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include <camera/scene.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 <renderer/blender.hpp>
|
||||
#include <renderer/buffers.hpp>
|
||||
|
@ -49,7 +46,7 @@ Renderer::Renderer(
|
|||
|
||||
m_view_projection_buffer = ConstantBuffer::create(
|
||||
ConstantBufferIndex::ViewProjection,
|
||||
sizeof(glm::mat4),
|
||||
sizeof(math::mat4),
|
||||
shared_context
|
||||
);
|
||||
|
||||
|
@ -77,69 +74,63 @@ void Renderer::on_window_resize(const WindowResizedEvent &event)
|
|||
//======================================== DRAW_QUAD ========================================//
|
||||
/* tinted textures */
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint,
|
||||
const math::vec3 &position,
|
||||
const math::vec2 &size,
|
||||
const math::vec4 &tint,
|
||||
Ref<Texture> texture
|
||||
)
|
||||
{
|
||||
draw_quad(
|
||||
glm::translate(glm::mat4(1.0f), position)
|
||||
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }),
|
||||
math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }),
|
||||
tint,
|
||||
std::move(texture)
|
||||
texture
|
||||
);
|
||||
}
|
||||
|
||||
/* tint */
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint
|
||||
const math::vec3 &position,
|
||||
const math::vec2 &size,
|
||||
const math::vec4 &tint
|
||||
)
|
||||
{
|
||||
draw_quad(
|
||||
glm::translate(glm::mat4(1.0f), position)
|
||||
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }),
|
||||
tint
|
||||
);
|
||||
draw_quad(math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }), tint);
|
||||
}
|
||||
|
||||
/* texture */
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const math::vec3 &position,
|
||||
const math::vec2 &size,
|
||||
Ref<Texture> texture
|
||||
)
|
||||
{
|
||||
draw_quad(
|
||||
glm::translate(glm::mat4(1.0f), position)
|
||||
* glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f }),
|
||||
std::move(texture)
|
||||
math::translate(position) * math::scale(math::vec3 { size.x, size.y, 1.0f }),
|
||||
texture
|
||||
);
|
||||
}
|
||||
//======================================== DRAW_QUAD ========================================//
|
||||
|
||||
//==================== 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(),
|
||||
4 };
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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");
|
||||
|
||||
|
@ -161,19 +152,19 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &te
|
|||
};
|
||||
|
||||
// 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 };
|
||||
|
||||
// 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 };
|
||||
|
||||
// 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 };
|
||||
|
||||
// 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 };
|
||||
|
||||
// advance
|
||||
|
@ -185,8 +176,8 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &te
|
|||
}
|
||||
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::mat4 &transform,
|
||||
const glm::vec4 &tint,
|
||||
const math::mat4 &transform,
|
||||
const math::vec4 &tint,
|
||||
const Ref<Texture> &texture
|
||||
)
|
||||
{
|
||||
|
@ -199,22 +190,22 @@ void Renderer::draw_quad_impl(
|
|||
};
|
||||
|
||||
// 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].texcoord = { 0.0f, 0.0f };
|
||||
|
||||
// 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].texcoord = { 1.0f, 0.0f };
|
||||
|
||||
// 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].texcoord = { 1.0f, 1.0f };
|
||||
|
||||
// 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].texcoord = { 0.0f, 1.0f };
|
||||
|
||||
|
@ -234,7 +225,7 @@ void Renderer::end_frame()
|
|||
m_render_command->swap_buffers();
|
||||
m_render_command->clear_back_buffer(
|
||||
m_default_framebuffer_camera ? m_default_framebuffer_camera->get_background_color() :
|
||||
glm::vec4(0.0f)
|
||||
math::vec4(0.0f)
|
||||
);
|
||||
|
||||
m_default_framebuffer_camera = nullptr;
|
||||
|
@ -242,7 +233,7 @@ void Renderer::end_frame()
|
|||
|
||||
void Renderer::begin_scene_impl(
|
||||
Camera *camera,
|
||||
const glm::mat4 &cameraTransform,
|
||||
const math::mat4 &cameraTransform,
|
||||
const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */
|
||||
)
|
||||
{
|
||||
|
@ -260,8 +251,8 @@ void Renderer::begin_scene_impl(
|
|||
}
|
||||
|
||||
// update view projection buffer
|
||||
auto *map = (glm::mat4 *)m_view_projection_buffer->map();
|
||||
map[0] = camera->get_projection() * glm::inverse(cameraTransform);
|
||||
auto *map = (math::mat4 *)m_view_projection_buffer->map();
|
||||
map[0] = camera->get_projection() * math::inverse(cameraTransform);
|
||||
m_view_projection_buffer->un_map();
|
||||
|
||||
// map renderers
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <math/vec2.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
|
@ -14,7 +14,7 @@ public:
|
|||
{
|
||||
std::string title;
|
||||
|
||||
glm::uvec2 size;
|
||||
math::uvec2 size;
|
||||
|
||||
bool vsync, visible;
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
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()
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
return m_properties.title;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_size() const -> const glm::uvec2 &
|
||||
[[nodiscard]] auto get_size() const -> const math::uvec2 &
|
||||
{
|
||||
return m_properties.size;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ void lWindow::set_title(const std::string &title)
|
|||
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;
|
||||
glfwSetWindowSize(m_handle, static_cast<int>(size.x), static_cast<int>(size.y));
|
||||
|
|
Loading…
Add table
Reference in a new issue