Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic ArchMath #100

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/ArchMath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "math/Math.h"
#include <math.h>

namespace arch {

using namespace arch::math;

} // namespace arch
71 changes: 0 additions & 71 deletions include/Transform.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/Window.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <glm/vec4.hpp>
#include <string>

#include <ArchMath.h>
#include <GLFW/glfw3.h>

namespace arch {
Expand Down Expand Up @@ -33,7 +33,7 @@ class Window {
*/
GLFWwindow* get() const;

void clear(glm::vec4 color) const;
void clear(Color color) const;
void clear(float r, float g, float b, float a) const;
void swapBuffers() const;
void resize(int width, int height) const;
Expand Down
46 changes: 46 additions & 0 deletions include/math/Math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <glm/mat2x2.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat4x4.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>

namespace arch::math {

using Byte = std::byte;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

using f32 = float_t;
using f64 = double_t;
Twarug marked this conversation as resolved.
Show resolved Hide resolved
using fld = long double;

using float2 = glm::vec2;
using float3 = glm::vec3;
using float4 = glm::vec4;

using int2 = glm::ivec2;
using int3 = glm::ivec3;
using int4 = glm::ivec4;

using uint2 = glm::uvec2;
using uint3 = glm::uvec3;
using uint4 = glm::uvec4;

using Mat2x2 = glm::mat2;
using Mat3x3 = glm::mat3;
using Mat4x4 = glm::mat4;

using Color = glm::vec4;

} // namespace arch::math
19 changes: 9 additions & 10 deletions src/Engine.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Engine.h"

#include <glm/glm.hpp>

#include "ArchMath.h"
#include "InputHandler.h"
#include "Logger.h"
#include "exceptions/GLFWException.h"
Expand Down Expand Up @@ -52,18 +51,18 @@ void Engine::_mainLoop() {
// };
// 2D square
struct Vertex {
glm::vec3 position;
glm::vec3 color;
glm::vec2 tex_coords;
float3 position;
float3 color;
float2 tex_coords;
};

std::vector<Vertex> vertices{
{ glm::vec3(0.5f, 0.5f, 0.0f), {}, glm::vec2(1.0f, 1.0f)},
{ glm::vec3(0.5f, -0.5f, 0.0f), {}, glm::vec2(1.0f, 0.0f)},
{glm::vec3(-0.5f, -0.5f, 0.0f), {}, glm::vec2(0.0f, 0.0f)},
{glm::vec3(-0.5f, 0.5f, 0.0f), {}, glm::vec2(0.0f, 1.0f)}
{ float3(0.5f, 0.5f, 0.0f), {}, float2(1.0f, 1.0f) },
{ float3(0.5f, -0.5f, 0.0f), {}, float2(1.0f, 0.0f) },
{ float3(-0.5f, -0.5f, 0.0f), {}, float2(0.0f, 0.0f) },
{ float3(-0.5f, 0.5f, 0.0f), {}, float2(0.0f, 1.0f) }
};
std::vector<uint32_t> indices{0, 1, 3, 1, 2, 3};
std::vector<u32> indices{ 0, 1, 3, 1, 2, 3 };
// Model model { { { vertices, indices } } };
// TextureLoader texture_loader;
// Renderer3D renderer {};
Expand Down
61 changes: 0 additions & 61 deletions src/Transform.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ bool Window::shouldClose() const {
return glfwWindowShouldClose(_window);
}

void Window::clear(glm::vec4 color) const {
glClearColor(color.x, color.y, color.z, color.w);
void Window::clear(Color color) const {
glClearColor(color.r, color.g, color.b, color.a);
glClear(GL_COLOR_BUFFER_BIT);
}

void Window::clear(float r, float g, float b, float a) const {
glm::vec4 color(r, g, b, a);
Color color(r, g, b, a);
clear(color);
}

Expand Down
Loading
Loading