From 283ce106971fb2870047075f153bcba2a203ce52 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Wed, 23 Feb 2022 19:26:58 -0800 Subject: [PATCH] Move math library to separate project --- include/egn/base_types.hpp | 6 +- include/egn/camera.hpp | 16 +- include/egn/font.hpp | 20 +- include/egn/game.hpp | 4 +- include/egn/object.hpp | 36 +-- include/gfx/ogl/fbo.hpp | 8 +- include/gfx/ogl/shader_program.hpp | 118 ++++---- include/gfx/ogl/texture.hpp | 4 +- include/gfx/ogl/ubo.hpp | 6 +- include/gfx/ogl/ubo.tpp | 2 +- include/gfx/ogl/vao.hpp | 3 +- include/gfx/ogl/window.hpp | 14 +- include/math/debug.hpp | 75 ----- include/math/detail/matrix.hpp | 117 -------- include/math/detail/matrix.tpp | 151 ---------- include/math/fwd_declare.hpp | 196 ------------- include/math/mat.hpp | 243 ---------------- include/math/mat.tpp | 424 ---------------------------- include/math/math.hpp | 31 -- include/math/math_common.hpp | 83 ------ include/math/projection.hpp | 46 --- include/math/projection.tpp | 98 ------- include/math/quat.hpp | 149 ---------- include/math/quat.tpp | 437 ----------------------------- include/math/vec.hpp | 128 --------- include/math/vec.tpp | 254 ----------------- include/ttt/board.hpp | 10 +- include/ttt/main_renderer.hpp | 10 +- include/ttt/play_state.hpp | 4 +- include/ttt/screen_renderer.hpp | 6 +- include/wip/ogl_material.hpp | 8 +- include/wip/ogl_renderer.hpp | 14 +- include/wip/vertex.hpp | 6 +- makefile | 7 +- src/egn/base_types.cpp | 2 +- src/egn/camera.cpp | 16 +- src/egn/collision.cpp | 56 ++-- src/egn/font.cpp | 10 +- src/egn/game.cpp | 2 +- src/egn/object.cpp | 36 +-- src/gfx/ogl/fbo.cpp | 6 +- src/gfx/ogl/shader_program.cpp | 180 ++++++------ src/gfx/ogl/texture.cpp | 4 +- src/gfx/ogl/window.cpp | 20 +- src/main.cpp | 2 +- src/math/mat.cpp | 28 -- src/math/quat.cpp | 26 -- src/math/vec.cpp | 28 -- src/ttt/board.cpp | 14 +- src/ttt/main_renderer.cpp | 8 +- src/ttt/play_state.cpp | 22 +- src/ttt/screen_renderer.cpp | 2 +- src/wip/ogl_renderer.cpp | 6 +- src/wip/ogl_shader.cpp | 3 + src/wip/square.cpp | 4 +- 55 files changed, 348 insertions(+), 2861 deletions(-) delete mode 100644 include/math/debug.hpp delete mode 100644 include/math/detail/matrix.hpp delete mode 100644 include/math/detail/matrix.tpp delete mode 100644 include/math/fwd_declare.hpp delete mode 100644 include/math/mat.hpp delete mode 100644 include/math/mat.tpp delete mode 100644 include/math/math.hpp delete mode 100644 include/math/math_common.hpp delete mode 100644 include/math/projection.hpp delete mode 100644 include/math/projection.tpp delete mode 100644 include/math/quat.hpp delete mode 100644 include/math/quat.tpp delete mode 100644 include/math/vec.hpp delete mode 100644 include/math/vec.tpp delete mode 100644 src/math/mat.cpp delete mode 100644 src/math/quat.cpp delete mode 100644 src/math/vec.cpp diff --git a/include/egn/base_types.hpp b/include/egn/base_types.hpp index c96b16f..28c9431 100644 --- a/include/egn/base_types.hpp +++ b/include/egn/base_types.hpp @@ -19,12 +19,12 @@ #ifndef OUR_DICK_ENGINE_BASE_TYPES_HPP #define OUR_DICK_ENGINE_BASE_TYPES_HPP -#include "math/vec.hpp" +#include namespace egn{ //Represent a 3D point - using point = math::vec3f; + using point = rml::vec3f; //Represent a line segment in 3D space given the end points class line_segment @@ -52,7 +52,7 @@ namespace egn{ point point2 = {}; public: aabb(void) = default; - aabb(const math::vec3f& p1, const math::vec3f& p2); + aabb(const rml::vec3f& p1, const rml::vec3f& p2); aabb(const aabb&) = default; aabb(aabb&&) = default; ~aabb(void) = default; diff --git a/include/egn/camera.hpp b/include/egn/camera.hpp index c055caf..8e858e5 100644 --- a/include/egn/camera.hpp +++ b/include/egn/camera.hpp @@ -19,7 +19,7 @@ #ifndef OUR_DICK_ENGINE_CAMERA_HPP #define OUR_DICK_ENGINE_CAMERA_HPP -#include "math/math.hpp" +#include #include "object.hpp" namespace egn{ @@ -37,15 +37,15 @@ namespace egn{ protected: //mutable because they're only really a cached value representation of the data //in position, orientation, near, far, etc - mutable math::mat4f m_projection_matrix; //camera-to-sceen matrix - mutable math::mat4f m_view_matrix; //world-to-camera matrix + mutable rml::mat4f m_projection_matrix; //camera-to-sceen matrix + mutable rml::mat4f m_view_matrix; //world-to-camera matrix float m_near = 1; //near clipping plane in camera space float m_far = 100; //far clipping plane in camera space public: camera_iface(void) = default; //Initialize with given projection matrix and clipping planes - camera_iface(const math::mat4f& proj, float n, float f); + camera_iface(const rml::mat4f& proj, float n, float f); camera_iface(const camera_iface&) = default; camera_iface(camera_iface&&) = default; virtual ~camera_iface(void) = default; @@ -54,13 +54,13 @@ namespace egn{ camera_iface& operator=(camera_iface&&) = default; //Set the camera's location and update relevant data structures - void set_position(const math::vec3f& pos)override; + void set_position(const rml::vec3f& pos)override; //Set the camera's facing angle and update relevant data structures - void set_orientation(const math::quat_f& distance)override; + void set_orientation(const rml::quat_f& distance)override; //getters - const math::mat4f& get_projection_matrix(void)const; - const math::mat4f& get_view_matrix(void)const; + const rml::mat4f& get_projection_matrix(void)const; + const rml::mat4f& get_view_matrix(void)const; float get_near_plane(void)const; float get_far_plane(void)const; diff --git a/include/egn/font.hpp b/include/egn/font.hpp index 968afcf..03266a5 100644 --- a/include/egn/font.hpp +++ b/include/egn/font.hpp @@ -33,11 +33,11 @@ namespace egn{ struct font_character{ - math::vec2 atlas_offset; - math::vec2i size; - math::vec2i bearing; - math::vec2i advance; - math::vec2f texture_coords[4]; + rml::vec2 atlas_offset; + rml::vec2i size; + rml::vec2i bearing; + rml::vec2i advance; + rml::vec2f texture_coords[4]; public: float aspect_ratio(void)const; @@ -67,7 +67,7 @@ namespace egn{ font_character& operator[](int character); - math::vec2 glyph_size(void)const; + rml::vec2 glyph_size(void)const; }; class font @@ -92,8 +92,8 @@ namespace egn{ private: using atlas_meta = std::tuple; template - void generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range, Ts&&... ranges); - void generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range); + void generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, rml::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range, Ts&&... ranges); + void generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, rml::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range); template atlas_meta get_atlas_size_ranges_(Ts&&... ranges); template @@ -108,7 +108,7 @@ namespace egn{ template - void font::generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range, Ts&&... ranges){ + void font::generate_atlas_piece_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, rml::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range, Ts&&... ranges){ generate_atlas_piece_impl_(atlas, metadata, target_pos, info, data_buffer, range); if constexpr(sizeof...(ranges) > 0){ @@ -125,7 +125,7 @@ namespace egn{ gfx::ogl::texture atlas(format, atlas_width, atlas_height, GL_UNSIGNED_BYTE, false); font_atlas::map_type atlas_metadata; - math::vec2 target_position = {0, 0}; + rml::vec2 target_position = {0, 0}; std::unique_ptr dest_data(new unsigned char[max_glyph_height * max_glyph_width * m_depth]); generate_atlas_piece_(atlas, atlas_metadata, target_position, std::tuple{atlas_width, atlas_height, max_glyph_width, max_glyph_height}, dest_data.get(), std::forward(ranges)...); diff --git a/include/egn/game.hpp b/include/egn/game.hpp index 8655d13..0405ee3 100644 --- a/include/egn/game.hpp +++ b/include/egn/game.hpp @@ -23,7 +23,7 @@ #include "game_state.hpp" #include "gfx/ogl/window.hpp" #include "input.hpp" -#include "math/vec.hpp" +#include #include "wip/renderer.hpp" #include @@ -50,7 +50,7 @@ namespace egn{ void keypress(int key, int action, int mods); void resize(int width, int height); - math::vec2 get_mouse_pos(void)const; + rml::vec2 get_mouse_pos(void)const; void on_notify(const game_state_event& e)override; diff --git a/include/egn/object.hpp b/include/egn/object.hpp index 98cc67c..c9a7e1d 100644 --- a/include/egn/object.hpp +++ b/include/egn/object.hpp @@ -19,7 +19,7 @@ #ifndef OUR_DICK_ENGINE_OBJECT_HPP #define OUR_DICK_ENGINE_OBJECT_HPP -#include "math/math.hpp" +#include #include "base_types.hpp" namespace egn{ @@ -35,19 +35,19 @@ namespace egn{ BOUNDING_VOLUME_UPDATE = 8, }; protected: - math::vec3f m_position; //track current positon in world space - math::quat_f m_orientation; //track current model space rotation - math::vec3f m_scale{1.0f, 1.0f, 1.0f}; //track model space scale + rml::vec3f m_position; //track current positon in world space + rml::quat_f m_orientation; //track current model space rotation + rml::vec3f m_scale{1.0f, 1.0f, 1.0f}; //track model space scale private: - mutable math::mat4f m_model_matrix; //compile all the above info into a matrix + mutable rml::mat4f m_model_matrix; //compile all the above info into a matrix protected: mutable int m_update_flag = NO_UPDATE; //whether or not to update the matrix upon access //make the update flag protected so subclasses can share it public: object(void) = default; - explicit object(const math::vec3f& position); - object(const math::vec3f& position, const math::quat_f& orientation); + explicit object(const rml::vec3f& position); + object(const rml::vec3f& position, const rml::quat_f& orientation); object(const object&) = default; object(object&&) = default; virtual ~object(void) = default; @@ -55,19 +55,19 @@ namespace egn{ object& operator=(const object&) = default; object& operator=(object&&) = default; - void translate(const math::vec3f& distance); - void rotate(const math::quat_f& distance); - void scale(const math::vec3f& distance); - void look_at(const math::vec3f& targ, const math::vec3f& up); + void translate(const rml::vec3f& distance); + void rotate(const rml::quat_f& distance); + void scale(const rml::vec3f& distance); + void look_at(const rml::vec3f& targ, const rml::vec3f& up); - virtual void set_position(const math::vec3f& pos); - virtual void set_orientation(const math::quat_f& orient); - virtual void set_scale(const math::vec3f& scale); + virtual void set_position(const rml::vec3f& pos); + virtual void set_orientation(const rml::quat_f& orient); + virtual void set_scale(const rml::vec3f& scale); - const math::mat4f& model_matrix(void)const; - const math::vec3f& position(void)const; - const math::vec3f& scale(void)const; - const math::quat_f& orientation(void)const; + const rml::mat4f& model_matrix(void)const; + const rml::vec3f& position(void)const; + const rml::vec3f& scale(void)const; + const rml::quat_f& orientation(void)const; protected: void recalc_model_matrix(void)const; diff --git a/include/gfx/ogl/fbo.hpp b/include/gfx/ogl/fbo.hpp index 4f979d8..fbe38e5 100644 --- a/include/gfx/ogl/fbo.hpp +++ b/include/gfx/ogl/fbo.hpp @@ -22,7 +22,7 @@ #include "gl_include.hpp" #include "texture.hpp" #include "rbo.hpp" -#include "math/vec.hpp" +#include #include "util/init_constants.hpp" namespace gfx::ogl{ @@ -32,7 +32,7 @@ namespace gfx::ogl{ { private: GLuint m_buffer; - math::vec4f m_vp_coords; //Opengl doesn't associate viewports with framebuffers, so i do + rml::vec4f m_vp_coords; //Opengl doesn't associate viewports with framebuffers, so i do public: //Construct an object representing the default 'root' framebuffer @@ -59,7 +59,7 @@ namespace gfx::ogl{ bool attach(const rbo& r, GLenum point); //Clear individual fields - void clear_color_buffer(const math::vec4f& color = {0.0f, 0.0f, 0.0f, 1.0f}); + void clear_color_buffer(const rml::vec4f& color = {0.0f, 0.0f, 0.0f, 1.0f}); void clear_depth_buffer(GLfloat value = 1.0f); void clear_stencil_buffer(GLint value = 0); //Clear fields as by glClear @@ -69,7 +69,7 @@ namespace gfx::ogl{ void set_viewport(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); //Activate this framebuffer's viewport. Calls glViewport void apply_viewport(void)const; - const math::vec4f& get_viewport(void)const; + const rml::vec4f& get_viewport(void)const; //Set this as the active framebuffer bool bind(void)const; diff --git a/include/gfx/ogl/shader_program.hpp b/include/gfx/ogl/shader_program.hpp index 10541dd..0092946 100644 --- a/include/gfx/ogl/shader_program.hpp +++ b/include/gfx/ogl/shader_program.hpp @@ -27,12 +27,10 @@ #include //forward #include -#include "math/math.hpp" +#include namespace gfx::ogl{ - using namespace math; - class uniform { private: @@ -52,49 +50,49 @@ namespace gfx::ogl{ GLenum get_type(void)const; GLfloat get_float(void)const; - math::vec2f get_vec2(void)const; - math::vec3f get_vec3(void)const; - math::vec4f get_vec4(void)const; + rml::vec2f get_vec2(void)const; + rml::vec3f get_vec3(void)const; + rml::vec4f get_vec4(void)const; GLdouble get_double(void)const; - math::vec2d get_dvec2(void)const; - math::vec3d get_dvec3(void)const; - math::vec4d get_dvec4(void)const; + rml::vec2d get_dvec2(void)const; + rml::vec3d get_dvec3(void)const; + rml::vec4d get_dvec4(void)const; GLint get_int(void)const; - math::vec2i get_ivec2(void)const; - math::vec3i get_ivec3(void)const; - math::vec4i get_ivec4(void)const; + rml::vec2i get_ivec2(void)const; + rml::vec3i get_ivec3(void)const; + rml::vec4i get_ivec4(void)const; GLuint get_uint(void)const; - math::vec2u get_uvec2(void)const; - math::vec3u get_uvec3(void)const; - math::vec4u get_uvec4(void)const; + rml::vec2u get_uvec2(void)const; + rml::vec3u get_uvec3(void)const; + rml::vec4u get_uvec4(void)const; GLboolean get_bool(void)const; - math::vec2i get_bvec2(void)const; - math::vec3i get_bvec3(void)const; - math::vec4i get_bvec4(void)const; + rml::vec2i get_bvec2(void)const; + rml::vec3i get_bvec3(void)const; + rml::vec4i get_bvec4(void)const; - math::mat2f get_mat2(void)const; - math::mat3f get_mat3(void)const; - math::mat4f get_mat4(void)const; - math::matrix get_mat2x3(void)const; - math::matrix get_mat2x4(void)const; - math::matrix get_mat3x2(void)const; - math::matrix get_mat3x4(void)const; - math::matrix get_mat4x2(void)const; - math::matrix get_mat4x3(void)const; + rml::mat2f get_mat2(void)const; + rml::mat3f get_mat3(void)const; + rml::mat4f get_mat4(void)const; + rml::matrix get_mat2x3(void)const; + rml::matrix get_mat2x4(void)const; + rml::matrix get_mat3x2(void)const; + rml::matrix get_mat3x4(void)const; + rml::matrix get_mat4x2(void)const; + rml::matrix get_mat4x3(void)const; - math::mat2d get_dmat2(void)const; - math::mat3d get_dmat3(void)const; - math::mat4d get_dmat4(void)const; - math::matrix get_dmat2x3(void)const; - math::matrix get_dmat2x4(void)const; - math::matrix get_dmat3x2(void)const; - math::matrix get_dmat3x4(void)const; - math::matrix get_dmat4x2(void)const; - math::matrix get_dmat4x3(void)const; + rml::mat2d get_dmat2(void)const; + rml::mat3d get_dmat3(void)const; + rml::mat4d get_dmat4(void)const; + rml::matrix get_dmat2x3(void)const; + rml::matrix get_dmat2x4(void)const; + rml::matrix get_dmat3x2(void)const; + rml::matrix get_dmat3x4(void)const; + rml::matrix get_dmat4x2(void)const; + rml::matrix get_dmat4x3(void)const; //float void set(GLfloat); @@ -119,14 +117,14 @@ namespace gfx::ogl{ void set(const texture_array& t, GLuint tex_unit = 0); //Float vectors - void set(const vec2f&); - void set(const vec3f&); - void set(const vec4f&); + void set(const rml::vec2f&); + void set(const rml::vec3f&); + void set(const rml::vec4f&); //Float vector array - void set(GLsizei count, const vec2f*); - void set(GLsizei count, const vec3f*); - void set(GLsizei count, const vec4f*); + void set(GLsizei count, const rml::vec2f*); + void set(GLsizei count, const rml::vec3f*); + void set(GLsizei count, const rml::vec4f*); //Explicit float vectors void set_1(GLsizei count, const GLfloat*); @@ -135,14 +133,14 @@ namespace gfx::ogl{ void set_4(GLsizei count, const GLfloat*); //Int vectors - void set(const vec2&); - void set(const vec3&); - void set(const vec4&); + void set(const rml::vec2i&); + void set(const rml::vec3i&); + void set(const rml::vec4i&); //Int vector array - void set(GLsizei count, const vec2*); - void set(GLsizei count, const vec3*); - void set(GLsizei count, const vec4*); + void set(GLsizei count, const rml::vec2i*); + void set(GLsizei count, const rml::vec3i*); + void set(GLsizei count, const rml::vec4i*); //Explicit int vectors void set_1(GLsizei count, const GLint*); @@ -151,14 +149,14 @@ namespace gfx::ogl{ void set_4(GLsizei count, const GLint*); //Unsigned int vectors - void set(const vec2&); - void set(const vec3&); - void set(const vec4&); + void set(const rml::vec2u&); + void set(const rml::vec3u&); + void set(const rml::vec4u&); //Unsigned int vector array - void set(GLsizei count, const vec2*); - void set(GLsizei count, const vec3*); - void set(GLsizei count, const vec4*); + void set(GLsizei count, const rml::vec2u*); + void set(GLsizei count, const rml::vec3u*); + void set(GLsizei count, const rml::vec4u*); //Explicit unsigned int vectors void set_1(GLsizei count, const GLuint*); @@ -167,14 +165,14 @@ namespace gfx::ogl{ void set_4(GLsizei count, const GLuint*); //Matrices - void set(const mat2f&); - void set(const mat3f&); - void set(const mat4f&); + void set(const rml::mat2f&); + void set(const rml::mat3f&); + void set(const rml::mat4f&); //Matrix array - void set(GLsizei count, const mat2f*); - void set(GLsizei count, const mat3f*); - void set(GLsizei count, const mat4f*); + void set(GLsizei count, const rml::mat2f*); + void set(GLsizei count, const rml::mat3f*); + void set(GLsizei count, const rml::mat4f*); //Explicit matrices void set_mat2(GLsizei count, const GLfloat*); diff --git a/include/gfx/ogl/texture.hpp b/include/gfx/ogl/texture.hpp index 2e91de6..9af6e1b 100644 --- a/include/gfx/ogl/texture.hpp +++ b/include/gfx/ogl/texture.hpp @@ -21,7 +21,7 @@ #include "egn/image.hpp" #include "gl_include.hpp" -#include "math/vec.hpp" +#include namespace gfx::ogl{ @@ -85,7 +85,7 @@ namespace gfx::ogl{ magfilter get_mag_filter(void)const; minfilter get_min_filter(void)const; - math::vec4f get_border_color(void)const; + rml::vec4f get_border_color(void)const; wrap get_wrap_x(void)const; wrap get_wrap_y(void)const; diff --git a/include/gfx/ogl/ubo.hpp b/include/gfx/ogl/ubo.hpp index e90ca50..eda5299 100644 --- a/include/gfx/ogl/ubo.hpp +++ b/include/gfx/ogl/ubo.hpp @@ -21,8 +21,8 @@ #include "gl_include.hpp" -#include "math/mat.hpp" -#include "math/vec.hpp" +#include +#include #include //a lot of stuff @@ -51,7 +51,7 @@ namespace gfx::ogl{ template struct is_valid_uniform_matrix{ template - static constexpr bool test(math::matrix_base*){ + static constexpr bool test(rml::matrix_base*){ return is_valid_uniform_scalar::value && T::Columns <= 4 && T::Rows <= 4; } static constexpr bool test(void*){ diff --git a/include/gfx/ogl/ubo.tpp b/include/gfx/ogl/ubo.tpp index 97f72a9..fe9694c 100644 --- a/include/gfx/ogl/ubo.tpp +++ b/include/gfx/ogl/ubo.tpp @@ -229,7 +229,7 @@ namespace gfx::ogl{ return 4; } }else if constexpr(detail::is_bounded_array::value){ - return get_alignment_of_(); + return get_alignment_of_(); }else{ constexpr size_t element_alignment = get_alignment_of_(); if constexpr(T::Columns > 1){ //matrix diff --git a/include/gfx/ogl/vao.hpp b/include/gfx/ogl/vao.hpp index be7df23..24b76b9 100644 --- a/include/gfx/ogl/vao.hpp +++ b/include/gfx/ogl/vao.hpp @@ -20,11 +20,10 @@ #define OUR_DICK_GRAPHICS_OGL_VAO_HPP #include "gl_include.hpp" -#include "math/math.hpp" +#include #include "vbo.hpp" namespace gfx::ogl{ - using namespace math; class vertex_attribute; diff --git a/include/gfx/ogl/window.hpp b/include/gfx/ogl/window.hpp index ceb4aac..3a0ab93 100644 --- a/include/gfx/ogl/window.hpp +++ b/include/gfx/ogl/window.hpp @@ -21,7 +21,7 @@ #include "gl_include.hpp" #include "../init.hpp" -#include "math/math.hpp" +#include #include "util/init_constants.hpp" namespace gfx::ogl{ @@ -69,12 +69,12 @@ namespace gfx::ogl{ void destroy(void); - void set_size(const math::vec2i&); + void set_size(const rml::vec2i&); void set_size(int w, int h); void set_width(int w); void set_height(int h); void set_title(const char* t); - void set_pos(const math::vec2i&); + void set_pos(const rml::vec2i&); void set_pos(int x, int y); void set_x(int x); void set_y(int y); @@ -95,20 +95,20 @@ namespace gfx::ogl{ void set_active(void); - math::vec2i get_size(void)const; + rml::vec2i get_size(void)const; int get_width(void)const; int get_height(void)const; - math::vec2i get_pos(void)const; + rml::vec2i get_pos(void)const; int get_posx(void)const; int get_posy(void)const; - math::vec2i get_context_version(void)const; + rml::vec2i get_context_version(void)const; int get_context_vmaj(void)const; int get_context_vmin(void)const; int get_swap_interval(void)const; - math::vec2d get_cursor_pos(void)const; + rml::vec2d get_cursor_pos(void)const; double get_cursor_posx(void)const; double get_cursor_posy(void)const; bool get_key(int key, int action)const; diff --git a/include/math/debug.hpp b/include/math/debug.hpp deleted file mode 100644 index 43124b1..0000000 --- a/include/math/debug.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef OUR_DICK_MATH_DEBUG_HPP -#define OUR_DICK_MATH_DEBUG_HPP - -#include //printf -#include //size_t - -#include "quat.hpp" -#include "mat.hpp" - -namespace math{ - namespace detail{ - static inline void print_integral(int i){ - printf("%d", i); - } - static inline void print_integral(float f){ - printf("%f", f); - } - static inline void print_double(double d){ - printf("%lf", d); - } - static inline void print_integral(unsigned int i){ - printf("%u", i); - } - static inline void print_integral(long int i){ - printf("%li", i); - } - static inline void print_integral(unsigned long int i){ - printf("%lu", i); - } - static inline void print_integral(long double d){ - printf("%Lf", d); - } - } - - //Debug - template - void dump_matrix(const matrix_base& mat){ - for(size_t i = 0;i < C;++i){ - for(size_t j = 0;j < R;++j){ - detail::print_integral(mat[i][j]); - printf(" "); - } - printf("\n"); - } - printf("\n"); - } - template - void dump_quaternion(const quaternion& q){ - for(size_t i = 0;i < 4;++i){ - detail::print_integral(q[i]); - printf(" "); - } - printf("\n"); - } -} - -#endif diff --git a/include/math/detail/matrix.hpp b/include/math/detail/matrix.hpp deleted file mode 100644 index abefc9f..0000000 --- a/include/math/detail/matrix.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_DETAIL_MATRIX_HPP -#define REXY_DETAIL_MATRIX_HPP - -#include //size_t -#include //integer_sequence -#include "../fwd_declare.hpp" - -namespace math::detail{ - - template - struct gen_id_tup { - using tup = typename gen_id_tup::tup; - }; - template - struct gen_id_tup { - using tup = typename gen_id_tup::tup; - }; - template - struct gen_id_tup { - using tup = typename gen_id_tup::tup; - }; - template - struct gen_id_tup { - using tup = std::integer_sequence; - }; - - - template - struct gen_zero_tup { - using tup = typename gen_zero_tup::tup; - }; - template - struct gen_zero_tup<0,Args...> { - using tup = std::integer_sequence; - }; - - template - struct id_initialization_matrix { - using tuple = typename gen_id_tup::tup; - }; - - - template - struct default_initialization_matrix { - using tuple = typename gen_zero_tup::tup; - }; - template - struct default_initialization_matrix { - using tuple = typename id_initialization_matrix::tuple; - }; - - template - class mat_ref_obj - { - public: - using size_type = size_t; - - protected: - T* m_data = nullptr; - public: - constexpr mat_ref_obj(T* d, size_type i); - constexpr T& operator[](size_type i); - constexpr const T& operator[](size_type i)const; - }; - template - struct determinate_helper { - static constexpr T perform(const matrix& m); - }; - template - struct determinate_helper { - static constexpr T perform(const matrix& m); - }; - template - struct determinate_helper { - static constexpr T perform(const matrix& m); - }; - - template - struct inverse_helper { - //TODO generalized inverse - }; - template - struct inverse_helper { - static constexpr matrix perform(const matrix& m); - }; - template - struct inverse_helper { - static constexpr matrix perform(const matrix& m); - }; - template - struct inverse_helper { - static constexpr matrix perform(const matrix& m); - }; - -} - -#include "matrix.tpp" - -#endif diff --git a/include/math/detail/matrix.tpp b/include/math/detail/matrix.tpp deleted file mode 100644 index f2c3c82..0000000 --- a/include/math/detail/matrix.tpp +++ /dev/null @@ -1,151 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_DETAIL_MATRIX_TPP -#define REXY_DETAIL_MATRIX_TPP - -#include //size_t -#include //integer_sequence - -namespace math::detail{ - - template - constexpr mat_ref_obj::mat_ref_obj(T* d, size_type i): - m_data(d+(i*R)){} - - template - constexpr T& mat_ref_obj::operator[](size_type i){ - return m_data[i]; - } - template - constexpr const T& mat_ref_obj::operator[](size_type i)const{ - return m_data[i]; - } - template - constexpr T determinate_helper::perform(const matrix& m){ - T sum = 0; - T op = 1; - for(size_t i = 0; i < R; ++i){ - T item = op * m[0][i]; - matrix mul(no_initialize); - for(size_t j = 1, mj = 0; j < R; ++j){ - for(size_t k = 0, mk = 0; k < R; ++k){ - if(k == i) - continue; - mul[mj][mk] = m[j][k]; - ++mk; - } - ++mj; - } - sum += item * determinate_helper::perform(mul); - op = -op; - } - return sum; - } - template - constexpr T determinate_helper::perform(const matrix& m){ - return (m.get(0) * ((m.get(4) * m.get(8)) - (m.get(5) * m.get(7))) - - m.get(1) * ((m.get(3) * m.get(8)) - (m.get(5) * m.get(6))) + - m.get(2) * ((m.get(3) * m.get(7)) - (m.get(4) * m.get(6)))); - } - template - constexpr T determinate_helper::perform(const matrix& m){ - return m.get(0) * m.get(3) - m.get(1) * m.get(2); - } - - template - constexpr matrix inverse_helper::perform(const matrix& m){ - T det = m.determinate(); - if(!det) - return matrix(zero_initialize); - return matrix(m.get(3) / det, -(m.get(1)) / det, -(m.get(2)) / det, m.get(0) / det); - } - template - constexpr matrix inverse_helper::perform(const matrix& m){ - T det = m.determinate(); - if(!det) - return matrix(zero_initialize); - return matrix(((m.get(4) * m.get(8)) - (m.get(5) * m.get(7))) / det, - -((m.get(1) * m.get(8)) - (m.get(2) * m.get(7))) / det, - ((m.get(1) * m.get(5)) - (m.get(2) * m.get(4))) / det, - -((m.get(3) * m.get(8)) - (m.get(5) * m.get(6))) / det, - ((m.get(0) * m.get(8)) - (m.get(2) * m.get(6))) / det, - -((m.get(0) * m.get(5)) - (m.get(2) * m.get(3))) / det, - ((m.get(3) * m.get(7)) - (m.get(4) * m.get(6))) / det, - -((m.get(0) * m.get(7)) - (m.get(1) * m.get(6))) / det, - ((m.get(0) * m.get(4)) - (m.get(1) * m.get(3))) / det); - } - template - constexpr matrix inverse_helper::perform(const matrix& m){ - //barely over 50 lines, can be made slightly shorter by making the return statement unreadable - T det = m.determinate(); - if(!det) - return matrix(zero_initialize); - return matrix((m.get(5) * ((m.get(10) * m.get(15)) - (m.get(11) * m.get(14))) - - m.get(6) * ((m.get(9) * m.get(15)) - (m.get(11) * m.get(13))) + - m.get(7) * ((m.get(9) * m.get(14)) - (m.get(10) * m.get(13)))) / det, - -(m.get(1) * ((m.get(10) * m.get(15)) - (m.get(11) * m.get(14))) - - m.get(2) * ((m.get(9) * m.get(15)) - (m.get(11) * m.get(13))) + - m.get(3) * ((m.get(9) * m.get(14)) - (m.get(10) * m.get(13)))) / det, - (m.get(1) * ((m.get(6) * m.get(15)) - (m.get(7) * m.get(14))) - - m.get(2) * ((m.get(5) * m.get(15)) - (m.get(7) * m.get(13))) + - m.get(3) * ((m.get(5) * m.get(14)) - (m.get(6) * m.get(13)))) / det, - -(m.get(1) * ((m.get(6) * m.get(11)) - (m.get(7) * m.get(10))) - - m.get(2) * ((m.get(5) * m.get(11)) - (m.get(7) * m.get(9))) + - m.get(3) * ((m.get(5) * m.get(10)) - (m.get(6) * m.get(9)))) / det, - -(m.get(4) * ((m.get(10) * m.get(15)) - (m.get(11) * m.get(14))) - - m.get(6) * ((m.get(8) * m.get(15)) - (m.get(11) * m.get(12))) + - m.get(7) * ((m.get(8) * m.get(14)) - (m.get(10) * m.get(12)))) / det, - (m.get(0) * ((m.get(10) * m.get(15)) - (m.get(11) * m.get(14))) - - m.get(2) * ((m.get(8) * m.get(15)) - (m.get(11) * m.get(12))) + - m.get(3) * ((m.get(8) * m.get(14)) - (m.get(10) * m.get(12)))) / det, - -(m.get(0) * ((m.get(6) * m.get(15)) - (m.get(7) * m.get(14))) - - m.get(2) * ((m.get(4) * m.get(15)) - (m.get(7) * m.get(12))) + - m.get(3) * ((m.get(4) * m.get(14)) - (m.get(6) * m.get(12)))) / det, - (m.get(0) * ((m.get(6) * m.get(11)) - (m.get(7) * m.get(10))) - - m.get(2) * ((m.get(4) * m.get(11)) - (m.get(7) * m.get(8))) + - m.get(3) * ((m.get(4) * m.get(10)) - (m.get(6) * m.get(8)))) / det, - (m.get(4) * ((m.get(9) * m.get(15)) - (m.get(11) * m.get(13))) - - m.get(5) * ((m.get(8) * m.get(15)) - (m.get(11) * m.get(12))) + - m.get(7) * ((m.get(8) * m.get(13)) - (m.get(9) * m.get(12)))) / det, - -(m.get(0) * ((m.get(9) * m.get(15)) - (m.get(11) * m.get(13))) - - m.get(1) * ((m.get(8) * m.get(15)) - (m.get(11) * m.get(12))) + - m.get(3) * ((m.get(8) * m.get(13)) - (m.get(9) * m.get(12)))) / det, - (m.get(0) * ((m.get(5) * m.get(15)) - (m.get(7) * m.get(13))) - - m.get(1) * ((m.get(4) * m.get(15)) - (m.get(7) * m.get(12))) + - m.get(3) * ((m.get(4) * m.get(13)) - (m.get(5) * m.get(12)))) / det, - -(m.get(0) * ((m.get(5) * m.get(11)) - (m.get(7) * m.get(9))) - - m.get(1) * ((m.get(4) * m.get(11)) - (m.get(7) * m.get(8))) + - m.get(3) * ((m.get(4) * m.get(9)) - (m.get(5) * m.get(8)))) / det, - -(m.get(4) * ((m.get(9) * m.get(14)) - (m.get(10) * m.get(13))) - - m.get(5) * ((m.get(8) * m.get(14)) - (m.get(10) * m.get(12))) + - m.get(6) * ((m.get(8) * m.get(13)) - (m.get(9) * m.get(12)))) / det, - (m.get(0) * ((m.get(9) * m.get(14)) - (m.get(10) * m.get(13))) - - m.get(1) * ((m.get(8) * m.get(14)) - (m.get(10) * m.get(12))) + - m.get(2) * ((m.get(8) * m.get(13)) - (m.get(9) * m.get(12)))) / det, - -(m.get(0) * ((m.get(5) * m.get(14)) - (m.get(6) * m.get(13))) - - m.get(1) * ((m.get(4) * m.get(14)) - (m.get(6) * m.get(12))) + - m.get(2) * ((m.get(4) * m.get(13)) - (m.get(5) * m.get(12)))) / det, - (m.get(0) * ((m.get(5) * m.get(10)) - (m.get(6) * m.get(9))) - - m.get(1) * ((m.get(4) * m.get(10)) - (m.get(6) * m.get(8))) + - m.get(2) * ((m.get(4) * m.get(9)) - (m.get(5) * m.get(8)))) / det); - } - -} - -#endif diff --git a/include/math/fwd_declare.hpp b/include/math/fwd_declare.hpp deleted file mode 100644 index d5f71b8..0000000 --- a/include/math/fwd_declare.hpp +++ /dev/null @@ -1,196 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_MATH_FWD_DECLARE_HPP -#define REXY_MATH_FWD_DECLARE_HPP - -#include //size_t -#include -#ifdef __cpp_lib_concepts -#include -namespace detail{ - template - concept convertible_to = std::convertible_to; -} -#else -namespace detail{ - template - concept convertible_to = std::is_convertible_v; -} -#endif - -//Provide aliases for common matrix, vector, and quaternion types - -namespace math{ - - //Must forward declare type traits for use in concepts because you can't forward declare concepts - template - struct is_vector; - template - struct is_quaternion; - template - struct is_matrix; - - //Create concepts that depend on the type traits - template - concept Quaternion = is_quaternion::value; - template - concept Matrix = is_matrix::value; - template - concept Vector = is_vector::value; - - template - concept Scalar = !Matrix && !Vector && !Quaternion && requires(std::decay_t t){ - {t += t} -> detail::convertible_to; - {t -= t} -> detail::convertible_to; - {t /= t} -> detail::convertible_to; - {t *= t} -> detail::convertible_to; - {t + t} -> detail::convertible_to>; - {t - t} -> detail::convertible_to>; - {t / t} -> detail::convertible_to>; - {t * t} -> detail::convertible_to>; - {-t} -> detail::convertible_to>; - {t > t} -> detail::convertible_to; - {t < t} -> detail::convertible_to; - {t >= t} -> detail::convertible_to; - {t <= t} -> detail::convertible_to; - {t == t} -> detail::convertible_to; - {t != t} -> detail::convertible_to; - }; - - template - class matrix_base; - - template - class matrix; - template - class vector; - template - class quaternion; - - template - using mat2 = matrix; - template - using mat3 = matrix; - template - using mat4 = matrix; - - template - using vec2 = vector; - template - using vec3 = vector; - template - using vec4 = vector; - - using vec2f = vec2; - using vec2i = vec2; - using vec2u = vec2; - using vec2d = vec2; - using vec2s = vec2; - using vec2b = vec2; - - using vec3f = vec3; - using vec3i = vec3; - using vec3u = vec3; - using vec3d = vec3; - using vec3s = vec3; - using vec3b = vec3; - - using vec4f = vec4; - using vec4i = vec4; - using vec4u = vec4; - using vec4d = vec4; - using vec4s = vec4; - using vec4b = vec4; - - using mat2f = mat2; - using mat2i = mat2; - using mat2u = mat2; - using mat2d = mat2; - using mat2s = mat2; - using mat2b = mat2; - - using mat3f = mat3; - using mat3i = mat3; - using mat3u = mat3; - using mat3d = mat3; - using mat3s = mat3; - - using mat4f = mat4; - using mat4i = mat4; - using mat4u = mat4; - using mat4d = mat4; - using mat4s = mat4; - using mat4b = mat4; - - template - using quat = quaternion; - - using quat_f = quat; - using quat_i = quat; - using quat_u = quat; - using quat_d = quat; - using quat_s = quat; - using quat_b = quat; - - namespace detail{ - - template - struct is_matrix_helper { - template - static std::true_type test(matrix_base*); - static std::false_type test(void*); - - static constexpr bool value = std::is_same*>(nullptr)))>::value; - }; - - template - struct is_quat_helper { - template - static std::true_type test(quaternion*); - static std::false_type test(void*); - static constexpr bool value = std::is_same*>(nullptr)))>::value; - }; - - template - struct is_vector_helper { - template - static std::true_type test(vector*); - static std::false_type test(void*); - - static constexpr bool value = std::is_same*>(nullptr)))>::value; - }; - - } - - template - struct is_vector{ - static constexpr bool value = (detail::is_vector_helper::value && ...); - }; - template - struct is_quaternion { - static constexpr bool value = (detail::is_quat_helper::value && ...); - }; - template - struct is_matrix { - static constexpr bool value = (detail::is_matrix_helper::value && ...); - }; - -} - -#endif diff --git a/include/math/mat.hpp b/include/math/mat.hpp deleted file mode 100644 index 161ec3e..0000000 --- a/include/math/mat.hpp +++ /dev/null @@ -1,243 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_MAT_HPP -#define REXY_MAT_HPP - -#include //size_t -#include //integer_sequence -#include //decay_t, is_same, integral_constant -#include "math_common.hpp" -#include "fwd_declare.hpp" -#include - -namespace math{ - - //Common stuff shared by all types of matrices - template - class matrix_base - { - static_assert(C > 0, "Cannot have 0 columns matrix"); - static_assert(R > 0, "Cannot have 0 rows matrix"); - public: - using value_type = T; - using size_type = size_t; - using pointer = value_type*; - using const_pointer = const value_type*; - using reference = value_type&; - using const_reference = const value_type&; - - static constexpr size_type Columns = C; - static constexpr size_type Rows = R; - - protected: - value_type m_data[R*C]; - - protected: - template - constexpr matrix_base(std::integer_sequence); - public: - //Default construct as identity when square, zero otherwise - constexpr matrix_base(void); - - //Range initializing constructors - constexpr explicit matrix_base(detail::zero_initialize_t); - constexpr explicit matrix_base(detail::no_initialize_t); - - //Value initializing constructors - constexpr explicit matrix_base(value_type v); - template && ...),int> = 0> - constexpr matrix_base(Args&&... args); - - //Copying constructors - constexpr matrix_base(const matrix_base&) = default; - constexpr matrix_base(matrix_base&&) = default; - template - constexpr matrix_base(const matrix_base& m); - ~matrix_base(void) = default; - - constexpr matrix_base& operator=(const matrix_base&) = default; - constexpr matrix_base& operator=(matrix_base&&) = default; - template - constexpr matrix_base& operator=(const matrix_base& m); - - //Getters/Setters - constexpr auto operator[](size_type x); - constexpr auto operator[](size_type x)const; - constexpr reference get(size_type x, size_type y); - constexpr const_reference get(size_type x, size_type y)const; - constexpr reference get(size_type i); - constexpr const_reference get(size_type i)const; - - constexpr size_type columns(void)const; - constexpr size_type rows(void)const; - constexpr size_type size(void)const; - - constexpr pointer raw(void); - constexpr const_pointer raw(void)const; - constexpr operator pointer(void); - constexpr operator const_pointer(void)const; - }; - - //Non square matrices - template - class matrix : public matrix_base - { - private: - using base = matrix_base; - public: - using value_type = typename base::value_type; - using size_type = typename base::size_type; - using pointer = typename base::pointer; - using const_pointer = typename base::const_pointer; - using reference = typename base::reference; - using const_reference = typename base::const_reference; - - public: - using base::base; - - template = 0> - constexpr matrix(const matrix_base& other); - template - constexpr matrix(const matrix& other); - constexpr matrix(const matrix&) = default; - constexpr matrix(matrix&&) = default; - ~matrix(void) = default; - - //Assignement - constexpr matrix& operator=(const matrix&) = default; - constexpr matrix& operator=(matrix&&) = default; - template - constexpr matrix& operator=(const matrix& m); - }; - - //Square matrices - template - class matrix : public matrix_base - { - private: - using base = matrix_base; - public: - using value_type = typename base::value_type; - using size_type = typename base::size_type; - using pointer = typename base::pointer; - using const_pointer = typename base::const_pointer; - using reference = typename base::reference; - using const_reference = typename base::const_reference; - - public: - using base::base; - - constexpr matrix(const matrix&) = default; - constexpr matrix(matrix&&) = default; - constexpr explicit matrix(detail::id_initialize_t); - template = 0> - constexpr matrix(const matrix_base& other); - template - constexpr matrix(const matrix& other); - ~matrix(void) = default; - - //Assignement - constexpr matrix& operator=(const matrix&) = default; - constexpr matrix& operator=(matrix&&) = default; - template - constexpr matrix& operator=(const matrix& m); - - //square matrix arithmetic operations - constexpr value_type determinate(void)const; - constexpr value_type trace(void)const; - constexpr matrix transpose(void)const; - constexpr matrix inverse(void)const; - }; - - template - constexpr T determinate(const matrix& m); - template - constexpr matrix inverse(const matrix& m); - - template - matrix rotation2d_pure(T angle); - template - constexpr matrix rotation2d_pure(T sin, T cos); - template - constexpr matrix scale2d(T x, T y); - - template - matrix rotation2d(T angle); - template - constexpr matrix rotation2d(T sin, T cos); - template - matrix rotation2d(T x, T y, T z); - - template - constexpr matrix rotation3d(T angle_x, T angle_y, T angle_z); - template - constexpr matrix translation3d(T x, T y, T z); - template - constexpr matrix scale3d(T x, T y, T z); - - //Logic operators - template - constexpr bool operator==(const matrix_base& left, const matrix_base right); - template - constexpr bool operator!=(const matrix_base& left, const matrix_base right); - - //Arithmetic operators - template - constexpr auto operator*(const matrix& left, const matrix& right); - template - constexpr auto operator*(const matrix& left, U&& right); - template - constexpr auto operator*(U&& left, const matrix& right); - template - constexpr auto operator/(const matrix& left, U&& right); - template - constexpr auto operator+(const matrix& left, const matrix& right); - template - constexpr auto operator-(const matrix& left, const matrix& right); - template - constexpr auto operator-(const matrix& left); - - template - constexpr auto abs(const matrix_base& left); - template - constexpr bool fuzzy_eq(const matrix_base& left, const matrix_base& right, const V& epsilon); - template - constexpr bool fuzzy_neq(const matrix_base& left, const matrix_base& right, const V& epsilon); - - //Arithmetic assignment operators - template - constexpr decltype(auto) operator*=(matrix& left, const matrix& right); - template - constexpr decltype(auto) operator*=(matrix& left, U&& right); - template - constexpr decltype(auto) operator/=(matrix& left, U&& right); - template - constexpr decltype(auto) operator+=(matrix& left, const matrix& right); - template - constexpr decltype(auto) operator-=(matrix& left, const matrix& right); - - extern template class matrix; - extern template class matrix; - extern template class matrix; - -} - -#include "mat.tpp" - -#endif diff --git a/include/math/mat.tpp b/include/math/mat.tpp deleted file mode 100644 index 615c140..0000000 --- a/include/math/mat.tpp +++ /dev/null @@ -1,424 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_MAT_TPP -#define REXY_MAT_TPP - -#include //size_t -#include //sin, cos, abs -#include //decay_t, declval -#include "detail/matrix.hpp" -#include "quat.hpp" - -namespace math{ - - namespace detail{ - template - static constexpr const T& min(const T& l, const T& r){ - return l < r ? l : r; - } - } - - template - template - constexpr matrix_base::matrix_base(std::integer_sequence): - m_data{Ss...}{} - - template - constexpr matrix_base::matrix_base(void): - matrix_base(typename detail::default_initialization_matrix::tuple{}){} - - template - constexpr matrix_base::matrix_base(detail::zero_initialize_t): - m_data{}{} - template - constexpr matrix_base::matrix_base(detail::no_initialize_t){} - - template - constexpr matrix_base::matrix_base(value_type v){ - for(size_type i = 0; i < Columns*Rows; ++i) - m_data[i] = v; - } - template - template && ...),int>> - constexpr matrix_base::matrix_base(Args&&... args): - m_data{static_cast(std::forward(args))...}{} - - template - template - constexpr matrix_base::matrix_base(const matrix_base& m){ - using mat = matrix_base; - for(typename mat::size_type i = 0; i < mat::Columns*mat::Rows; ++i) - m_data[i] = m.get(i); - } - - template - template - constexpr matrix_base& matrix_base::operator=(const matrix_base& m){ - constexpr auto cols = detail::min(TC, C); - constexpr auto rws = detail::min(TR, R); - for(size_type i = 0;i < cols;++i){ - for(size_type j = 0;j < rws;++j){ - get(i, j) = m.get(i, j); - } - } - return *this; - } - - - template - constexpr auto matrix_base::operator[](size_type x){ - return detail::mat_ref_obj{m_data, x}; - } - template - constexpr auto matrix_base::operator[](size_type x)const{ - return detail::mat_ref_obj{m_data, x}; - } - template - constexpr auto matrix_base::get(size_type x, size_type y) -> reference{ - return m_data[(x*Rows)+y]; - } - template - constexpr auto matrix_base::get(size_type x, size_type y)const -> const_reference{ - return m_data[(x*Rows)+y]; - } - template - constexpr auto matrix_base::get(size_type i) -> reference{ - return m_data[i]; - } - template - constexpr auto matrix_base::get(size_type i)const -> const_reference{ - return m_data[i]; - } - - template - constexpr auto matrix_base::columns(void)const -> size_type{ - return Columns; - } - template - constexpr auto matrix_base::rows(void)const -> size_type{ - return Rows; - } - template - constexpr auto matrix_base::size(void)const -> size_type{ - return Columns*Rows; - } - - template - constexpr auto matrix_base::raw(void) -> pointer{ - return m_data; - } - template - constexpr auto matrix_base::raw(void)const -> const_pointer{ - return m_data; - } - template - constexpr matrix_base::operator pointer(void){ - return m_data; - } - template - constexpr matrix_base::operator const_pointer(void)const{ - return m_data; - } - - template - template> - constexpr matrix::matrix(const matrix_base& other){ - for(size_type i = 0;i < TC;++i){ - for(size_type j = 0;j < TR;++j){ - get(i, j) = other.get(i, j); - } - } - } - template - template - constexpr matrix::matrix(const matrix& other){ - for(size_type i = 0;i < C;++i){ - for(size_type j = 0;j < R;++j){ - get(i, j) = other.get(i, j); - } - } - } - - template - template - constexpr matrix& matrix::operator=(const matrix& m){ - base::operator=(m); - return *this; - } - - template - constexpr matrix::matrix(detail::id_initialize_t): - base(){} - template - template> - constexpr matrix::matrix(const matrix_base& other): - matrix(id_initialize) - { - for(size_type i = 0;i < TC;++i){ - for(size_type j = 0;j < TR;++j){ - get(i, j) = other.get(i, j); - } - } - } - template - template - constexpr matrix::matrix(const matrix& other){ - for(size_type i = 0;i < R;++i){ - for(size_type j = 0;j < R;++j){ - get(i, j) = other.get(i, j); - } - } - } - - - template - template - constexpr matrix& matrix::operator=(const matrix& m){ - base::operator=(m); - return *this; - } - - template - constexpr auto matrix::determinate(void)const -> value_type{ - return math::determinate(*this); - } - template - constexpr auto matrix::trace(void)const -> value_type{ - value_type sum = 0; - for(size_type i = 0; i < R; ++i){ - sum += this->get(i, i); - } - return sum; - } - template - constexpr matrix matrix::transpose(void)const{ - matrix m(no_initialize); - for(size_type i = 0; i < R; ++i){ - for(size_type j = 0; j < R; ++j){ - m.get(j, i) = this->get(i, j); - } - } - return m; - } - template - constexpr matrix matrix::inverse(void)const{ - return math::inverse(*this); - } - - - template - constexpr T determinate(const matrix& m){ - return detail::determinate_helper::perform(m); - } - template - constexpr matrix inverse(const matrix& m){ - return detail::inverse_helper::perform(m); - } - - template - matrix rotation2d_pure(T angle){ - return rotation2d_pure(std::sin(angle), std::cos(angle)); - } - template - constexpr matrix rotation2d_pure(T sin, T cos){ - return matrix(cos, sin, -sin, cos); - } - template - constexpr matrix scale2d(T x, T y){ - return matrix(x, T{0}, T{0}, y); - } - - template - matrix rotation2d(T angle){ - return rotation2d(std::sin(angle), std::cos(angle)); - } - template - constexpr matrix rotation2d(T sin, T cos){ - return matrix(cos, -sin, T{0}, - sin, cos, T{0}, - T{0}, T{0}, T{1}); - } - template - matrix rotation2d(T x, T y, T z){ - quaternion q(x, y, z); - return q.to_mat3(); - } - - template - constexpr matrix rotation3d(T angle_x, T angle_y, T angle_z){ - quaternion q(angle_x, angle_y, angle_z); - return q.to_mat4(); - } - template - constexpr matrix translation3d(T x, T y, T z){ - return matrix(T{1}, T{0}, T{0}, T{0}, - T{0}, T{1}, T{0}, T{0}, - T{0}, T{0}, T{1}, T{0}, - x, y, z, T{1}); - } - template - constexpr matrix scale3d(T x, T y, T z){ - return matrix(x, T{0}, T{0}, T{0}, - T{0}, y, T{0}, T{0}, - T{0}, T{0}, z, T{0}, - T{0}, T{0}, T{0}, T{1}); - } - - - template - constexpr bool operator==(const matrix_base& left, const matrix_base right){ - for(size_t i = 0; i < left.size(); ++i){ - if(left.get(i) != right.get(i)) - return false; - } - return true; - } - template - constexpr bool operator!=(const matrix_base& left, const matrix_base right){ - return !(left == right); - } - - template - constexpr auto operator*(const matrix& left, const matrix& right){ - using res_t = decltype(std::declval() * std::declval()); - matrix res(zero_initialize); - size_t index = 0; - for(size_t i = 0; i < right.rows(); ++i){ - for(size_t j = 0; j < left.columns(); ++j){ - for(size_t k = 0; k < left.rows(); ++k){ - res.get(index) += right.get(i, k) * left.get(k, j); - } - ++index; - } - } - return res; - } - template - constexpr auto operator*(const matrix& left, U&& right){ - using res_t = decltype(std::declval() * std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = left.get(i) * std::forward(right); - } - return res; - } - template - constexpr auto operator*(U&& left, const matrix& right){ - using res_t = decltype(std::declval() * std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < right.size(); ++i){ - res.get(i) = std::forward(left) * right.get(i); - } - return res; - } - template - constexpr auto operator/(const matrix& left, U&& right){ - using res_t = decltype(std::declval() / std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = left.get(i) / std::forward(right); - } - return res; - } - template - constexpr auto operator+(const matrix& left, const matrix& right){ - using res_t = decltype(std::declval() + std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = left.get(i) + right.get(i); - } - return res; - } - template - constexpr auto operator-(const matrix& left, const matrix& right){ - using res_t = decltype(std::declval() - std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = left.get(i) - right.get(i); - } - return res; - } - template - constexpr auto operator-(const matrix& left){ - using res_t = decltype(-std::declval()); - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = -left.get(i); - } - return res; - } - template - constexpr auto abs(const matrix_base& left){ - matrix res(no_initialize); - for(size_t i = 0; i < left.size(); ++i){ - res.get(i) = std::abs(left.get(i)); - } - return res; - } - template - constexpr bool fuzzy_eq(const matrix_base& left, const matrix_base& right, const V& epsilon){ - for(size_t i = 0;i < left.size();++i){ - if(std::abs(left.get(i) - right.get(i)) > epsilon) - return false; - } - return true; - } - template - constexpr bool fuzzy_neq(const matrix_base& left, const matrix_base& right, const V& epsilon){ - return !fuzzy_eq(left, right, epsilon); - } - - template - constexpr decltype(auto) operator*=(matrix& left, const matrix& right){ - //have to evaluate entire expression first since matrix multiplication depends on reusing many elements - //cannot be expression templatized, TODO - return (left = (left * right)); - } - template - constexpr decltype(auto) operator*=(matrix& left, U&& right){ - for(size_t i = 0; i < left.size(); ++i){ - left.get(i) = left.get(i) * std::forward(right); - } - return left; - } - template - constexpr decltype(auto) operator/=(matrix& left, U&& right){ - for(size_t i = 0; i < left.size(); ++i){ - left.get(i) = left.get(i) / std::forward(right); - } - return left; - } - template - constexpr decltype(auto) operator+=(matrix& left, const matrix& right){ - for(size_t i = 0; i < left.size(); ++i){ - left.get(i) = left.get(i) + right.get(i); - } - return left; - } - template - constexpr decltype(auto) operator-=(matrix& left, const matrix& right){ - for(size_t i = 0; i < left.size(); ++i){ - left.get(i) = left.get(i) - right.get(i); - } - return left; - } - -} - -#endif diff --git a/include/math/math.hpp b/include/math/math.hpp deleted file mode 100644 index 8c35a0c..0000000 --- a/include/math/math.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_MATH_HPP -#define REXY_MATH_HPP - -//include this file to access all the math components easily - -#include "fwd_declare.hpp" -#include "math_common.hpp" -#include "vec.hpp" -#include "mat.hpp" -#include "quat.hpp" -#include "projection.hpp" - -#endif diff --git a/include/math/math_common.hpp b/include/math/math_common.hpp deleted file mode 100644 index 5d95461..0000000 --- a/include/math/math_common.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_DETAIL_MATH_HPP -#define REXY_DETAIL_MATH_HPP - -#include "fwd_declare.hpp" - -namespace math{ - - namespace detail{ - //sentinel classes saying how to initialize some math classes - struct zero_initialize_t {}; - struct no_initialize_t {}; - struct id_initialize_t {}; - struct manual_initialize_t {}; - } - - //instantiation of sentinels - static inline constexpr detail::zero_initialize_t zero_initialize; - static inline constexpr detail::no_initialize_t no_initialize; - static inline constexpr detail::id_initialize_t id_initialize; - static inline constexpr detail::manual_initialize_t manual_initialize; - - template - static constexpr T pi(void){ - return static_cast(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821); - } - template - static constexpr T to_degrees(T t){ - return (t * 180.0) / pi(); - } - template - static constexpr T to_radians(T t){ - return (t * pi()) / 180.0; - } - - template - static constexpr T clamp(const T& t, const T& min, const T& max){ - if(t < min) - return min; - if(t > max) - return max; - return t; - } - template - static constexpr T clamp_min(const T& t, const T& min){ - if(t < min) - return min; - return t; - } - template - static constexpr T clamp_max(const T& t, const T& max){ - if(t > max) - return max; - return t; - } - -} -constexpr long double operator"" _rad(long double f){ - return f; -} -constexpr long double operator"" _deg(long double f){ - return math::to_radians(f); -} - - -#endif diff --git a/include/math/projection.hpp b/include/math/projection.hpp deleted file mode 100644 index d5c44a2..0000000 --- a/include/math/projection.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef OUR_DICK_MATH_PROJECTION_HPP -#define OUR_DICK_MATH_PROJECTION_HPP - -#include "mat.hpp" -#include "vec.hpp" -#include "math_common.hpp" - -namespace math{ - - template - matrix fov_projection(T fov, T asp, T near, T far); - template - matrix fov_asymetric_projection(T fovl, T fovr, T fovb, T fovt, T asp, T near, T far); - template - matrix ortho_projection(T w, T h, T n, T f); - template - matrix ortho_asymetric_projection(T l, T r, T b, T t, T n, T f); - - template - vec3 project(const mat4& viewproj_mat, const vec3& world_coords, const vec4& viewport); - template - vec3 unproject(const mat4& viewproj_mat, const vec3& viewport_coords, const vec4& viewport); - -} - -#include "projection.tpp" - -#endif diff --git a/include/math/projection.tpp b/include/math/projection.tpp deleted file mode 100644 index 81c9d3f..0000000 --- a/include/math/projection.tpp +++ /dev/null @@ -1,98 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef OUR_DICK_MATH_PROJECTION_TPP -#define OUR_DICK_MATH_PROJECTION_TPP - -#include "mat.hpp" -#include "vec.hpp" -#include //sin, cos, tan - -namespace math{ - - template - matrix fov_projection(T fov, T asp, T near, T far){ - T r = near * std::tan(fov / T{2.0}); - return matrix((near / r) / asp, T{0}, T{0}, T{0}, - T{0}, (near / r), T{0}, T{0}, - T{0}, T{0}, (far + near) / (near - far), -T{1}, - T{0}, T{0}, (T{2} * near * far) / (near - far), T{0}); - } - template - matrix fov_asymetric_projection(T fovl, T fovr, T fovb, T fovt, T asp, T n, T f){ - T l = n * std::tan(fovl); - T r = n * std::tan(fovr); - T b = n * std::tan(fovb); - T t = n * std::tan(fovt); - - return matrix(((T{2} * n) / (r - l)) * asp, T{0}, T{0}, T{0}, - T{0}, (T{2} * n) / (t - b), T{0}, T{0}, - (r + l) / (r - l), (t + b) / (t - b), (f + n) / (n - f), -T{1}, - T{0}, T{0}, (T{2} * n * f) / (n - f), T{0}); - } - template - matrix ortho_projection(T w, T h, T n, T f){ - return matrix(T{2} / w, T{0}, T{0}, T{0}, - T{0}, T{2} / h, T{0}, T{0}, - T{0}, T{0}, T{1} / (n - f), T{0}, - T{0}, T{0}, (n + f) / (n - f), T{1}); - } - template - matrix ortho_asymetric_projection(T l, T r, T b, T t, T n, T f){ - return matrix(T{2} / (r - l), T{0}, T{0}, T{0}, - T{0}, T{2} / (t - b), T{0}, T{0}, - T{0}, T{0}, T{1} / (n - f), T{0}, - (r + l) / (l - r), (t + b) / (b - t), (n + f) / (n - f), T{1}); - } - - template - vec3 project(const mat4& viewproj_mat, const vec3& w_coords, const vec4& viewport){ - //project world coordinates to ndc coordinates - vec4 world_coords{w_coords[0], w_coords[1], w_coords[2], T{1.0}}; - vec4 ndc_coords = viewproj_mat * world_coords; - - //perspective_division - ndc_coords /= ndc_coords[3]; - - //project ndc coordinates to viewport coordinates - return vec3{((ndc_coords[0] + T{1.0}) * viewport[2] * T{0.5}) + viewport[0], - ((ndc_coords[1] + T{1.0}) * viewport[3] * T{0.5}) + viewport[1], - ndc_coords[2] - }; - } - template - vec3 unproject(const mat4& viewproj_mat, const vec3& viewport_coords, const vec4& viewport){ - //project viewport coordinates to ndc coordinates - vec4 ndc_coords{((viewport_coords[0] - viewport[0]) * T{2.0} / viewport[2]) - T{1.0}, - ((viewport_coords[1] - viewport[1]) * T{2.0} / viewport[3]) - T{1.0}, - viewport_coords[2], - T{1.0}}; - - //project ndc coordinates to world coordinates - mat4 inv_viewproj_mat = viewproj_mat.inverse(); - vec4 world_coords = inv_viewproj_mat * ndc_coords; - - //perspective division - world_coords /= world_coords[3]; - - return {world_coords[0], world_coords[1], world_coords[2]}; - } - -} - -#endif diff --git a/include/math/quat.hpp b/include/math/quat.hpp deleted file mode 100644 index 2cbf8f8..0000000 --- a/include/math/quat.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_QUAT_HPP -#define REXY_QUAT_HPP - -#include //size_t -#include //pair -#include //is_same, is_arithmetic, integral_constant - -#include "math_common.hpp" -#include "fwd_declare.hpp" - -namespace math{ - - //( ͡° ͜ʖ ͡°) - template - class quaternion - { - public: - using value_type = T; - using size_type = size_t; - using pointer = value_type*; - using const_pointer = const value_type*; - using reference = value_type&; - using const_reference = const value_type&; - - private: - value_type m_data[4]; - - public: - constexpr quaternion(void); - //Construct from Euler angles - constexpr quaternion(detail::zero_initialize_t); - constexpr quaternion(detail::id_initialize_t); - constexpr quaternion(detail::no_initialize_t); - constexpr quaternion(detail::manual_initialize_t, - value_type w, value_type x, - value_type y, value_type z); - quaternion(const mat3& rotmat); - quaternion(const mat4& rotmat); - quaternion(value_type bank, value_type heading, value_type attitude); - quaternion(const vec3& angles); - //Construct from axis-angle - quaternion(value_type angle, const vec3& axis); - quaternion(value_type angle, value_type x, value_type y, value_type z); - //Copy ctor - constexpr quaternion(const quaternion&) = default; - constexpr quaternion(quaternion&&) = default; - ~quaternion(void) = default; - - //Assignment - constexpr quaternion& operator=(const quaternion&) = default; - constexpr quaternion& operator=(quaternion&&) = default; - - //Direct array access - constexpr operator pointer(void); - constexpr operator const_pointer(void)const; - constexpr reference operator[](size_type i); - constexpr const_reference operator[](size_type i)const; - constexpr reference get(size_type i); - constexpr const_reference get(size_type i)const; - - constexpr reference w(void); - constexpr const_reference w(void)const; - constexpr reference x(void); - constexpr const_reference x(void)const; - constexpr reference y(void); - constexpr const_reference y(void)const; - constexpr reference z(void); - constexpr const_reference z(void)const; - - //Assign axis from angle-axis - void set_axis(value_type x, value_type y, value_type z); - void set_axis(const vec3& axis); - vec3 get_axis(void)const; - - void set_angle(value_type a); - value_type get_angle(void)const; - value_type norm(void)const; - quaternion conjugate(void)const; - quaternion inverse(void)const; - value_type magnitude(void)const; - quaternion normalize(void)const; - - vec3 get_right(void)const; - vec3 get_up(void)const; - vec3 get_forward(void)const; - - //Explicit Conversion1 - vec3 to_vec3(void)const; - vec4 to_vec4(void)const; - mat3 to_mat3(void)const; - mat4 to_mat4(void)const; - vec3 to_euler_angles(void)const; - std::pair> to_axis_angle(void)const; - }; - - template - bool operator==(const quaternion& left, const quaternion& right); - template - bool operator!=(const quaternion& left, const quaternion& right); - template - auto operator-(const quaternion& left); - template - auto operator-(const quaternion& left, const quaternion& right); - template - auto operator+(const quaternion& left, const quaternion& right); - template - auto operator*(const quaternion& left, const quaternion& right); - template - auto operator*(const quaternion& left, const vec3& right); - template - auto operator*(const quaternion& left, U&& right); - template - auto operator/(const quaternion& left, U&& right); - - template - decltype(auto) operator+=(quaternion& left, const quaternion& right); - template - decltype(auto) operator-=(quaternion& left, const quaternion& right); - template - decltype(auto) operator*=(quaternion& left, const quaternion& right); - template - decltype(auto) operator*=(quaternion& left, U&& right); - template - decltype(auto) operator/=(quaternion& left, U&& right); - - extern template class quaternion; -} - -#include "quat.tpp" - -#endif diff --git a/include/math/quat.tpp b/include/math/quat.tpp deleted file mode 100644 index 29674a3..0000000 --- a/include/math/quat.tpp +++ /dev/null @@ -1,437 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_QUAT_TPP -#define REXY_QUAT_TPP - -#include //sin, cos, tan, sqrt, etc -#include "mat.hpp" -#include "vec.hpp" - -namespace math{ - - template - constexpr quaternion::quaternion(void): - quaternion(id_initialize){} - template - constexpr quaternion::quaternion(detail::zero_initialize_t): - m_data{0, 0, 0, 0}{} - template - constexpr quaternion::quaternion(detail::id_initialize_t): - m_data{1, 0, 0, 0}{} - template - constexpr quaternion::quaternion(detail::no_initialize_t){} - - template - constexpr quaternion::quaternion(detail::manual_initialize_t, - value_type w, value_type x, - value_type y, value_type z): - m_data{w, x, y, z}{} - - template - quaternion::quaternion(const mat3& rotmat){ - auto tr = rotmat.trace(); - if(tr > 0){ - auto f = 0.5 / sqrt(tr + 1.0); - m_data[0] = 0.25 / f; - m_data[1] = (rotmat.get(5) - rotmat.get(7)) * f; - m_data[2] = (rotmat.get(6) - rotmat.get(2)) * f; - m_data[3] = (rotmat.get(1) - rotmat.get(3)) * f; - }else if((rotmat.get(0) > rotmat.get(4)) && (rotmat.get(0) > rotmat.get(8))){ - auto f = sqrt(1.0 + rotmat.get(0) - rotmat.get(4) - rotmat.get(8)) * 2.0; - m_data[0] = (rotmat.get(5) - rotmat.get(7)) / f; - m_data[1] = f * 0.25; - m_data[2] = (rotmat.get(3) + rotmat.get(1)) / f; - m_data[3] = (rotmat.get(6) + rotmat.get(2)) / f; - }else if(rotmat.get(4) > rotmat.get(8)){ - auto f = sqrt(1.0 + rotmat.get(4) - rotmat.get(0) - rotmat.get(8)) * 2.0; - m_data[0] = (rotmat.get(6) - rotmat.get(2)) / f; - m_data[1] = (rotmat.get(3) + rotmat.get(1)) / f; - m_data[2] = f * 0.25; - m_data[3] = (rotmat.get(7) + rotmat.get(5)) / f; - }else{ - auto f = sqrt(1.0 + rotmat.get(8) - rotmat.get(0) - rotmat.get(4)) * 2.0; - m_data[0] = (rotmat.get(1) - rotmat.get(3)) / f; - m_data[1] = (rotmat.get(6) + rotmat.get(2)) / f; - m_data[2] = (rotmat.get(7) + rotmat.get(5)) / f; - m_data[3] = f * 0.25; - } - } - template - quaternion::quaternion(const mat4& rotmat): - quaternion(mat3{rotmat.get(0), rotmat.get(1), rotmat.get(2), - rotmat.get(4), rotmat.get(5), rotmat.get(6), - rotmat.get(8), rotmat.get(9), rotmat.get(10)}){} - template - quaternion::quaternion(value_type bank, value_type heading, value_type attitude){ - bank /= value_type{2}; - heading /= value_type{2}; - attitude /= value_type{2}; - value_type cos_heading = std::cos(heading); - value_type sin_heading = std::sin(heading); - value_type cos_attitude = std::cos(attitude); - value_type sin_attitude = std::sin(attitude); - value_type cos_bank = std::cos(bank); - value_type sin_bank = std::sin(bank); - - m_data[0] = (cos_heading * cos_attitude * cos_bank) - (sin_heading * sin_attitude * sin_bank); - m_data[1] = (sin_heading * sin_attitude * cos_bank) + (cos_heading * cos_attitude * sin_bank); - m_data[2] = (sin_heading * cos_attitude * cos_bank) + (cos_heading * sin_attitude * sin_bank); - m_data[3] = (cos_heading * sin_attitude * cos_bank) - (sin_heading * cos_attitude * sin_bank); - } - template - quaternion::quaternion(const vec3& angles): - quaternion(angles.x(), angles.y(), angles.z()){} - template - quaternion::quaternion(value_type angle, const vec3& axis): - quaternion(angle, axis.x(), axis.y(), axis.z()){} - template - quaternion::quaternion(value_type angle, value_type x, value_type y, value_type z){ - angle /= value_type{2.0}; - value_type sin_angle = std::sin(angle); - m_data[0] = std::cos(angle); - m_data[1] = sin_angle * x; - m_data[2] = sin_angle * y; - m_data[3] = sin_angle * z; - } - - template - constexpr quaternion::operator pointer(void){ - return m_data; - } - template - constexpr quaternion::operator const_pointer(void)const{ - return m_data; - } - template - constexpr auto quaternion::operator[](size_type i) -> reference{ - return m_data[i]; - } - template - constexpr auto quaternion::operator[](size_type i)const -> const_reference{ - return m_data[i]; - } - template - constexpr auto quaternion::get(size_type i) -> reference{ - return m_data[i]; - } - template - constexpr auto quaternion::get(size_type i)const -> const_reference{ - return m_data[i]; - } - template - constexpr auto quaternion::w(void) -> reference{ - return m_data[0]; - } - template - constexpr auto quaternion::w(void)const -> const_reference{ - return m_data[0]; - } - template - constexpr auto quaternion::x(void) -> reference{ - return m_data[1]; - } - template - constexpr auto quaternion::x(void)const -> const_reference{ - return m_data[1]; - } - template - constexpr auto quaternion::y(void) -> reference{ - return m_data[2]; - } - template - constexpr auto quaternion::y(void)const -> const_reference{ - return m_data[2]; - } - template - constexpr auto quaternion::z(void) -> reference{ - return m_data[3]; - } - template - constexpr auto quaternion::z(void)const -> const_reference{ - return m_data[3]; - } - template - void quaternion::set_axis(value_type x, value_type y, value_type z){ - value_type sin_angle = std::sin(std::acos(m_data[0])); - m_data[1] = sin_angle * x; - m_data[2] = sin_angle * y; - m_data[3] = sin_angle * z; - } - template - void quaternion::set_axis(const vec3& v){ - set_axis(v.x(), v.y(), v.z()); - } - template - auto quaternion::get_axis(void)const -> vec3{ - quaternion tmp(*this); - if(m_data[0] > value_type{1.0}) - tmp = tmp.normalize(); - value_type s = std::sqrt(1 - tmp.m_data[0] * tmp.m_data[0]); - if(s <= value_type{0.001}) - return vec3(1, 0, 0); - return vec3(tmp.m_data[1] / s, tmp.m_data[2] / s, tmp.m_data[3] / s); - } - template - void quaternion::set_angle(value_type t){ - t /= value_type{2.0}; - value_type old_sin_angle = std::sin(std::acos(m_data[0])); - value_type sin_angle = std::sin(t); - m_data[0] = std::cos(t); - m_data[1] = (m_data[1] / old_sin_angle) * sin_angle; - m_data[2] = (m_data[2] / old_sin_angle) * sin_angle; - m_data[3] = (m_data[3] / old_sin_angle) * sin_angle; - } - template - auto quaternion::get_angle(void)const -> value_type{ - return 2.0 * std::acos(m_data[0]); - } - template - auto quaternion::norm(void)const -> value_type{ - return m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; - } - template - quaternion quaternion::conjugate(void)const{ - return quaternion(manual_initialize, m_data[0], -m_data[1], -m_data[2], -m_data[3]); - } - template - quaternion quaternion::inverse(void)const{ - return conjugate() / norm(); - } - template - auto quaternion::magnitude(void)const -> value_type{ - return std::sqrt(norm()); - } - template - quaternion quaternion::normalize(void)const{ - value_type mag = magnitude(); - return quaternion(manual_initialize, m_data[0] / mag, m_data[1] / mag, m_data[2] / mag, m_data[3] / mag); - } - template - auto quaternion::get_right(void)const -> vec3{ - return vec3(1 - 2 * ((m_data[2] * m_data[2]) + (m_data[3] * m_data[3])), - 2 * ((m_data[1] * m_data[2]) - (m_data[3] * m_data[0])), - 2 * ((m_data[1] * m_data[3]) + (m_data[2] * m_data[0]))); - } - template - auto quaternion::get_up(void)const -> vec3{ - return vec3( 2 * ((m_data[1] * m_data[2]) + (m_data[3] * m_data[0])), - 1 - 2 * ((m_data[1] * m_data[1]) + (m_data[3] * m_data[3])), - 2 * ((m_data[2] * m_data[3]) - (m_data[1] * m_data[0]))); - } - template - auto quaternion::get_forward(void)const -> vec3{ - return vec3( 2 * ((m_data[1] * m_data[3]) - (m_data[2] * m_data[0])), - 2 * ((m_data[2] * m_data[3]) + (m_data[1] * m_data[0])), - 1 - 2 * ((m_data[1] * m_data[1]) + (m_data[2] * m_data[2]))); - } - template - auto quaternion::to_vec3(void)const -> vec3{ - return vec3(m_data[1], m_data[2], m_data[3]); - } - template - auto quaternion::to_vec4(void)const -> vec4{ - return vec4(m_data[1], m_data[2], m_data[3]); - } - template - auto quaternion::to_mat3(void)const -> mat3{ - mat3 m; - - value_type xx = m_data[1] * m_data[1]; - value_type yy = m_data[2] * m_data[2]; - value_type zz = m_data[3] * m_data[3]; - - value_type xy = m_data[1] * m_data[2]; - value_type xz = m_data[1] * m_data[3]; - value_type xw = m_data[1] * m_data[0]; - value_type yz = m_data[2] * m_data[3]; - value_type yw = m_data[2] * m_data[0]; - value_type zw = m_data[3] * m_data[0]; - - m.get(0) = 1 - 2 * (yy + zz); - m.get(1) = 2 * (xy + zw); - m.get(2) = 2 * (xz - yw); - m.get(3) = 2 * (xy - zw); - m.get(4) = 1 - 2 * (xx + zz); - m.get(5) = 2 * (yz + xw); - m.get(6) = 2 * (xz + yw); - m.get(7) = 2 * (yz - xw); - m.get(8) = 1 - 2 * (xx + yy); - return m; - } - template - auto quaternion::to_mat4(void)const -> mat4{ - mat4 m; - - value_type xx = m_data[1] * m_data[1]; - value_type yy = m_data[2] * m_data[2]; - value_type zz = m_data[3] * m_data[3]; - - value_type xy = m_data[1] * m_data[2]; - value_type xz = m_data[1] * m_data[3]; - value_type xw = m_data[1] * m_data[0]; - value_type yz = m_data[2] * m_data[3]; - value_type yw = m_data[2] * m_data[0]; - value_type zw = m_data[3] * m_data[0]; - - m.get(0) = 1 - 2 * (yy + zz); - m.get(1) = 2 * (xy + zw); - m.get(2) = 2 * (xz - yw); - m.get(3) = 0; - m.get(4) = 2 * (xy - zw); - m.get(5) = 1 - 2 * (xx + zz); - m.get(6) = 2 * (yz + xw); - m.get(7) = 0; - m.get(8) = 2 * (xz + yw); - m.get(9) = 2 * (yz - xw); - m.get(10) = 1 - 2 * (xx + yy); - m.get(11) = 0; - m.get(12) = 0; - m.get(13) = 0; - m.get(14) = 0; - m.get(15) = 1; - return m; - } - template - auto quaternion::to_euler_angles(void)const -> vec3{ - value_type ww = m_data[0] * m_data[0]; - value_type xx = m_data[1] * m_data[1]; - value_type yy = m_data[2] * m_data[2]; - value_type zz = m_data[3] * m_data[3]; - - value_type correction = ww + xx + yy + zz; - value_type test = m_data[1] * m_data[2] + m_data[3] * m_data[0]; - if(test > 0.499 * correction){ - return vec3(0, 2 * std::atan2(m_data[1], m_data[0]), pi() / 2.0); - }else if(test < -0.499 * correction){ - return vec3(0, -2 * std::atan2(m_data[1], m_data[0]), -pi() / 2.0); - } - return vec3(std::atan2((2 * m_data[1] * m_data[0]) - (2 * m_data[2] * m_data[3]), ww - xx + yy - zz), - std::atan2((2 * m_data[2] * m_data[0]) - (2 * m_data[1] * m_data[3]), xx - yy - zz + ww), - std::asin(2 * test / correction)); - } - template - auto quaternion::to_axis_angle(void)const -> std::pair>{ - quaternion q(*this); - if(m_data[0] > 1.0) - q = q.normalize(); - - value_type s = std::sqrt(1 - q.m_data[0] * q.m_data[0]); - if(s <= value_type{0.001}){ - return {2 * std::acos(q.m_data[0]), {1, 0, 0}}; - } - return {2 * std::acos(q.m_data[0]), {q.m_data[1] / s, q.m_data[2] / s, q.m_data[3] / s}}; - } - - template - bool operator==(const quaternion& left, const quaternion& right){ - return left.w() == right.w() && - left.x() == right.x() && - left.y() == right.y() && - left.z() == right.z(); - } - template - bool operator!=(const quaternion& left, const quaternion& right){ - return !(left == right); - } - template - auto operator-(const quaternion& left){ - using res_t = T; - return quaternion(manual_initialize, -left.w(), -left.x(), -left.y(), -left.z()); - } - template - auto operator-(const quaternion& left, const quaternion& right){ - using res_t = decltype(std::declval() - std::declval()); - return quaternion(manual_initialize, left.w() - right.w(), left.x() - right.x(), - left.y() - right.y(), left.z() - right.z()); - } - template - auto operator+(const quaternion& left, const quaternion& right){ - using res_t = decltype(std::declval() + std::declval()); - return quaternion(manual_initialize, left.w() + right.w(), left.x() + right.x(), - left.y() + right.y(), left.z() + right.z()); - } - template - auto operator*(const quaternion& left, const quaternion& right){ - using res_t = decltype(std::declval() * std::declval()); - return quaternion(manual_initialize, - (right.w() * left.w()) - (right.x() * left.x()) - - (right.y() * left.y()) - (right.z() * left.z()), - (right.w() * left.x()) + (right.x() * left.w()) + - (right.y() * left.z()) - (right.z() * left.y()), - (right.w() * left.y()) - (right.x() * left.z()) + - (right.y() * left.w()) + (right.z() * left.x()), - (right.w() * left.z()) + (right.x() * left.y()) - - (right.y() * left.x()) + (right.z() * left.w())); - } - template - auto operator*(const quaternion& left, const vec3& right){ - return left.to_mat3() * right; - } - template - auto operator*(const quaternion& left, U&& right){ - using res_t = decltype(std::declval() * std::declval()); - return quaternion(manual_initialize, left.w() * right, left.x() * right, left.y() * right, left.z() * right); - } - template - auto operator/(const quaternion& left, U&& right){ - using res_t = decltype(std::declval() / std::declval()); - return quaternion(manual_initialize, left.w() / right, left.x() / right, left.y() / right, left.z() / right); - } - template - decltype(auto) operator+=(quaternion& left, const quaternion& right){ - left.w() += right.w(); - left.x() += right.x(); - left.y() += right.y(); - left.z() += right.z(); - return left; - } - template - decltype(auto) operator-=(quaternion& left, const quaternion& right){ - left.w() -= right.w(); - left.x() -= right.x(); - left.y() -= right.y(); - left.z() -= right.z(); - return left; - } - template - decltype(auto) operator*=(quaternion& left, const quaternion& right){ - left = left * right; - return left; - } - - template - decltype(auto) operator*=(quaternion& left, U&& right){ - left.w() *= right; - left.x() *= right; - left.y() *= right; - left.z() *= right; - return left; - } - template - decltype(auto) operator/=(quaternion& left, U&& right){ - left.w() /= right; - left.x() /= right; - left.y() /= right; - left.z() /= right; - return left; - } - -} - -#endif diff --git a/include/math/vec.hpp b/include/math/vec.hpp deleted file mode 100644 index b30963c..0000000 --- a/include/math/vec.hpp +++ /dev/null @@ -1,128 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_VEC_HPP -#define REXY_VEC_HPP - -#include "mat.hpp" -#include "math_common.hpp" - -namespace math{ - - //class representing vectors - //inherit from matrix base because it also shared matrix attributes - template - class vector : public matrix_base - { - private: - using base = matrix_base; - public: - using value_type = typename base::value_type; - using size_type = typename base::size_type; - using pointer = typename base::pointer; - using const_pointer = typename base::const_pointer; - using reference = typename base::reference; - using const_reference = typename base::const_reference; - - public: - using base::base; - - template && ...),int> = 0> - constexpr vector(const vector& other, Args&&... args); - template - constexpr vector(const vector& other); - constexpr vector(const vector&) = default; - constexpr vector(vector&&) = default; - ~vector(void) = default; - - //Assignement - constexpr vector& operator=(const vector&) = default; - constexpr vector& operator=(vector&&) = default; - template - constexpr vector& operator=(const vector& m); - - constexpr reference operator[](size_type i); - constexpr const_reference operator[](size_type i)const; - - constexpr reference x(void); - constexpr const_reference x(void)const; - template - constexpr reference y(void); - template - constexpr const_reference y(void)const; - template - constexpr reference z(void); - template - constexpr const_reference z(void)const; - template - constexpr reference w(void); - template - constexpr const_reference w(void)const; - - value_type magnitude(void)const; - vector normalize(void); - protected: - template - constexpr void assign_(size_type offset, U&& u, Args&&... args); - }; - - template - constexpr auto perp(const vector& v); - template - constexpr auto perp(const vector& left, const vector& right); - template - constexpr auto cross(const vector& left, const vector& right); - - template - constexpr auto magnitude(const vector& v); - - template - constexpr auto operator*(const matrix& left, const vector& right); - template - constexpr auto operator*(const vector& left, const vector& right); - template - constexpr auto operator*(const vector& left, U&& right); - template - constexpr auto operator*(U&& left, const vector& right); - template - constexpr auto operator/(const vector& left, U&& right); - template - constexpr auto operator+(const vector& left, const vector& right); - template - constexpr auto operator-(const vector& left, const vector& right); - template - constexpr auto operator-(const vector& left); - - template - constexpr decltype(auto) operator*=(vector& left, U&& right); - template - constexpr decltype(auto) operator/=(vector& left, U&& right); - template - constexpr decltype(auto) operator+=(vector& left, const vector& right); - template - constexpr decltype(auto) operator-=(vector& left, const vector& right); - - extern template class vector; - extern template class vector; - extern template class vector; - -} - -#include "vec.tpp" - -#endif diff --git a/include/math/vec.tpp b/include/math/vec.tpp deleted file mode 100644 index dc80266..0000000 --- a/include/math/vec.tpp +++ /dev/null @@ -1,254 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2020 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef REXY_VEC_TPP -#define REXY_VEC_TPP - -#include //sqrt - -namespace math{ - - template - template && ...),int>> - constexpr vector::vector(const vector& other, Args&&... args){ - static_assert(sizeof...(args) + TR <= R); - size_type i = 0; - for(;i < TR;++i){ - this->m_data[i] = other[i]; - } - if constexpr(sizeof...(args) > 0){ - assign_(i, std::forward(args)...); - } - } - template - template - constexpr vector::vector(const vector& other){ - for(size_type i = 0;i < R;++i){ - this->m_data[i] = other[i]; - } - } - template - template - constexpr void vector::assign_(size_type offset, U&& u, Args&&... args){ - this->m_data[offset] = std::forward(u); - if constexpr(sizeof...(args) > 0){ - assign_(offset + 1, std::forward(args)...); - } - } - template - template - constexpr vector& vector::operator=(const vector& m){ - base::operator=(m); - return *this; - } - template - constexpr auto vector::operator[](size_type i) -> reference{ - return this->m_data[i]; - } - template - constexpr auto vector::operator[](size_type i)const -> const_reference{ - return this->m_data[i]; - } - - template - constexpr auto vector::x(void) -> reference{ - return this->m_data[0]; - } - template - constexpr auto vector::x(void)const -> const_reference{ - return this->m_data[0]; - } - template - template - constexpr auto vector::y(void) -> reference{ - static_assert(R > 1, "Vector does not contain a 2nd element"); - return this->m_data[1]; - } - template - template - constexpr auto vector::y(void)const -> const_reference{ - static_assert(R > 1, "Vector does not contain a 2nd element"); - return this->m_data[1]; - } - template - template - constexpr auto vector::z(void) -> reference{ - static_assert(R > 2, "Vector does not contain a 3rd element"); - return this->m_data[2]; - } - template - template - constexpr auto vector::z(void)const -> const_reference{ - static_assert(R > 2, "Vector does not contain a 3rd element"); - return this->m_data[2]; - } - template - template - constexpr auto vector::w(void) -> reference{ - static_assert(R > 3, "Vector does not contain a 4th element"); - return this->m_data[3]; - } - template - template - constexpr auto vector::w(void)const -> const_reference{ - static_assert(R > 3, "Vector does not contain a 4th element"); - return this->m_data[3]; - } - template - auto vector::magnitude(void)const -> value_type{ - value_type sum = 0; - for(size_type i = 0;i < R;++i){ - sum += (this->m_data[i] * this->m_data[i]); - } - return sqrt(sum); - } - template - vector vector::normalize(void){ - return (*this) / magnitude(); - } - - template - constexpr auto perp(const vector& v){ - return vec2(-v[1], v[0]); - } - template - constexpr auto perp(const vector& left, const vector& right){ - return (left[0] * right[1]) - (left[1] * right[0]); - } - template - constexpr auto cross(const vector& left, const vector& right){ - using res_t = decltype(left[0] * right[0]); - return vec3((left[1] * right[2]) - (left[2] * right[1]), - (left[2] * right[0]) - (left[0] * right[2]), - (left[0] * right[1]) - (left[1] * right[0])); - } - template - constexpr auto magnitude(const vector& v){ - return v.magnitude(); - } - - template - constexpr auto operator*(const matrix& left, const vector& right){ - using res_t = decltype(std::declval() * std::declval()); - vector res(zero_initialize); - size_t index = 0; - //columns == rows - for(size_t i = 0; i < R; ++i){ - for(size_t k = 0; k < C; ++k){ - res.get(index) += left.get(k, i) * right[k]; - } - ++index; - } - return res; - } - template - constexpr auto operator*(const vector& left, const vector& right){ - using res_t = decltype(std::declval() * std::declval()); - res_t res = 0; - for(size_t i = 0; i < R; ++i){ - res += left[i] * right[i]; - } - return res; - } - template - constexpr auto operator*(const vector& left, U&& right){ - using res_t = decltype(std::declval() * std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = left[i] * std::forward(right); - } - return res; - } - template - constexpr auto operator*(U&& left, const vector& right){ - using res_t = decltype(std::declval() * std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = std::forward(left) * right[i]; - } - return res; - } - template - constexpr auto operator/(const vector& left, U&& right){ - using res_t = decltype(std::declval() / std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = left[i] / std::forward(right); - } - return res; - } - template - constexpr auto operator+(const vector& left, const vector& right){ - using res_t = decltype(std::declval() + std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = left[i] + right[i]; - } - return res; - } - template - constexpr auto operator-(const vector& left, const vector& right){ - using res_t = decltype(std::declval() - std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = left[i] - right[i]; - } - return res; - } - template - constexpr auto operator-(const vector& left){ - using res_t = decltype(-std::declval()); - vector res(zero_initialize); - for(size_t i = 0; i < R; ++i){ - res[i] = -left[i]; - } - return res; - } - - template - constexpr decltype(auto) operator*=(vector& left, U&& right){ - for(size_t i = 0; i < R; ++i){ - left[i] *= right; - } - return left; - } - template - constexpr decltype(auto) operator/=(vector& left, U&& right){ - for(size_t i = 0; i < R; ++i){ - left[i] /= right; - } - return left; - } - template - constexpr decltype(auto) operator+=(vector& left, const vector& right){ - for(size_t i = 0; i < R; ++i){ - left[i] += right[i]; - } - return left; - } - template - constexpr decltype(auto) operator-=(vector& left, const vector& right){ - for(size_t i = 0; i < R; ++i){ - left[i] -= right[i]; - } - return left; - } - -} - -#endif diff --git a/include/ttt/board.hpp b/include/ttt/board.hpp index 978a7d1..693cd1b 100644 --- a/include/ttt/board.hpp +++ b/include/ttt/board.hpp @@ -19,7 +19,7 @@ #ifndef OUR_DICK_BOARD_HPP #define OUR_DICK_BOARD_HPP -#include "math/vec.hpp" +#include #include "config.hpp" #include //unique_ptr, shared_ptr @@ -42,7 +42,7 @@ public: }; private: - math::vec4f m_color_filter; + rml::vec4f m_color_filter; public: state value = state::BLANK; @@ -50,8 +50,8 @@ public: new_tile(void); new_tile(state start_value); - void set_color(const math::vec4f& color); - const math::vec4f& get_color(void)const; + void set_color(const rml::vec4f& color); + const rml::vec4f& get_color(void)const; }; class new_board : public wip::gfx::renderable, public egn::object @@ -78,7 +78,7 @@ public: new_tile::state check_winner(void)const; bool is_full(void)const; - int click_collision_cheat(const math::vec3f&)const; + int click_collision_cheat(const rml::vec3f&)const; void set_tile(int index, new_tile::state value); new_tile& get_tile(int index); const new_tile& get_tile(int index)const; diff --git a/include/ttt/main_renderer.hpp b/include/ttt/main_renderer.hpp index 9ac9117..bcdc5fc 100644 --- a/include/ttt/main_renderer.hpp +++ b/include/ttt/main_renderer.hpp @@ -22,7 +22,7 @@ #include "gfx/ogl/shader_program.hpp" #include "gfx/ogl/vao.hpp" #include "gfx/ogl/vbo.hpp" -#include "math/math.hpp" +#include #include "basic_framebuffer.hpp" #include "wip/renderer.hpp" @@ -36,8 +36,8 @@ class main_renderer { private: struct vertex{ - math::vec2f pos; - math::vec2f tex_coord; + rml::vec2f pos; + rml::vec2f tex_coord; }; static constexpr vertex s_vertices[] = { {{-1.0f, 1.0f}, {0.0f, 1.0f}}, @@ -60,11 +60,11 @@ private: public: main_renderer(wip::gfx::renderer& res, int width, int height); - void set_vp_matrix(const math::mat4f& vp); + void set_vp_matrix(const rml::mat4f& vp); void render(scene&); gfx::ogl::texture& color_buffer(void); void resize_viewport(int width, int height); - const math::vec4f& get_viewport(void)const; + const rml::vec4f& get_viewport(void)const; }; diff --git a/include/ttt/play_state.hpp b/include/ttt/play_state.hpp index 911a268..6932041 100644 --- a/include/ttt/play_state.hpp +++ b/include/ttt/play_state.hpp @@ -23,7 +23,7 @@ #include "main_renderer.hpp" #include "egn/camera.hpp" -#include "math/vec.hpp" +#include #include "board.hpp" class play_state : public egn::game_state_iface @@ -46,7 +46,7 @@ public: void render(void)override; private: - math::vec3f project_screen_to_world_(const math::vec3f& screen); + rml::vec3f project_screen_to_world_(const rml::vec3f& screen); }; #endif diff --git a/include/ttt/screen_renderer.hpp b/include/ttt/screen_renderer.hpp index cf7df63..fd9e535 100644 --- a/include/ttt/screen_renderer.hpp +++ b/include/ttt/screen_renderer.hpp @@ -22,7 +22,7 @@ #include "gfx/ogl/vbo.hpp" #include "gfx/ogl/vao.hpp" #include "gfx/ogl/texture.hpp" -#include "math/math.hpp" +#include #include "gfx/ogl/shader_program.hpp" #include "wip/renderer.hpp" @@ -37,8 +37,8 @@ class screen_renderer { private: struct vertex{ - math::vec2f pos; - math::vec2f tex_coord; + rml::vec2f pos; + rml::vec2f tex_coord; }; static constexpr vertex s_vertices[] = { {{-1.0f, 1.0f}, {0.0f, 1.0f}}, diff --git a/include/wip/ogl_material.hpp b/include/wip/ogl_material.hpp index dc9631b..feb6dc3 100644 --- a/include/wip/ogl_material.hpp +++ b/include/wip/ogl_material.hpp @@ -19,7 +19,7 @@ #ifndef OUR_DICK_GRAPHICS_WIP_OGL_MATERIAL_HPP #define OUR_DICK_GRAPHICS_WIP_OGL_MATERIAL_HPP -#include "math/vec.hpp" +#include #include "gfx/ogl/shader_program.hpp" #include "gfx/ogl/texture.hpp" @@ -32,9 +32,9 @@ namespace wip::gfx::ogl{ public: std::shared_ptr<::gfx::ogl::shader_program> shader; std::shared_ptr<::gfx::ogl::texture> diffuse_texture; - math::vec4f diffuse; - math::vec4f specular; - math::vec4f ambient; + rml::vec4f diffuse; + rml::vec4f specular; + rml::vec4f ambient; float shininess; material(const std::shared_ptr<::gfx::ogl::shader_program>& sh); diff --git a/include/wip/ogl_renderer.hpp b/include/wip/ogl_renderer.hpp index 46c50e2..d11cf76 100644 --- a/include/wip/ogl_renderer.hpp +++ b/include/wip/ogl_renderer.hpp @@ -21,8 +21,8 @@ #include "gfx/resource_container.hpp" -#include "math/vec.hpp" -#include "math/mat.hpp" +#include +#include #include "gfx/ogl/ubo.hpp" #include "ogl_resource_manager.hpp" @@ -37,8 +37,8 @@ namespace wip::gfx::ogl{ using container_type = resource_manager::container_type; protected: - ::gfx::ogl::ubo m_camera_uniform; - ::gfx::ogl::ubo m_model_uniform; + ::gfx::ogl::ubo m_camera_uniform; + ::gfx::ogl::ubo m_model_uniform; public: renderer(void) = default; @@ -49,9 +49,9 @@ namespace wip::gfx::ogl{ renderer& operator=(const renderer&) = default; renderer& operator=(renderer&&) = default; - void set_viewport(const math::vec4f& vp); - void set_model_matrix(const math::mat4f& mat); - void set_camera(const math::mat4f& view, const math::mat4f& proj); + void set_viewport(const rml::vec4f& vp); + void set_model_matrix(const rml::mat4f& mat); + void set_camera(const rml::mat4f& view, const rml::mat4f& proj); void bind_default_surface(void); void clear_current_surface(void); diff --git a/include/wip/vertex.hpp b/include/wip/vertex.hpp index 89493cc..881d4ff 100644 --- a/include/wip/vertex.hpp +++ b/include/wip/vertex.hpp @@ -19,13 +19,13 @@ #ifndef OUR_DICK_GRAPHICS_WIP_VERTEX_HPP #define OUR_DICK_GRAPHICS_WIP_VERTEX_HPP -#include "math/vec.hpp" +#include namespace wip::gfx{ struct vertex{ - math::vec3f position; - math::vec2f tex_coords; + rml::vec3f position; + rml::vec2f tex_coords; }; } diff --git a/makefile b/makefile index 926efaf..8edb747 100644 --- a/makefile +++ b/makefile @@ -26,7 +26,8 @@ DEPDIR::=$(OBJDIR)/dep LIBDIRS::=lib INCLUDE_DIRS::=include CFLAGS::=-std=c18 -Wall -pedantic -Wextra -CXXFLAGS::=-std=c++20 -Wall -pedantic -Wextra -fno-rtti -fno-exceptions $(shell pkg-config --cflags freetype2) +CXXFLAGS::=-std=c++20 -Wall -pedantic -Wextra -fno-rtti -fno-exceptions +PKGS::=freetype2 librml librexy DEBUG_CFLAGS::= DEBUG_CXXFLAGS::=-DOUR_DICK_DEBUG=2 EXT::=cpp @@ -147,8 +148,8 @@ endif #add dependency tracking and include directories -INTERNAL_COMPILERFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DEPDIR)/$(notdir $(patsubst %.o,%.d,$@))" -INTERNAL_LINKFLAGS=$(foreach dir,$(LIBDIRS),-L"$(dir)") +INTERNAL_COMPILERFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") $(foreach pkg,$(PKGS),$(shell pkg-config --cflags "$(pkg)")) -MMD -MP -MF"$(DEPDIR)/$(notdir $(patsubst %.o,%.d,$@))" +INTERNAL_LINKFLAGS=$(foreach dir,$(LIBDIRS),-L"$(dir)") $(foreach pkg,$(PKGS),$(shell pkg-config --libs "$(pkg)")) INTERNAL_SOURCES::=$(SOURCES) $(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext)))) OBJECTS::=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(INTERNAL_SOURCES))))) ALL_COMPILEFLAGS=$(COMPILER_FLAGS) $(INTERNAL_COMPILERFLAGS) diff --git a/src/egn/base_types.cpp b/src/egn/base_types.cpp index e46da78..f7c06c3 100644 --- a/src/egn/base_types.cpp +++ b/src/egn/base_types.cpp @@ -20,7 +20,7 @@ namespace egn{ - aabb::aabb(const math::vec3& p1, const math::vec3& p2): + aabb::aabb(const rml::vec3& p1, const rml::vec3& p2): point1(p1.x(), p1.y(), p1.z()), point2(p2.x(), p2.y(), p2.z()){} sphere::sphere(float r): diff --git a/src/egn/camera.cpp b/src/egn/camera.cpp index 59331b1..78d1a3c 100644 --- a/src/egn/camera.cpp +++ b/src/egn/camera.cpp @@ -18,30 +18,30 @@ #include "egn/camera.hpp" #include "config.hpp" -#include "math/projection.hpp" +#include namespace egn{ - camera_iface::camera_iface(const math::mat4f& proj, float n, float f): + camera_iface::camera_iface(const rml::mat4f& proj, float n, float f): m_projection_matrix(proj), m_near(n), m_far(f){} - void camera_iface::set_position(const math::vec3f& pos){ + void camera_iface::set_position(const rml::vec3f& pos){ object::set_position(pos); m_update_flag |= VIEW_UPDATE; } - void camera_iface::set_orientation(const math::quat_f& orient){ + void camera_iface::set_orientation(const rml::quat_f& orient){ object::set_orientation(orient); m_update_flag |= VIEW_UPDATE; } - const math::mat4f& camera_iface::get_projection_matrix(void)const{ + const rml::mat4f& camera_iface::get_projection_matrix(void)const{ if(m_update_flag & PROJ_UPDATE){ recalc_projection_matrix(); m_update_flag ^= PROJ_UPDATE; } return m_projection_matrix; } - const math::mat4f& camera_iface::get_view_matrix(void)const{ + const rml::mat4f& camera_iface::get_view_matrix(void)const{ if(m_update_flag & VIEW_UPDATE){ recalc_view_matrix(); m_update_flag ^= VIEW_UPDATE; @@ -74,7 +74,7 @@ namespace egn{ ortho_camera::ortho_camera(float w, float h, float n, float f): - camera_iface(math::ortho_projection(w, h, n, f), n, f), + camera_iface(rml::ortho_projection(w, h, n, f), n, f), m_width(w), m_height(h){} @@ -100,7 +100,7 @@ namespace egn{ void ortho_camera::recalc_projection_matrix(void)const{ rexy::debug::verbose::print("Rebuilding orthographic projection matrix\n"); - m_projection_matrix = math::ortho_projection(m_width, m_height, m_near, m_far); + m_projection_matrix = rml::ortho_projection(m_width, m_height, m_near, m_far); } flat_camera::flat_camera(float w, float h): diff --git a/src/egn/collision.cpp b/src/egn/collision.cpp index 801bca3..9da904d 100644 --- a/src/egn/collision.cpp +++ b/src/egn/collision.cpp @@ -37,7 +37,7 @@ namespace egn{ } - static math::vec3f lineseg_point_proj(const line_segment& l, const math::vec3f& r){ + static rml::vec3f lineseg_point_proj(const line_segment& l, const rml::vec3f& r){ /* C (the point) . @@ -59,8 +59,8 @@ namespace egn{ dist = |C - L(b)| */ - math::vec3f ab = (l.point2 - l.point1); - math::vec3f ac = (r - l.point1); + rml::vec3f ab = (l.point2 - l.point1); + rml::vec3f ac = (r - l.point1); //check if point is within the line segment //don't need to divide b by (ab * ab) to check if it's less than 0 @@ -77,18 +77,18 @@ namespace egn{ b = b / ab2; //calculate the point using the parametric equation for the line - math::vec3f pb = l.point1 + (ab * b); + rml::vec3f pb = l.point1 + (ab * b); return pb; } - static math::vec3f rectangle_point_coplanar_proj(const rectangle& l, const math::vec3f& r){ + static rml::vec3f rectangle_point_coplanar_proj(const rectangle& l, const rml::vec3f& r){ //r MUST be coplanar with l //r = a //l.point1 = b //l.point2 = c //l.point3 = d //l.point4 = e - math::vec3f cb = l.point2 - l.point1; - math::vec3f eb = l.point4 - l.point1; + rml::vec3f cb = l.point2 - l.point1; + rml::vec3f eb = l.point4 - l.point1; //apply the cb vector to 2 points along the primary i axis of the plane defined by the rectangle //compare that to the result of the application of the cb vector on the input point @@ -108,7 +108,7 @@ namespace egn{ //contained within the rectangle. Otherwise, we must project the point onto the rectangle's border. //If not in the rectangle, we can have 1 or 2 candidate edges to project onto. We want the closest one //to the input point. - //math::vec3f cand1, cand2; + //rml::vec3f cand1, cand2; /* now we divide the plane into a voronoi diagram where each region is closest @@ -201,28 +201,28 @@ namespace egn{ return false; } bool check_collision(const sphere& l, const sphere& r, float epsilon){ - return math::fuzzy_eq(l.point1, r.point1, l.radius + r.radius + epsilon); + return rml::fuzzy_eq(l.point1, r.point1, l.radius + r.radius + epsilon); } bool check_collision(const sphere& l, const aabb& r, float epsilon){ return check_collision(r, l, epsilon); } bool check_collision(const sphere& l, const line_segment& r, float epsilon){ - return math::fuzzy_eq(l.point1 - lineseg_point_proj(r, l.point1), math::vec3f(math::zero_initialize), l.radius + epsilon); + return rml::fuzzy_eq(l.point1 - lineseg_point_proj(r, l.point1), rml::vec3f(rml::zero_initialize), l.radius + epsilon); } bool check_collision(const sphere& l, const rectangle& r, float epsilon){ //see comments in check_collision(rectangle, point) for explanation - math::vec3f normal = math::cross(r.point2 - r.point1, r.point3 - r.point2); + rml::vec3f normal = rml::cross(r.point2 - r.point1, r.point3 - r.point2); float n2 = normal * normal; - math::vec3f d = l.point1 - r.point1; + rml::vec3f d = l.point1 - r.point1; - math::vec3f projected_point = l.point1 - (((normal * d) / n2) * normal); + rml::vec3f projected_point = l.point1 - (((normal * d) / n2) * normal); - math::vec3f proj_dist = l.point1 - rectangle_point_coplanar_proj(r, projected_point); + rml::vec3f proj_dist = l.point1 - rectangle_point_coplanar_proj(r, projected_point); return (proj_dist * proj_dist) <= ((l.radius + epsilon) * (l.radius + epsilon)); } bool check_collision(const sphere& l, const point& r, float epsilon){ - return math::fuzzy_eq(l.point1, r, l.radius + epsilon); + return rml::fuzzy_eq(l.point1, r, l.radius + epsilon); } bool check_collision(const line_segment& l, const line_segment& r, float epsilon){ //A lot more math in this one than I'd like to put in comments. Check these sites: @@ -234,10 +234,10 @@ namespace egn{ //starting lines. Make sure these points are within the line segment and return true if the //length of our newly found segment is within epsilon of 0 //Do note that floating point precision really starts taking a toll at this stage of complexity - math::vec3f v21 = l.point2 - l.point1; //u - math::vec3f v43 = r.point2 - r.point1; //v - math::vec3f v13 = l.point1 - r.point1; //w - math::vec3f zero = math::vec3f(math::zero_initialize); + rml::vec3f v21 = l.point2 - l.point1; //u + rml::vec3f v43 = r.point2 - r.point1; //v + rml::vec3f v13 = l.point1 - r.point1; //w + rml::vec3f zero = rml::vec3f(rml::zero_initialize); if(v43 == zero && v21 == zero){ return check_collision(l.point1, r.point1); @@ -298,10 +298,10 @@ namespace egn{ mua = (std::abs(mua_num) < epsilon ? 0 : mua_num / mua_den); mub = (std::abs(mub_num) < epsilon ? 0 : mub_num / mub_den); - math::vec3f p1 = l.point1 + (mua * v21); - math::vec3f p2 = r.point1 + (mub * v43); + rml::vec3f p1 = l.point1 + (mua * v21); + rml::vec3f p2 = r.point1 + (mub * v43); - return math::fuzzy_eq(p2 - p1, zero, epsilon); + return rml::fuzzy_eq(p2 - p1, zero, epsilon); } bool check_collision(const line_segment& l, const sphere& r, float epsilon){ return check_collision(r, l, epsilon); @@ -316,7 +316,7 @@ namespace egn{ return false; } bool check_collision(const line_segment& l, const point& r, float epsilon){ - return math::fuzzy_eq(r - lineseg_point_proj(l, r), math::vec3f(math::zero_initialize), epsilon); + return rml::fuzzy_eq(r - lineseg_point_proj(l, r), rml::vec3f(rml::zero_initialize), epsilon); } bool check_collision(const rectangle& l, const rectangle& r, float epsilon){ (void)l; @@ -335,21 +335,21 @@ namespace egn{ } bool check_collision(const rectangle& l, const point& r, float epsilon){ //get a normal vector for the rectangle - math::vec3f normal = math::cross(l.point2 - l.point1, l.point3 - l.point2); + rml::vec3f normal = rml::cross(l.point2 - l.point1, l.point3 - l.point2); float n2 = normal * normal; - math::vec3f d = r - l.point1; + rml::vec3f d = r - l.point1; //Project the point onto the plane defined by the rectangle - math::vec3f projected_point = r - (((normal * d) / n2) * normal); + rml::vec3f projected_point = r - (((normal * d) / n2) * normal); //find the nearest point on the rectangle to the newly created coplanar point and see if it's within //epsilon of the original point - math::vec3f proj_dist = r - rectangle_point_coplanar_proj(l, projected_point); + rml::vec3f proj_dist = r - rectangle_point_coplanar_proj(l, projected_point); return (proj_dist * proj_dist) <= (epsilon * epsilon); //avoid square root } bool check_collision(const point& l, const point& r, float epsilon){ - return math::fuzzy_eq(l, r, epsilon); + return rml::fuzzy_eq(l, r, epsilon); } bool check_collision(const point& l, const aabb& r, float epsilon){ return check_collision(r, l, epsilon); diff --git a/src/egn/font.cpp b/src/egn/font.cpp index b6da65e..10b8ea0 100644 --- a/src/egn/font.cpp +++ b/src/egn/font.cpp @@ -17,7 +17,7 @@ */ #include "egn/font.hpp" -#include "math/vec.hpp" +#include #include //sqrt, round #include //move #include @@ -47,7 +47,7 @@ namespace egn{ font_character& font_atlas::operator[](int character){ return m_atlas_data[character]; } - math::vec2 font_atlas::glyph_size(void)const{ + rml::vec2 font_atlas::glyph_size(void)const{ return {m_requested_width, m_requested_height}; } @@ -82,7 +82,7 @@ namespace egn{ } font_character calculate_character(FT_Face face, size_t atlas_w, size_t atlas_h, size_t atlas_x, size_t atlas_y){ - const math::vec2 dest_size = {face->glyph->metrics.width >> 6, face->glyph->metrics.height >> 6}; + const rml::vec2 dest_size = {face->glyph->metrics.width >> 6, face->glyph->metrics.height >> 6}; const float ratio_w = 1.0f / atlas_w; const float ratio_h = 1.0f / atlas_h; const float left = ratio_w * atlas_x; @@ -105,7 +105,7 @@ namespace egn{ src += pitch; } } - void font::generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, math::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range){ + void font::generate_atlas_piece_impl_(gfx::ogl::texture& atlas, font_atlas::map_type& metadata, rml::vec2& target_pos, const atlas_meta& info, unsigned char* data_buffer, const std::pair& range){ const auto& [atlas_width, atlas_height, max_glyph_width, max_glyph_height] = info; const auto format = (m_depth == 3) ? GL_RGB : GL_RED; const int freetype_load_flags = FT_LOAD_RENDER | ((m_depth == 3) ? FT_LOAD_TARGET_LCD : 0); @@ -117,7 +117,7 @@ namespace egn{ continue; } auto& bitmap = m_face->glyph->bitmap; - const math::vec2 out_size = {bitmap.width / m_depth, bitmap.rows}; + const rml::vec2 out_size = {bitmap.width / m_depth, bitmap.rows}; if(target_pos.x() + out_size.x() > atlas_width){ target_pos.x() = 0; target_pos.y() += max_glyph_height; diff --git a/src/egn/game.cpp b/src/egn/game.cpp index 9136a31..42aace3 100644 --- a/src/egn/game.cpp +++ b/src/egn/game.cpp @@ -91,7 +91,7 @@ namespace egn{ m_event_queue.emplace(input_event{input_event::type::RESIZE, glfwGetTime(), 0, 0, 0, (double)width, (double)height}); } - math::vec2 game::get_mouse_pos(void)const{ + rml::vec2 game::get_mouse_pos(void)const{ return m_window.get_cursor_pos(); } diff --git a/src/egn/object.cpp b/src/egn/object.cpp index 96675cb..09494d5 100644 --- a/src/egn/object.cpp +++ b/src/egn/object.cpp @@ -21,57 +21,57 @@ namespace egn{ - object::object(const math::vec3f& position): + object::object(const rml::vec3f& position): m_position(position){} - object::object(const math::vec3f& position, const math::quat_f& orientation): + object::object(const rml::vec3f& position, const rml::quat_f& orientation): m_position(position), m_orientation(orientation){} - void object::translate(const math::vec3f& distance){ + void object::translate(const rml::vec3f& distance){ set_position(m_position + distance); } - void object::rotate(const math::quat_f& distance){ + void object::rotate(const rml::quat_f& distance){ set_orientation(m_orientation * distance); } - void object::scale(const math::vec3f& distance){ - set_scale(math::vec3f{m_scale[0] * distance[0], + void object::scale(const rml::vec3f& distance){ + set_scale(rml::vec3f{m_scale[0] * distance[0], m_scale[1] * distance[1], m_scale[2] * distance[2]}); } - void object::look_at(const math::vec3f& targ, const math::vec3f& up){ - math::vec3f front((m_position - targ).normalize()); - math::vec3f right(math::cross(up, front)); - math::vec3f true_up(math::cross(front, right)); - set_orientation(math::quat_f{math::mat3f{right[0], true_up[0], front[0], + void object::look_at(const rml::vec3f& targ, const rml::vec3f& up){ + rml::vec3f front((m_position - targ).normalize()); + rml::vec3f right(rml::cross(up, front)); + rml::vec3f true_up(rml::cross(front, right)); + set_orientation(rml::quat_f{rml::mat3f{right[0], true_up[0], front[0], right[1], true_up[1], front[1], right[2], true_up[2], front[2]}}); } - void object::set_position(const math::vec3f& pos){ + void object::set_position(const rml::vec3f& pos){ m_update_flag |= (TRANSLATION_UPDATE | BOUNDING_VOLUME_UPDATE); m_position = pos; } - void object::set_orientation(const math::quat_f& orient){ + void object::set_orientation(const rml::quat_f& orient){ m_update_flag |= (ROTATION_UPDATE | BOUNDING_VOLUME_UPDATE); m_orientation = orient; } - void object::set_scale(const math::vec3f& scale){ + void object::set_scale(const rml::vec3f& scale){ m_update_flag |= (SCALE_UPDATE | BOUNDING_VOLUME_UPDATE); m_scale = scale; } - const math::mat4f& object::model_matrix(void)const{ + const rml::mat4f& object::model_matrix(void)const{ if(m_update_flag & (SCALE_UPDATE | ROTATION_UPDATE | TRANSLATION_UPDATE)){ recalc_model_matrix(); m_update_flag &= (~(SCALE_UPDATE | ROTATION_UPDATE | TRANSLATION_UPDATE)); } return m_model_matrix; } - const math::vec3f& object::position(void)const{ + const rml::vec3f& object::position(void)const{ return m_position; } - const math::vec3f& object::scale(void)const{ + const rml::vec3f& object::scale(void)const{ return m_scale; } - const math::quat_f& object::orientation(void)const{ + const rml::quat_f& object::orientation(void)const{ return m_orientation; } diff --git a/src/gfx/ogl/fbo.cpp b/src/gfx/ogl/fbo.cpp index a131600..038b9c7 100644 --- a/src/gfx/ogl/fbo.cpp +++ b/src/gfx/ogl/fbo.cpp @@ -56,7 +56,7 @@ namespace gfx::ogl{ return true; } - void fbo::clear_color_buffer(const math::vec4f& color){ + void fbo::clear_color_buffer(const rml::vec4f& color){ glClearNamedFramebufferfv(m_buffer, GL_COLOR, 0, &color[0]); } void fbo::clear_depth_buffer(GLfloat value){ @@ -80,12 +80,12 @@ namespace gfx::ogl{ } void fbo::set_viewport(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2){ - m_vp_coords = math::vec4f{x1, y1, x2, y2}; + m_vp_coords = rml::vec4f{x1, y1, x2, y2}; } void fbo::apply_viewport(void)const{ glViewport(m_vp_coords.x(), m_vp_coords.y(), m_vp_coords.z(), m_vp_coords.w()); } - const math::vec4f& fbo::get_viewport(void)const{ + const rml::vec4f& fbo::get_viewport(void)const{ return m_vp_coords; } diff --git a/src/gfx/ogl/shader_program.cpp b/src/gfx/ogl/shader_program.cpp index 6922c53..63fc6f6 100644 --- a/src/gfx/ogl/shader_program.cpp +++ b/src/gfx/ogl/shader_program.cpp @@ -131,18 +131,18 @@ namespace gfx::ogl{ glGetUniformfv(m_shader_id, m_location, &ret); return ret; } - math::vec2f uniform::get_vec2(void)const{ - math::vec2f ret; + rml::vec2f uniform::get_vec2(void)const{ + rml::vec2f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::vec3f uniform::get_vec3(void)const{ - math::vec3f ret; + rml::vec3f uniform::get_vec3(void)const{ + rml::vec3f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::vec4f uniform::get_vec4(void)const{ - math::vec4f ret; + rml::vec4f uniform::get_vec4(void)const{ + rml::vec4f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } @@ -152,18 +152,18 @@ namespace gfx::ogl{ glGetUniformdv(m_shader_id, m_location, &ret); return ret; } - math::vec2d uniform::get_dvec2(void)const{ - math::vec2d ret; + rml::vec2d uniform::get_dvec2(void)const{ + rml::vec2d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::vec3d uniform::get_dvec3(void)const{ - math::vec3d ret; + rml::vec3d uniform::get_dvec3(void)const{ + rml::vec3d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::vec4d uniform::get_dvec4(void)const{ - math::vec4d ret; + rml::vec4d uniform::get_dvec4(void)const{ + rml::vec4d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } @@ -173,18 +173,18 @@ namespace gfx::ogl{ glGetUniformiv(m_shader_id, m_location, &ret); return ret; } - math::vec2i uniform::get_ivec2(void)const{ - math::vec2i ret; + rml::vec2i uniform::get_ivec2(void)const{ + rml::vec2i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } - math::vec3i uniform::get_ivec3(void)const{ - math::vec3i ret; + rml::vec3i uniform::get_ivec3(void)const{ + rml::vec3i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } - math::vec4i uniform::get_ivec4(void)const{ - math::vec4i ret; + rml::vec4i uniform::get_ivec4(void)const{ + rml::vec4i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } @@ -194,18 +194,18 @@ namespace gfx::ogl{ glGetUniformuiv(m_shader_id, m_location, &ret); return ret; } - math::vec2u uniform::get_uvec2(void)const{ - math::vec2u ret; + rml::vec2u uniform::get_uvec2(void)const{ + rml::vec2u ret; glGetUniformuiv(m_shader_id, m_location, ret); return ret; } - math::vec3u uniform::get_uvec3(void)const{ - math::vec3u ret; + rml::vec3u uniform::get_uvec3(void)const{ + rml::vec3u ret; glGetUniformuiv(m_shader_id, m_location, ret); return ret; } - math::vec4u uniform::get_uvec4(void)const{ - math::vec4u ret; + rml::vec4u uniform::get_uvec4(void)const{ + rml::vec4u ret; glGetUniformuiv(m_shader_id, m_location, ret); return ret; } @@ -215,110 +215,110 @@ namespace gfx::ogl{ glGetUniformiv(m_shader_id, m_location, &ret); return static_cast(ret); } - math::vec2i uniform::get_bvec2(void)const{ - math::vec2i ret; + rml::vec2i uniform::get_bvec2(void)const{ + rml::vec2i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } - math::vec3i uniform::get_bvec3(void)const{ - math::vec3i ret; + rml::vec3i uniform::get_bvec3(void)const{ + rml::vec3i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } - math::vec4i uniform::get_bvec4(void)const{ - math::vec4i ret; + rml::vec4i uniform::get_bvec4(void)const{ + rml::vec4i ret; glGetUniformiv(m_shader_id, m_location, ret); return ret; } - math::mat2f uniform::get_mat2(void)const{ - math::mat2f ret; + rml::mat2f uniform::get_mat2(void)const{ + rml::mat2f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::mat3f uniform::get_mat3(void)const{ - math::mat3f ret; + rml::mat3f uniform::get_mat3(void)const{ + rml::mat3f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::mat4f uniform::get_mat4(void)const{ - math::mat4f ret; + rml::mat4f uniform::get_mat4(void)const{ + rml::mat4f ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat2x3(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat2x3(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat2x4(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat2x4(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat3x2(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat3x2(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat3x4(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat3x4(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat4x2(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat4x2(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_mat4x3(void)const{ - math::matrix ret; + rml::matrix uniform::get_mat4x3(void)const{ + rml::matrix ret; glGetUniformfv(m_shader_id, m_location, ret); return ret; } - math::mat2d uniform::get_dmat2(void)const{ - math::mat2d ret; + rml::mat2d uniform::get_dmat2(void)const{ + rml::mat2d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::mat3d uniform::get_dmat3(void)const{ - math::mat3d ret; + rml::mat3d uniform::get_dmat3(void)const{ + rml::mat3d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::mat4d uniform::get_dmat4(void)const{ - math::mat4d ret; + rml::mat4d uniform::get_dmat4(void)const{ + rml::mat4d ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat2x3(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat2x3(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat2x4(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat2x4(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat3x2(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat3x2(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat3x4(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat3x4(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat4x2(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat4x2(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } - math::matrix uniform::get_dmat4x3(void)const{ - math::matrix ret; + rml::matrix uniform::get_dmat4x3(void)const{ + rml::matrix ret; glGetUniformdv(m_shader_id, m_location, ret); return ret; } @@ -371,17 +371,17 @@ namespace gfx::ogl{ glProgramUniform1i(m_shader_id, m_location, tex_unit); } - void uniform::set(const vec2f& v){ + void uniform::set(const rml::vec2f& v){ glProgramUniform2fv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec3f& v){ + void uniform::set(const rml::vec3f& v){ glProgramUniform3fv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec4f& v){ + void uniform::set(const rml::vec4f& v){ glProgramUniform4fv(m_shader_id, m_location, 1, v); } - void uniform::set(GLsizei count, const vec2f* v_arr){ + void uniform::set(GLsizei count, const rml::vec2f* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[2])){ glProgramUniform2fv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -394,7 +394,7 @@ namespace gfx::ogl{ glProgramUniform2fv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec3f* v_arr){ + void uniform::set(GLsizei count, const rml::vec3f* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[3])){ glProgramUniform3fv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -408,7 +408,7 @@ namespace gfx::ogl{ glProgramUniform3fv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec4f* v_arr){ + void uniform::set(GLsizei count, const rml::vec4f* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[4])){ glProgramUniform4fv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -437,17 +437,17 @@ namespace gfx::ogl{ glProgramUniform4fv(m_shader_id, m_location, count, v_arr); } - void uniform::set(const vec2& v){ + void uniform::set(const rml::vec2i& v){ glProgramUniform2iv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec3& v){ + void uniform::set(const rml::vec3i& v){ glProgramUniform3iv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec4& v){ + void uniform::set(const rml::vec4i& v){ glProgramUniform4iv(m_shader_id, m_location, 1, v); } - void uniform::set(GLsizei count, const vec2* v_arr){ + void uniform::set(GLsizei count, const rml::vec2i* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLint[2])){ glProgramUniform2iv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -460,7 +460,7 @@ namespace gfx::ogl{ glProgramUniform2iv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec3* v_arr){ + void uniform::set(GLsizei count, const rml::vec3i* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLint[3])){ glProgramUniform3iv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -474,7 +474,7 @@ namespace gfx::ogl{ glProgramUniform3iv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec4* v_arr){ + void uniform::set(GLsizei count, const rml::vec4i* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLint[4])){ glProgramUniform4iv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -503,17 +503,17 @@ namespace gfx::ogl{ glProgramUniform4iv(m_shader_id, m_location, count, v_arr); } - void uniform::set(const vec2& v){ + void uniform::set(const rml::vec2u& v){ glProgramUniform2uiv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec3& v){ + void uniform::set(const rml::vec3u& v){ glProgramUniform3uiv(m_shader_id, m_location, 1, v); } - void uniform::set(const vec4& v){ + void uniform::set(const rml::vec4u& v){ glProgramUniform4uiv(m_shader_id, m_location, 1, v); } - void uniform::set(GLsizei count, const vec2* v_arr){ + void uniform::set(GLsizei count, const rml::vec2u* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[2])){ glProgramUniform2uiv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -526,7 +526,7 @@ namespace gfx::ogl{ glProgramUniform2uiv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec3* v_arr){ + void uniform::set(GLsizei count, const rml::vec3u* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[3])){ glProgramUniform3uiv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -540,7 +540,7 @@ namespace gfx::ogl{ glProgramUniform3uiv(m_shader_id, m_location, count, arr.get()); } } - void uniform::set(GLsizei count, const vec4* v_arr){ + void uniform::set(GLsizei count, const rml::vec4u* v_arr){ if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[4])){ glProgramUniform4uiv(m_shader_id, m_location, count, reinterpret_cast(v_arr)); }else{ @@ -569,17 +569,17 @@ namespace gfx::ogl{ glProgramUniform4uiv(m_shader_id, m_location, count, v_arr); } - void uniform::set(const mat2f& m){ + void uniform::set(const rml::mat2f& m){ glProgramUniformMatrix2fv(m_shader_id, m_location, 1, GL_FALSE, m); } - void uniform::set(const mat3f& m){ + void uniform::set(const rml::mat3f& m){ glProgramUniformMatrix3fv(m_shader_id, m_location, 1, GL_FALSE, m); } - void uniform::set(const mat4f& m){ + void uniform::set(const rml::mat4f& m){ glProgramUniformMatrix4fv(m_shader_id, m_location, 1, GL_FALSE, m); } - void uniform::set(GLsizei count, const mat2f* m_arr){ + void uniform::set(GLsizei count, const rml::mat2f* m_arr){ if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[4])){ glProgramUniformMatrix2fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast(m_arr)); }else{ @@ -594,7 +594,7 @@ namespace gfx::ogl{ glProgramUniformMatrix2fv(m_shader_id, m_location, count, GL_FALSE, arr.get()); } } - void uniform::set(GLsizei count, const mat3f* m_arr){ + void uniform::set(GLsizei count, const rml::mat3f* m_arr){ if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[9])){ glProgramUniformMatrix3fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast(m_arr)); }else{ @@ -614,7 +614,7 @@ namespace gfx::ogl{ glProgramUniformMatrix3fv(m_shader_id, m_location, count, GL_FALSE, arr.get()); } } - void uniform::set(GLsizei count, const mat4f* m_arr){ + void uniform::set(GLsizei count, const rml::mat4f* m_arr){ if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[16])){ glProgramUniformMatrix4fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast(m_arr)); }else{ diff --git a/src/gfx/ogl/texture.cpp b/src/gfx/ogl/texture.cpp index c88078d..b5200ba 100644 --- a/src/gfx/ogl/texture.cpp +++ b/src/gfx/ogl/texture.cpp @@ -149,8 +149,8 @@ namespace gfx::ogl{ glGetTextureParameteriv(m_tex_id, GL_TEXTURE_MIN_FILTER, &filter); return static_cast(filter); } - math::vec4 texture_base::get_border_color(void)const{ - math::vec4 color; + rml::vec4 texture_base::get_border_color(void)const{ + rml::vec4 color; glGetTextureParameterfv(m_tex_id, GL_TEXTURE_BORDER_COLOR, color); return color; } diff --git a/src/gfx/ogl/window.cpp b/src/gfx/ogl/window.cpp index 32e8d0c..5c99cd3 100644 --- a/src/gfx/ogl/window.cpp +++ b/src/gfx/ogl/window.cpp @@ -330,7 +330,7 @@ static void enable_opengl_debug_context(void){ m_title = nullptr; } - void window::set_size(const math::vec2i& v){ + void window::set_size(const rml::vec2i& v){ set_size(v.x(), v.y()); } void window::set_size(int w, int h){ @@ -345,7 +345,7 @@ static void enable_opengl_debug_context(void){ void window::set_title(const char* t){ glfwSetWindowTitle(m_window, t); } - void window::set_pos(const math::vec2i& v){ + void window::set_pos(const rml::vec2i& v){ set_pos(v.x(), v.y()); } void window::set_pos(int x, int y){ @@ -405,8 +405,8 @@ static void enable_opengl_debug_context(void){ } - math::vec2i window::get_size(void)const{ - math::vec2i retval; + rml::vec2i window::get_size(void)const{ + rml::vec2i retval; glfwGetWindowSize(m_window, &retval.x(), &retval.y()); return retval; } @@ -417,8 +417,8 @@ static void enable_opengl_debug_context(void){ return get_size().y(); } - math::vec2i window::get_pos(void)const{ - math::vec2i retval; + rml::vec2i window::get_pos(void)const{ + rml::vec2i retval; glfwGetWindowPos(m_window, &retval.x(), &retval.y()); return retval; } @@ -428,8 +428,8 @@ static void enable_opengl_debug_context(void){ int window::get_posy(void)const{ return get_pos().y(); } - math::vec2i window::get_context_version(void)const{ - return math::vec2i{get_context_vmaj(), get_context_vmin()}; + rml::vec2i window::get_context_version(void)const{ + return rml::vec2i{get_context_vmaj(), get_context_vmin()}; } int window::get_context_vmaj(void)const{ return glfwGetWindowAttrib(m_window, GLFW_CONTEXT_VERSION_MAJOR); @@ -441,8 +441,8 @@ static void enable_opengl_debug_context(void){ return m_swap_interval; } - math::vec2d window::get_cursor_pos(void)const{ - math::vec2d retval; + rml::vec2d window::get_cursor_pos(void)const{ + rml::vec2d retval; glfwGetCursorPos(m_window, &retval.x(), &retval.y()); return retval; } diff --git a/src/main.cpp b/src/main.cpp index b302c6f..6a226f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ #include "ttt/tic_tac_toe.hpp" #include "egn/font.hpp" -#include "math/debug.hpp" +#include int main(){ srand(time(NULL)); diff --git a/src/math/mat.cpp b/src/math/mat.cpp deleted file mode 100644 index 8728926..0000000 --- a/src/math/mat.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2022 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include "math/mat.hpp" -#include "math/fwd_declare.hpp" - -namespace math{ - - template class matrix; - template class matrix; - template class matrix; - -} diff --git a/src/math/quat.cpp b/src/math/quat.cpp deleted file mode 100644 index f6a4010..0000000 --- a/src/math/quat.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2022 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include "math/quat.hpp" -#include "math/fwd_declare.hpp" - -namespace math{ - - template class quaternion; - -} diff --git a/src/math/vec.cpp b/src/math/vec.cpp deleted file mode 100644 index 117d888..0000000 --- a/src/math/vec.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2022 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include "math/vec.hpp" -#include "math/fwd_declare.hpp" - -namespace math{ - - template class vector; - template class vector; - template class vector; - -} diff --git a/src/ttt/board.cpp b/src/ttt/board.cpp index e77d375..ed7373b 100644 --- a/src/ttt/board.cpp +++ b/src/ttt/board.cpp @@ -23,10 +23,10 @@ new_tile::new_tile(state start_value): value(start_value){} -void new_tile::set_color(const math::vec4f& color){ +void new_tile::set_color(const rml::vec4f& color){ m_color_filter = color; } -const math::vec4f& new_tile::get_color(void)const{ +const rml::vec4f& new_tile::get_color(void)const{ return m_color_filter; } @@ -65,15 +65,15 @@ bool new_board::is_full(void)const{ } return true; } -int new_board::click_collision_cheat(const math::vec3f& unproj_3)const{ - math::vec4f unproj_4 = {unproj_3[0], unproj_3[1], unproj_3[2], 1}; - math::vec4f mod_coord = model_matrix().inverse() * unproj_4; +int new_board::click_collision_cheat(const rml::vec3f& unproj_3)const{ + rml::vec4f unproj_4 = {unproj_3[0], unproj_3[1], unproj_3[2], 1}; + rml::vec4f mod_coord = model_matrix().inverse() * unproj_4; mod_coord /= mod_coord[3]; - math::vec3f projected1 = {mod_coord[0], mod_coord[1], mod_coord[2]}; + rml::vec3f projected1 = {mod_coord[0], mod_coord[1], mod_coord[2]}; for(size_t i = 0;i < 9;++i){ const new_tile& sq = m_tiles[i]; - const math::vec3f& sq_pos = sq.position(); + const rml::vec3f& sq_pos = sq.position(); if((projected1.x() > (sq_pos.x() - 1.0f) && projected1.x() < (sq_pos.x() + 1.0f)) && (projected1.y() > (sq_pos.y() - 1.0f) && projected1.y() < (sq_pos.y() + 1.0f))) { diff --git a/src/ttt/main_renderer.cpp b/src/ttt/main_renderer.cpp index 7a0e00c..49a064c 100644 --- a/src/ttt/main_renderer.cpp +++ b/src/ttt/main_renderer.cpp @@ -42,12 +42,12 @@ main_renderer::main_renderer(wip::gfx::renderer& res, int width, int height): rexy::debug::print_error("%s\n", m_square_shader->get_error().c_str()); } - m_square_shader->get_uniform("vp_mat").set(math::mat4f{}); + m_square_shader->get_uniform("vp_mat").set(rml::mat4f{}); vert = res.shader_stages().emplace_value("screen_shader_vert", screen_shader::vertex_shader_text, gfx::ogl::shader_stage::type::VERTEX).first; frag = res.shader_stages().emplace_value("screen_shader_frag", screen_shader::fragment_shader_text, gfx::ogl::shader_stage::type::FRAGMENT).first; m_screen_shader = res.shader_programs().emplace_value("screen_shader", *vert, *frag).first; - m_screen_shader->get_uniform("vp_mat").set(math::mat4f{}); + m_screen_shader->get_uniform("vp_mat").set(rml::mat4f{}); m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex)); auto attrib = m_vao.get_attribute(0); @@ -62,7 +62,7 @@ main_renderer::main_renderer(wip::gfx::renderer& res, int width, int height): resize_viewport(width, height); } -void main_renderer::set_vp_matrix(const math::mat4f& vp){ +void main_renderer::set_vp_matrix(const rml::mat4f& vp){ m_square_shader->get_uniform("vp_mat").set(vp); } void main_renderer::render(scene&){ @@ -101,6 +101,6 @@ void main_renderer::resize_viewport(int width, int height){ data[4].tex_coord = {x2, y2}; data[5].tex_coord = {x1, y2}; } -const math::vec4f& main_renderer::get_viewport(void)const{ +const rml::vec4f& main_renderer::get_viewport(void)const{ return m_fb.get_viewport(); } diff --git a/src/ttt/play_state.cpp b/src/ttt/play_state.cpp index 92c6b56..556a9cf 100644 --- a/src/ttt/play_state.cpp +++ b/src/ttt/play_state.cpp @@ -21,7 +21,7 @@ #include "ttt/pause_state.hpp" #include "gfx/ogl/gl_include.hpp" //TODO: separate key definitions from GLFW #include "egn/image.hpp" //TODO: move image to engine namespace -#include "math/math.hpp" +#include #include "config.hpp" #include "egn/game.hpp" #include "ttt/board.hpp" @@ -68,16 +68,16 @@ void play_state::enter(){ } void play_state::leave(){} -math::vec3f play_state::project_screen_to_world_(const math::vec3f& screen){ - const math::vec4f& viewport = m_main_renderer.get_viewport(); - const math::vec3f vp_coords{screen.x() - viewport[0], viewport[3] - (screen.y() - viewport[1]), screen.z()}; - const math::mat4f vp_mat = m_main_camera.get_projection_matrix() * m_main_camera.get_view_matrix(); - return math::unproject(vp_mat, vp_coords, viewport); +rml::vec3f play_state::project_screen_to_world_(const rml::vec3f& screen){ + const rml::vec4f& viewport = m_main_renderer.get_viewport(); + const rml::vec3f vp_coords{screen.x() - viewport[0], viewport[3] - (screen.y() - viewport[1]), screen.z()}; + const rml::mat4f vp_mat = m_main_camera.get_projection_matrix() * m_main_camera.get_view_matrix(); + return rml::unproject(vp_mat, vp_coords, viewport); } -math::vec4f tile_color(const new_tile& t, bool mouseclick){ - static constexpr math::vec4f teal = {0, 1, 1, 0.1}; - static constexpr math::vec4f green = {0, 1, 0, 0.1}; +rml::vec4f tile_color(const new_tile& t, bool mouseclick){ + static constexpr rml::vec4f teal = {0, 1, 1, 0.1}; + static constexpr rml::vec4f green = {0, 1, 0, 0.1}; if(t.value == new_tile::state::BLANK && mouseclick){ return green; } @@ -105,10 +105,10 @@ void play_state::handle_input(const egn::input_event& ev){ m_main_renderer.resize_viewport(ev.x, ev.y); renderer().set_viewport({0, 0, ev.x, ev.y}); }else if(ev.ev_type == egn::input_event::type::MOUSE_MOVE){ - math::vec3f projected1 = project_screen_to_world_({ev.x, ev.y, 1.0f}); + rml::vec3f projected1 = project_screen_to_world_({ev.x, ev.y, 1.0f}); //TODO actual 3D ray picking - //math::vec3f projected2 = project_screen_to_world_({ev.x, ev.y, -1.0f}); + //rml::vec3f projected2 = project_screen_to_world_({ev.x, ev.y, -1.0f}); int new_index = m_board->click_collision_cheat(projected1); diff --git a/src/ttt/screen_renderer.cpp b/src/ttt/screen_renderer.cpp index 9855b2b..fca564c 100644 --- a/src/ttt/screen_renderer.cpp +++ b/src/ttt/screen_renderer.cpp @@ -25,7 +25,7 @@ #include "egn/font.hpp" #include "ttt/font_shader.hpp" -#include "math/debug.hpp" +#include screen_renderer::screen_renderer(wip::gfx::renderer& res, int width, int height, const std::shared_ptr& base_tex): m_vbo(s_vertices, sizeof(s_vertices), gfx::ogl::buffer::usage::DYNAMIC_DRAW), diff --git a/src/wip/ogl_renderer.cpp b/src/wip/ogl_renderer.cpp index 6a2b2fd..563eb33 100644 --- a/src/wip/ogl_renderer.cpp +++ b/src/wip/ogl_renderer.cpp @@ -21,13 +21,13 @@ namespace wip::gfx::ogl{ - void renderer::set_viewport(const math::vec4f& vp){ + void renderer::set_viewport(const rml::vec4f& vp){ glViewport(vp.x(), vp.y(), vp.z(), vp.w()); } - void renderer::set_model_matrix(const math::mat4f& mat){ + void renderer::set_model_matrix(const rml::mat4f& mat){ m_model_uniform.set<0>(mat); } - void renderer::set_camera(const math::mat4f& view, const math::mat4f& proj){ + void renderer::set_camera(const rml::mat4f& view, const rml::mat4f& proj){ m_camera_uniform.set<0>(proj * view); } void renderer::bind_default_surface(void){ diff --git a/src/wip/ogl_shader.cpp b/src/wip/ogl_shader.cpp index 37e14c0..2580a31 100644 --- a/src/wip/ogl_shader.cpp +++ b/src/wip/ogl_shader.cpp @@ -23,6 +23,7 @@ #include "config.hpp" namespace wip::gfx::ogl{ + [[maybe_unused]] static constexpr shader_stage::type map_type(shader_type in){ using in_type = shader_type; using out_type = shader_stage::type; @@ -39,6 +40,7 @@ namespace wip::gfx::ogl{ return out_type::VERTEX; }; } + [[maybe_unused]] static constexpr shader_type map_type(shader_stage::type in){ using in_type = shader_stage::type; using out_type = shader_type; @@ -55,6 +57,7 @@ namespace wip::gfx::ogl{ return out_type::VERTEX; }; } + [[maybe_unused]] static constexpr ::gfx::ogl::buffer::usage map_type(buffer_type in){ using in_type = buffer_type; using out_type = ::gfx::ogl::buffer::usage; diff --git a/src/wip/square.cpp b/src/wip/square.cpp index 982bbcd..2ceb1bc 100644 --- a/src/wip/square.cpp +++ b/src/wip/square.cpp @@ -18,7 +18,7 @@ #include "wip/square.hpp" -#include "math/mat.hpp" +#include namespace wip{ @@ -31,7 +31,7 @@ namespace wip{ } void square::render(gfx::renderer& r, gfx::draw_command&){ //TODO: all render code should be handled in the mesh; it is tied to the render api whereas instances shouldn't be - r.set_model_matrix(math::mat4f(math::id_initialize)); + r.set_model_matrix(rml::mat4f(rml::id_initialize)); m_mesh->render(r); }