diff --git a/Engine/Config/GraphicsLibrary/graphics.h b/Engine/Config/GraphicsLibrary/graphics.h new file mode 100644 index 0000000..67da31f --- /dev/null +++ b/Engine/Config/GraphicsLibrary/graphics.h @@ -0,0 +1,60 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** graphics +*/ + +#ifndef GRAPHICS_H_ + #define GRAPHICS_H_ + +//////////////////////////////////////////////////////////// +// Define an enum for the graphics libraries +//////////////////////////////////////////////////////////// +enum GraphicsLibrary { + CSFML, + SFML, + SDL, + OPENGL, + VULKAN, + DIRECTX +}; + +//////////////////////////////////////////////////////////// +// Define the default graphics library +//////////////////////////////////////////////////////////// +#define GRAPHICS_LIBRARY_DEFALUT CSFML + +#ifndef GRAPHICS_LIBRARY + #define GRAPHICS_LIBRARY GRAPHICS_LIBRARY_DEFALUT +#endif + +//////////////////////////////////////////////////////////// +// Include the appropriate header based on the enum value +//////////////////////////////////////////////////////////// +#ifdef GRAPHICS_LIBRARY + #if GRAPHICS_LIBRARY == CSFML + #include + #elif GRAPHICS_LIBRARY == SFML + #include + #elif GRAPHICS_LIBRARY == SDL + #include + #elif GRAPHICS_LIBRARY == OPENGL + #include + #include + #include + #include + #elif GRAPHICS_LIBRARY == VULKAN + #include + #include + #include + #elif GRAPHICS_LIBRARY == DIRECTX + #include + #else + #error "[Config@GraphicsLibrary]: No graphics library or invalid graphics library." + #endif +#endif + +#endif /* !GRAPHICS_H_ */ diff --git a/Engine/Config/OperatingSystem/distribution.h b/Engine/Config/OperatingSystem/distribution.h new file mode 100644 index 0000000..583cfe1 --- /dev/null +++ b/Engine/Config/OperatingSystem/distribution.h @@ -0,0 +1,126 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** distribution +*/ + +#ifndef DISTRIBUTION_H_ + #define DISTRIBUTION_H_ + +//////////////////////////////////////////////////////////// +// Check if we need to mark functions as extern "C" +//////////////////////////////////////////////////////////// +#ifdef __cplusplus + #define ENGINE_EXTERN_C extern "C" +#else + #define ENGINE_EXTERN_C extern +#endif + + +//////////////////////////////////////////////////////////// +// Identify the operating system +//////////////////////////////////////////////////////////// +#if defined(_WIN32) || defined(__WIN32__) + + // Windows + #define ENGINE_SYSTEM_WINDOWS + +#elif defined(linux) || defined(__linux) + + // Linux + #define ENGINE_SYSTEM_LINUX + +#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh) + + // MacOS + #define ENGINE_SYSTEM_MACOS + +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + + // FreeBSD + #define ENGINE_SYSTEM_FREEBSD + +#else + + // Unsupported system + #error [Config@Distribution]: This operating system is not supported by ENGINE library. + +#endif + + +//////////////////////////////////////////////////////////// +// Define helpers to create portable import / export macros for each module +//////////////////////////////////////////////////////////// +#if defined(ENGINE_SYSTEM_WINDOWS) + + // Windows compilers need specific (and different) keywords for export and import + #define ENGINE_API_EXPORT extern "C" __declspec(dllexport) + #define ENGINE_API_IMPORT ENGINE_EXTERN_C __declspec(dllimport) + + // For Visual C++ compilers, we also need to turn off this annoying C4251 warning + #ifdef _MSC_VER + + #pragma warning(disable : 4251) + + #endif + +#else // Linux, FreeBSD, Mac OS X + + #if __GNUC__ >= 4 + + // GCC 4 has special keywords for showing/hidding symbols, + // the same keyword is used for both importing and exporting + #define ENGINE_API_EXPORT extern "C" __attribute__ ((__visibility__ ("default"))) + #define ENGINE_API_IMPORT ENGINE_EXTERN_C __attribute__ ((__visibility__ ("default"))) + + #else + + // GCC < 4 has no mechanism to explicitely hide symbols, everything's exported + #define ENGINE_API_EXPORT extern "C" + #define ENGINE_API_IMPORT ENGINE_EXTERN_C + + #endif + +#endif + +//////////////////////////////////////////////////////////// +// Cross-platform warning for deprecated functions and classes +// +// @example: +// struct ENGINE_DEPRECATED MyStruct +// { +// ... +// }; +// +// ENGINE_DEPRECATED void global_func(); +//////////////////////////////////////////////////////////// +#if defined(ENGINE_NO_DEPRECATED_WARNINGS) + + // User explicitly requests to disable deprecation warnings + #define ENGINE_DEPRECATED + +#elif defined(_MSC_VER) + + // Microsoft C++ compiler + // Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to + // trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified. + #define ENGINE_DEPRECATED __declspec(deprecated) + +#elif defined(__GNUC__) + + // g++ and Clang + #define ENGINE_DEPRECATED __attribute__ ((deprecated)) + +#else + + // Other compilers are not supported, leave class or function as-is. + // With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma. + #pragma message("ENGINE_DEPRECATED is not supported for your compiler, please contact the ENGINE team") + #define ENGINE_DEPRECATED + +#endif + +#endif /* !DISTRIBUTION_H_ */ diff --git a/Engine/Config/Version/version.h b/Engine/Config/Version/version.h new file mode 100644 index 0000000..97e94c3 --- /dev/null +++ b/Engine/Config/Version/version.h @@ -0,0 +1,46 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** version +*/ + +#ifndef VERSION_H_ + #define VERSION_H_ + +//////////////////////////////////////////////////////////// +// Define the ENGINE version +//////////////////////////////////////////////////////////// +#ifdef FLAG_VERSION_MAJOR + #define ENGINE_VERSION_MAJOR FLAG_VERSION_MAJOR +#else + #define ENGINE_VERSION_MAJOR 0 +#endif + +#ifdef FLAG_VERSION_MINOR + #define ENGINE_VERSION_MINOR FLAG_VERSION_MINOR +#else + #define ENGINE_VERSION_MINOR 1 +#endif + +#ifdef FLAG_VERSION_PATCH + #define ENGINE_VERSION_PATCH FLAG_VERSION_PATCH +#else + #define ENGINE_VERSION_PATCH 0 +#endif + +//////////////////////////////////////////////////////////// +// Define the ENGINE version string +//////////////////////////////////////////////////////////// +// Helper macro to convert a macro to a string +#define STRINGIFY(x) STRINGIFY_(x) +#define STRINGIFY_(x) #x + +#define ENGINE_VERSION_STRING \ + STRINGIFY(ENGINE_VERSION_MAJOR) "." \ + STRINGIFY(ENGINE_VERSION_MINOR) "." \ + STRINGIFY(ENGINE_VERSION_PATCH) + +#endif /* !VERSION_H_ */ diff --git a/Engine/Config/config.h b/Engine/Config/config.h new file mode 100644 index 0000000..4ac3758 --- /dev/null +++ b/Engine/Config/config.h @@ -0,0 +1,23 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** config +*/ + +#ifndef CONFIG_H_ + #define CONFIG_H_ + +//////////////////////////////////////////////////////////// +// Include the appropriate header based on the platform used: +// - the GraphicsLibrary used by the user (OpenGL, Vulkan, DirectX, etc.) +// - the OperatingSystem used by the user (Windows, Linux, MacOS, etc.) +// - the Version of the Engine used by the user (0.0.1, 0.1.0, 1.0.0, etc.) +//////////////////////////////////////////////////////////// +#include "GraphicsLibrary/graphics.h" +#include "OperatingSystem/distribution.h" +#include "Version/version.h" + +#endif /* !CONFIG_H_ */ diff --git a/Engine/Engine/Clock/clock.c b/Engine/Engine/Clock/clock.c new file mode 100644 index 0000000..5eff679 --- /dev/null +++ b/Engine/Engine/Clock/clock.c @@ -0,0 +1,85 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** clock +*/ + +#include "engine_clock.h" + +engine_clock_t *clock_create(void) +{ + engine_clock_t *clock = (engine_clock_t*)malloc(sizeof(engine_clock_t)); + #if GRAPHICS_LIBRARY == CSFML + clock->clock = sfClock_create(); + #elif GRAPHICS_LIBRARY == SFML + clock->clock = new sf::Clock(); + #elif GRAPHICS_LIBRARY == SDL + clock->clock = SDL_CreateClock(); + #elif GRAPHICS_LIBRARY == OPENGL + clock->clock = GL_CreateClock(); + #elif GRAPHICS_LIBRARY == VULKAN + clock->clock = VK_CreateClock(); + #endif + return clock; +} + +void clock_destroy(engine_clock_t *clock) +{ + #if GRAPHICS_LIBRARY == CSFML + sfClock_destroy(clock->clock); + #elif GRAPHICS_LIBRARY == SFML + delete clock->clock; + #elif GRAPHICS_LIBRARY == SDL + SDL_DestroyClock(clock->clock); + #elif GRAPHICS_LIBRARY == OPENGL //using glwf for opengl and vulkan + GL_DestroyClock(clock->clock); + #elif GRAPHICS_LIBRARY == VULKAN + VK_DestroyClock(clock->clock); + #elif GRAPHICS_LIBRARY == DIRECTX + DX_DestroyClock(clock->clock); + #endif + free(clock); +} + +void clock_restart(engine_clock_t *clock) +{ + #if GRAPHICS_LIBRARY == CSFML + sfClock_restart(clock->clock); + #elif GRAPHICS_LIBRARY == SFML + clock->clock->restart(); + #elif GRAPHICS_LIBRARY == SDL + SDL_RestartClock(clock->clock); + #elif GRAPHICS_LIBRARY == OPENGL + GL_RestartClock(clock->clock); + #elif GRAPHICS_LIBRARY == VULKAN + VK_RestartClock(clock->clock); + #elif GRAPHICS_LIBRARY == DIRECTX + DX_RestartClock(clock->clock); + #endif +} + +float clock_get_f_delta_time(engine_clock_t *clock) +{ + #if GRAPHICS_LIBRARY == CSFML + float delta_time = sfTime_asSeconds(sfClock_getElapsedTime(clock->clock)); + return sfClock_restart(clock->clock), delta_time; + #elif GRAPHICS_LIBRARY == SFML + float delta_time = clock->clock->getElapsedTime().asSeconds(); + return clock->clock->restart().asSeconds(), delta_time; + #elif GRAPHICS_LIBRARY == SDL + float delta_time = SDL_GetElapsedTime(clock->clock); + return SDL_RestartClock(clock->clock), delta_time; + #elif GRAPHICS_LIBRARY == OPENGL + float delta_time = GL_GetElapsedTime(clock->clock); + return GL_RestartClock(clock->clock), delta_time; + #elif GRAPHICS_LIBRARY == VULKAN + float delta_time = VK_GetElapsedTime(clock->clock); + return VK_RestartClock(clock->clock), delta_time; + #elif GRAPHICS_LIBRARY == DIRECTX + float delta_time = DX_GetElapsedTime(clock->clock); + return DX_RestartClock(clock->clock), delta_time; + #endif +} diff --git a/Engine/Engine/Clock/engine_clock.h b/Engine/Engine/Clock/engine_clock.h new file mode 100644 index 0000000..e06b95b --- /dev/null +++ b/Engine/Engine/Clock/engine_clock.h @@ -0,0 +1,71 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** engine_clock +*/ + +#ifndef ENGINE_CLOCK_H_ + #define ENGINE_CLOCK_H_ + +//////////////////////////////////////////////////////////// +// Include the other headers of the engine module +//////////////////////////////////////////////////////////// +#include "config.h" + +//////////////////////////////////////////////////////////// +// Include the necessary headers for the clock module +//////////////////////////////////////////////////////////// +#ifdef __cplusplus + #include +#else + #include +#endif + +/** + * @brief Structure containing the clock module + * + * @param clock The clock of the clock module + * @return {clock_t *} - The clock module + */ +typedef struct { + #if GRAPHICS_LIBRARY == CSFML + sfClock *clock; + #elif GRAPHICS_LIBRARY == SFML + sf::Clock *clock; + #elif GRAPHICS_LIBRARY == SDL + SDL_Clock *clock; + #elif GRAPHICS_LIBRARY == OPENGL + GL_Clock *clock; + #elif GRAPHICS_LIBRARY == VULKAN + VK_Clock *clock; + #elif GRAPHICS_LIBRARY == DIRECTX + DX_Clock *clock; + #endif +} engine_clock_t; + +/** + * @brief Create a clock module + * + * @return {engine_clock_t *} - The clock module + */ +extern engine_clock_t *clock_create(void); + +/** + * @brief Destroy a clock module + * + * @param clock {engine_clock_t *} - The clock module + */ +extern void clock_destroy(engine_clock_t *clock); + +/** + * @brief Get the delta time of a clock module + * + * @param clock {engine_clock_t *} - The clock module + * @return {float} - The delta time + */ +extern float clock_get_f_delta_time(engine_clock_t *clock); + +#endif /* !ENGINE_CLOCK_H_ */ diff --git a/Engine/Engine/Event/engine_event.h b/Engine/Engine/Event/engine_event.h new file mode 100644 index 0000000..89085e7 --- /dev/null +++ b/Engine/Engine/Event/engine_event.h @@ -0,0 +1,13 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** engine_event +*/ + +#ifndef ENGINE_EVENT_H_ + #define ENGINE_EVENT_H_ + +#endif /* !ENGINE_EVENT_H_ */ diff --git a/Engine/Engine/Math/Geometry/math_geometry.h b/Engine/Engine/Math/Geometry/math_geometry.h new file mode 100644 index 0000000..c8ee08c --- /dev/null +++ b/Engine/Engine/Math/Geometry/math_geometry.h @@ -0,0 +1,63 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** math_geometry +*/ + +#ifndef MATH_GEOMETRY_H_ + #define MATH_GEOMETRY_H_ + +//////////////////////////////////////////////////////////// +// Include the other headers of the math module +//////////////////////////////////////////////////////////// +#include "math_vector.h" + +//////////////////////////////////////////////////////////// +// Include the headers of the external libraries +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Include necessary headers for the geometry module +//////////////////////////////////////////////////////////// +#ifdef __cplusplus + #include + #include +#else + #include + #include +#endif + +/** + * @brief Structure of a triangle with 3 vertices + * + * @param vertices Triangle vertices (x, y, z, w) + * @param textures Texture coordinates of the triangle (x, y, z) + * @param dp Distance from camera + */ +typedef struct triangle_s { + vector4f vertices[3]; + vector3f textures[3]; + // texture usemtl; + float dp; +} triangle_t; + +/** + * @brief Create a triangle with 3 vertices + * + * @param vertices {vector4f[3]} - The vertices of the triangle + * @param textures {vector3f[3]} - The texture coordinates of the triangle + * @return {triangle_t *} - The triangle + */ +extern triangle_t *geometry_triangle_create(vector4f vertices[3], vector3f textures[3]/*, texture usemtl*/); + +/** + * @brief Destroy a triangle + * + * @param triangle {triangle_t *} - The triangle to destroy + */ +extern void geometry_triangle_destroy(triangle_t *triangle); + +#endif /* !MATH_GEOMETRY_H_ */ diff --git a/Engine/Engine/Math/Geometry/triangle.c b/Engine/Engine/Math/Geometry/triangle.c new file mode 100644 index 0000000..2227f9e --- /dev/null +++ b/Engine/Engine/Math/Geometry/triangle.c @@ -0,0 +1,27 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** triangle +*/ + +#include "math_geometry.h" + +triangle_t *geometry_triangle_create(vector4f vertices[3], vector3f textures[3]/*, texture usemtl*/) +{ + triangle_t *triangle = malloc(sizeof(triangle_t)); + + triangle->vertices[0] = vertices[0]; + triangle->vertices[1] = vertices[1]; + triangle->vertices[2] = vertices[2]; + triangle->textures[0] = textures[0]; + triangle->textures[1] = textures[1]; + triangle->textures[2] = textures[2]; + return triangle; +} +void geometry_triangle_destroy(triangle_t *triangle) +{ + free(triangle); +} diff --git a/Engine/Engine/Math/Matrix/math_matrix.h b/Engine/Engine/Math/Matrix/math_matrix.h new file mode 100644 index 0000000..905614c --- /dev/null +++ b/Engine/Engine/Math/Matrix/math_matrix.h @@ -0,0 +1,90 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** matrix +*/ + +#ifndef MATRIX_H_ + #define MATRIX_H_ + +//////////////////////////////////////////////////////////// +// Include the other headers of the math module +//////////////////////////////////////////////////////////// +#include "math_vector.h" + +//////////////////////////////////////////////////////////// +// Include necessary headers for the matrix module +//////////////////////////////////////////////////////////// +#ifdef __cplusplus + #include + + using namespace std; + extern "C" { +#else + #include +#endif + +//////////////////////////////////////////////////////////// +// Define the default matrix4 of floats +//////////////////////////////////////////////////////////// +#define MATRIX4F_DEFAULT (matrix4f){{{0}}} + +/** + * @brief A 4x4 matrix of floats + * + * @param m {float[4][4]} - The matrix + */ +typedef struct { + float m[4][4]; +} matrix4f; + +/** + * @brief Multiply two matrix4 of floats + * + * @param m {matrix4f} - The first matrix + * @param n {matrix4f} - The second matrix + * @return {matrix4f} - The result matrix + */ +extern matrix4f matrix4_f_mul(matrix4f m, matrix4f n); + +/** + * @brief Multiply a matrix4 of floats and a vector4 of floats + * + * @param m {matrix4f} - The matrix + * @param v {vector4f} - The vector + * @return {vector4f} - The result vector + */ +extern vector4f matrix4_f_mul_vector4_f(matrix4f m, vector4f v); + +/** + * @brief Multiply a matrix4 of floats and a vector3 of floats + * + * @param m {matrix4f} - The matrix + * @param v {vector3f} - The vector + * @return {vector3f} - The result vector + */ +extern vector3f matrix4_f_mul_vector3_f(matrix4f m, vector3f v); + +/** + * @brief Get the quick inverse of a matrix4 of floats + * + * @param m {matrix4f} - The matrix + * @return {matrix4f} - The result matrix + */ +extern matrix4f matrix4_f_quick_inverse(matrix4f m); + +/** + * @brief Print a matrix4 of floats + * + * @param m {matrix4f} - The matrix + */ +extern void matrix4_f_print(matrix4f m); + +#ifdef __cplusplus + } +#endif + +#endif /* !MATRIX_H_ */ diff --git a/Engine/Engine/Math/Matrix/matrix.c b/Engine/Engine/Math/Matrix/matrix.c new file mode 100644 index 0000000..f0fa962 --- /dev/null +++ b/Engine/Engine/Math/Matrix/matrix.c @@ -0,0 +1,70 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** matrix +*/ + +#include "math_matrix.h" +#include + +matrix4f matrix4_f_mul(matrix4f m, matrix4f n) +{ + matrix4f o = MATRIX4F_DEFAULT; + + for (unsigned i = 0; i < 4; i++) + for (unsigned j = 0; j < 4; j++) + for (unsigned k = 0; k < 4; k++) + o.m[i][j] += m.m[i][k] * n.m[k][j]; + + return o; +} + +vector4f matrix4_f_mul_vector4_f(matrix4f m, vector4f v) +{ + vector4f o = VECTOR4F_DEFAULT; + + o.x = v.x * m.m[0][0] + v.y * m.m[1][0] + v.z * m.m[2][0] + v.w * m.m[3][0]; + o.y = v.x * m.m[0][1] + v.y * m.m[1][1] + v.z * m.m[2][1] + v.w * m.m[3][1]; + o.z = v.x * m.m[0][2] + v.y * m.m[1][2] + v.z * m.m[2][2] + v.w * m.m[3][2]; + o.w = v.x * m.m[0][3] + v.y * m.m[1][3] + v.z * m.m[2][3] + v.w * m.m[3][3]; + + return o; +} + +vector3f matrix4_f_mul_vector3_f(matrix4f m, vector3f v) +{ + vector3f o = VECTOR3F_DEFAULT; + + o.x = v.x * m.m[0][0] + v.y * m.m[1][0] + v.z * m.m[2][0]; + o.y = v.x * m.m[0][1] + v.y * m.m[1][1] + v.z * m.m[2][1]; + o.z = v.x * m.m[0][2] + v.y * m.m[1][2] + v.z * m.m[2][2]; + + return o; +} + +matrix4f matrix4_f_quick_inverse(matrix4f m) +{ + matrix4f o = MATRIX4F_DEFAULT; + + memcpy(o.m, m.m, sizeof(float) * 16); + + o.m[3][0] = -(m.m[3][0] * o.m[0][0] + m.m[3][1] * o.m[1][0] + m.m[3][2] * o.m[2][0]); + o.m[3][1] = -(m.m[3][0] * o.m[0][1] + m.m[3][1] * o.m[1][1] + m.m[3][2] * o.m[2][1]); + o.m[3][2] = -(m.m[3][0] * o.m[0][2] + m.m[3][1] * o.m[1][2] + m.m[3][2] * o.m[2][2]); + o.m[0][3] = o.m[1][3] = o.m[2][3] = 0.0f; + o.m[3][3] = 1.0f; + + return o; +} + +void matrix4_f_print(matrix4f m) +{ + printf("[matrix4f]:\n"); + printf("\t%f %f %f %f\n", m.m[0][0], m.m[0][1], m.m[0][2], m.m[0][3]); + printf("\t%f %f %f %f\n", m.m[1][0], m.m[1][1], m.m[1][2], m.m[1][3]); + printf("\t%f %f %f %f\n", m.m[2][0], m.m[2][1], m.m[2][2], m.m[2][3]); + printf("\t%f %f %f %f\n", m.m[3][0], m.m[3][1], m.m[3][2], m.m[3][3]); +} diff --git a/Engine/Engine/Math/Point/math_point.h b/Engine/Engine/Math/Point/math_point.h new file mode 100644 index 0000000..5a86b73 --- /dev/null +++ b/Engine/Engine/Math/Point/math_point.h @@ -0,0 +1,82 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** math_point +*/ + +#ifndef MATH_POINT_H_ + #define MATH_POINT_H_ + +//////////////////////////////////////////////////////////// +// Include the other headers of the math module +//////////////////////////////////////////////////////////// +#include "config.h" + +//////////////////////////////////////////////////////////// +// Include necessary headers for the point module +//////////////////////////////////////////////////////////// +#include + +//////////////////////////////////////////////////////////// +// Define the default point of floats +//////////////////////////////////////////////////////////// +#define POINT_F_DEFAULT (point_f){0, 0} +#define POINT_F_INIT(x, y) (point_f){x, y} + +/** + * @brief Structure containing a 2D point of floats + * + * @param x {float} - The x component of the vector + * @param y {float} - The y component of the vector + */ +typedef struct { + float x, y; +} point_f; + +/** + * @brief Addition of two point of floats + * + * @param v {point_f} - The first point of floats + * @param w {point_f} - The second point of floats + * @return {point_f} - The result of the addition + */ +extern point_f point_f_add(point_f v, point_f w); + +/** + * @brief Substraction of two point of floats + * + * @param v {point_f} - The first point of floats + * @param w {point_f} - The second point of floats + * @return {point_f} - The result of the substraction + */ +extern point_f point_f_sub(point_f v, point_f w); + +/** + * @brief Multiplication of a point of floats and a float + * + * @param v {point_f} - The point of floats + * @param w {float} - The float + * @return {point_f} - The result of the multiplication + */ +extern point_f point_f_mul(point_f v, float w); + +/** + * @brief Division of a point of floats and a float + * + * @param v {point_f} - The point of floats + * @param w {float} - The float + * @return {point_f} - The result of the division + */ +extern point_f point_f_div(point_f v, float w); + +/** + * @brief Print a point of floats in the console + * + * @param v {point_f} - The point of floats + */ +extern void point_f_print(point_f v); + +#endif /* !MATH_POINT_H_ */ diff --git a/Engine/Engine/Math/Point/point.c b/Engine/Engine/Math/Point/point.c new file mode 100644 index 0000000..ebbeba0 --- /dev/null +++ b/Engine/Engine/Math/Point/point.c @@ -0,0 +1,31 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** point +*/ + +#include "math_point.h" +#include + +point_f point_f_add(point_f p, point_f w) { + return (point_f){p.x + w.x, p.y + w.y}; +} + +point_f point_f_sub(point_f p, point_f w) { + return (point_f){p.x - w.x, p.y - w.y}; +} + +point_f point_f_mul(point_f p, float w) { + return (point_f){p.x * w, p.y * w}; +} + +point_f point_f_div(point_f p, float w) { + return (point_f){p.x / w, p.y / w}; +} + +void point_f_print(point_f p) { + printf("[point_f]: (%f, %f)\n", p.x, p.y); +} diff --git a/Engine/Engine/Math/Vector/math_vector.h b/Engine/Engine/Math/Vector/math_vector.h new file mode 100644 index 0000000..a77ef65 --- /dev/null +++ b/Engine/Engine/Math/Vector/math_vector.h @@ -0,0 +1,264 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** math_vector +*/ + +#ifndef MATH_VECTOR_H_ + #define MATH_VECTOR_H_ + +//////////////////////////////////////////////////////////// +// Include the other headers of the math module +//////////////////////////////////////////////////////////// +#include "config.h" + +//////////////////////////////////////////////////////////// +// Include necessary headers for the vector module +//////////////////////////////////////////////////////////// +#include + +//////////////////////////////////////////////////////////// +// Define the default vector4 of floats +//////////////////////////////////////////////////////////// +#define VECTOR4F_DEFAULT (vector4f){0, 0, 0, 0} +#define VECTOR4F_INIT(x, y, z, w) (vector4f){x, y, z, w} + +/** + * @brief Structure containing a 4D vector of floats + * + * @param x {float} - The x component of the vector + * @param y {float} - The y component of the vector + * @param z {float} - The z component of the vector + * @param w {float} - The w component of the vector + */ +typedef struct { + float x, y, z, w; +} vector4f; + +/** + * @brief Addition of two vector4 of floats + * + * @param v {vector4f} - The first vector4 of floats + * @param w {vector4f} - The second vector4 of floats + * @return {vector4f} - The result of the addition + */ +extern vector4f vector4_f_add(vector4f v, vector4f w); + +/** + * @brief Substraction of two vector4 of floats + * + * @param v {vector4f} - The first vector4 of floats + * @param w {vector4f} - The second vector4 of floats + * @return {vector4f} - The result of the substraction + */ +extern vector4f vector4_f_sub(vector4f v, vector4f w); + +/** + * @brief Multiplication of a vector4 of floats and a float + * + * @param v {vector4f} - The vector4 of floats + * @param w {float} - The float + * @return {vector4f} - The result of the multiplication + */ +extern vector4f vector4_f_mul(vector4f v, float w); + +/** + * @brief Division of a vector4 of floats and a float + * + * @param v {vector4f} - The vector4 of floats + * @param w {float} - The float + * @return {vector4f} - The result of the division + */ +extern vector4f vector4_f_div(vector4f v, float w); + + +/** + * @brief Normalise a vector4 of floats (make its length equal to 1) + * + * @param v {vector4f} - The vector4 of floats + * @return vector4f - The result of the normalisation + */ +extern vector4f vector4_f_normalise(vector4f v); + +/** + * @brief Compute the cross product of two vector4 of floats + * + * @param a {vector4f} - The first vector4 of floats + * @param b {vector4f} - The second vector4 of floats + * @return {vector4f} - The result of the cross product + */ +extern vector4f vector4_f_cross_product(vector4f a, vector4f b); + +/** + * @brief Compute the dot product of two vector4 of floats + * + * @param v {vector4f} - The first vector4 of floats + * @param w {vector4f} - The second vector4 of floats + * @return {float} - The result of the dot product + */ +extern float vector4_f_dot_product(vector4f v, vector4f w); + +/** + * @brief Compute the length of a vector4 of floats + * + * @param v {vector4f} - The vector4 of floats + * @return {float} - The length of the vector4 of floats + */ +extern float vector4_f_length(vector4f v); + + +/** + * @brief Compute the intersection of a plane and a line + * + * @param plane_p {vector4f} - The point of the plane + * @param plane_n {vector4f} - The normal of the plane + * @param line_start {vector4f} - The start of the line + * @param line_end {vector4f} - The end of the line + * @return {vector4f} - The intersection of the plane and the line + */ +extern vector4f vector4_f_intersect_plane(vector4f plane_p, vector4f plane_n, vector4f line_start, vector4f line_end); + +/** + * @brief Compute the intersection of a plane and a line + * + * @param plane_p {vector4f} - The point of the plane + * @param plane_n {vector4f} - The normal of the plane + * @param line_start {vector4f} - The start of the line + * @param line_end {vector4f} - The end of the line + * @param t {float *} - The intersection of the plane and the line + * @return {vector4f} - The intersection of the plane and the line + */ +extern vector4f vector4_f_intersect_line(vector4f plane_p, vector4f plane_n, vector4f line_start, vector4f line_end, float *t); + + +/** + * @brief Print a vector4 of floats in the console + * + * @param v {vector4f} - The vector4 of floats + */ +extern void vector4_f_print(vector4f v); + +//////////////////////////////////////////////////////////// +// Define the default vector3 of floats +//////////////////////////////////////////////////////////// +#define VECTOR3F_DEFAULT (vector3f){0, 0, 0} +#define VECTOR3F_INIT(x, y, z) (vector3f){x, y, z} + +/** + * @brief Structure containing a 3D vector of floats + * + * @param x {float} - The x component of the vector + * @param y {float} - The y component of the vector + * @param z {float} - The z component of the vector + */ +typedef struct { + float x, y, z; +} vector3f; + +/** + * @brief Addition of two vector3 of floats + * + * @param v {vector3f} - The first vector3 of floats + * @param w {vector3f} - The second vector3 of floats + * @return {vector3f} - The result of the addition + */ +extern vector3f vector3_f_add(vector3f v, vector3f w); + +/** + * @brief Substraction of two vector3 of floats + * + * @param v {vector3f} - The first vector3 of floats + * @param w {vector3f} - The second vector3 of floats + * @return {vector3f} - The result of the substraction + */ +extern vector3f vector3_f_sub(vector3f v, vector3f w); + +/** + * @brief Multiplication of a vector3 of floats and a float + * + * @param v {vector3f} - The vector3 of floats + * @param w {float} - The float + * @return {vector3f} - The result of the multiplication + */ +extern vector3f vector3_f_mul(vector3f v, float w); + +/** + * @brief Division of a vector3 of floats and a float + * + * @param v {vector3f} - The vector3 of floats + * @param w {float} - The float + * @return {vector3f} - The result of the division + */ +extern vector3f vector3_f_div(vector3f v, float w); + + +/** + * @brief Normalise a vector3 of floats (make its length equal to 1) + * + * @param v {vector3f} - The vector3 of floats + * @return vector3f - The result of the normalisation + */ +extern vector3f vector3_f_normalise(vector3f v); + +/** + * @brief Compute the cross product of two vector3 of floats + * + * @param a {vector3f} - The first vector3 of floats + * @param b {vector3f} - The second vector3 of floats + * @return {vector3f} - The result of the cross product + */ +extern vector3f vector3_f_cross_product(vector3f a, vector3f b); + +/** + * @brief Compute the dot product of two vector3 of floats + * + * @param v {vector3f} - The first vector3 of floats + * @param w {vector3f} - The second vector3 of floats + * @return {float} - The result of the dot product + */ +extern float vector3_f_dot_product(vector3f v, vector3f w); + +/** + * @brief Compute the length of a vector3 of floats + * + * @param v {vector3f} - The vector3 of floats + * @return {float} - The length of the vector3 of floats + */ +extern float vector3_f_length(vector3f v); + + +/** + * @brief Compute the intersection of a plane and a line + * + * @param plane_p {vector3f} - The point of the plane + * @param plane_n {vector3f} - The normal of the plane + * @param line_start {vector3f} - The start of the line + * @param line_end {vector3f} - The end of the line + * @return {vector3f} - The intersection of the plane and the line + */ +extern vector3f vector3_f_intersect_plane(vector3f plane_p, vector3f plane_n, vector3f line_start, vector3f line_end); + +/** + * @brief Compute the intersection of a plane and a line + * + * @param plane_p {vector3f} - The point of the plane + * @param plane_n {vector3f} - The normal of the plane + * @param line_start {vector3f} - The start of the line + * @param line_end {vector3f} - The end of the line + * @param t {float *} - The intersection of the plane and the line + * @return {vector3f} - The intersection of the plane and the line + */ +extern vector3f vector3_f_intersect_line(vector3f plane_p, vector3f plane_n, vector3f line_start, vector3f line_end, float *t); + + +/** + * @brief Print a vector3 of floats in the console + * + * @param v {vector3f} - The vector3 of floats + */ +extern void vector3_f_print(vector3f v); + +#endif /* !MATH_VECTOR_H_ */ diff --git a/Engine/Engine/Math/Vector/vector3.c b/Engine/Engine/Math/Vector/vector3.c new file mode 100644 index 0000000..e6a4618 --- /dev/null +++ b/Engine/Engine/Math/Vector/vector3.c @@ -0,0 +1,76 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** vector3 +*/ + +#include "math_vector.h" +#include + +vector3f vector3_f_add(vector3f v, vector3f w) { + return (vector3f){v.x + w.x, v.y + w.y, v.z + w.z}; +} + +vector3f vector3_f_sub(vector3f v, vector3f w) { + return (vector3f){v.x - w.x, v.y - w.y, v.z - w.z}; +} + +vector3f vector3_f_mul(vector3f v, float w) { + return (vector3f){v.x * w, v.y * w, v.z * w}; +} + +vector3f vector3_f_div(vector3f v, float w) { + return (vector3f){v.x / w, v.y / w, v.z / w}; +} + +vector3f vector3_f_normalise(vector3f v) { + float length = vector3_f_length(v); + return (vector3f){v.x / length, v.y / length, v.z / length}; +} + +vector3f vector3_f_cross_product(vector3f a, vector3f b) { + return (vector3f){ + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x + }; +} + +float vector3_f_dot_product(vector3f v, vector3f w) { + return v.x * w.x + v.y * w.y + v.z * w.z; +} + +float vector3_f_length(vector3f v) { + return sqrtf(vector3_f_dot_product(v, v)); +} + +vector3f vector3_f_intersect_plane(vector3f plane_p, vector3f plane_n, vector3f line_start, vector3f line_end) +{ + plane_n = vector3_f_normalise(plane_n); + float plane_d = -vector3_f_dot_product(plane_n, plane_p); + float ad = vector3_f_dot_product(line_start, plane_n); + float bd = vector3_f_dot_product(line_end, plane_n); + float t = (-plane_d - ad) / (bd - ad); + vector3f line_start_to_end = vector3_f_sub(line_end, line_start); + vector3f line_to_intersect = vector3_f_mul(line_start_to_end, t); + return vector3_f_add(line_start, line_to_intersect); +} + +vector3f vector3_f_intersect_line(vector3f plane_p, vector3f plane_n, vector3f line_start, vector3f line_end, float *t) +{ + plane_n = vector3_f_normalise(plane_n); + float plane_d = -vector3_f_dot_product(plane_n, plane_p); + float ad = vector3_f_dot_product(line_start, plane_n); + float bd = vector3_f_dot_product(line_end, plane_n); + *t = (-plane_d - ad) / (bd - ad); + vector3f line_start_to_end = vector3_f_sub(line_end, line_start); + vector3f line_to_intersect = vector3_f_mul(line_start_to_end, *t); + return vector3_f_add(line_start, line_to_intersect); +} + +void vector3_f_print(vector3f v) { + printf("[vector3f]: (%f, %f, %f)\n", v.x, v.y, v.z); +} diff --git a/Engine/Engine/Math/Vector/vector4.c b/Engine/Engine/Math/Vector/vector4.c new file mode 100644 index 0000000..c4cd769 --- /dev/null +++ b/Engine/Engine/Math/Vector/vector4.c @@ -0,0 +1,77 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** vector4 +*/ + +#include "math_vector.h" +#include + +vector4f vector4_f_add(vector4f v, vector4f w) { + return (vector4f){v.x + w.x, v.y + w.y, v.z + w.z, v.w + w.w}; +} + +vector4f vector4_f_sub(vector4f v, vector4f w) { + return (vector4f){v.x - w.x, v.y - w.y, v.z - w.z, v.w - w.w}; +} + +vector4f vector4_f_mul(vector4f v, float w) { + return (vector4f){v.x * w, v.y * w, v.z * w, v.w * w}; +} + +vector4f vector4_f_div(vector4f v, float w) { + return (vector4f){v.x / w, v.y / w, v.z / w, v.w / w}; +} + +vector4f vector4_f_normalise(vector4f v) { + float length = vector4_f_length(v); + return (vector4f){v.x / length, v.y / length, v.z / length, v.w / length}; +} + +vector4f vector4_f_cross_product(vector4f a, vector4f b) { + return (vector4f){ + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x, + 0 + }; +} + +float vector4_f_dot_product(vector4f v, vector4f w) { + return v.x * w.x + v.y * w.y + v.z * w.z + v.w * w.w; +} + +float vector4_f_length(vector4f v) { + return sqrtf(vector4_f_dot_product(v, v)); +} + +vector4f vector4_f_intersect_plane(vector4f plane_p, vector4f plane_n, vector4f line_start, vector4f line_end) +{ + plane_n = vector4_f_normalise(plane_n); + float plane_d = -vector4_f_dot_product(plane_n, plane_p); + float ad = vector4_f_dot_product(line_start, plane_n); + float bd = vector4_f_dot_product(line_end, plane_n); + float t = (-plane_d - ad) / (bd - ad); + vector4f line_start_to_end = vector4_f_sub(line_end, line_start); + vector4f line_to_intersect = vector4_f_mul(line_start_to_end, t); + return vector4_f_add(line_start, line_to_intersect); +} + +vector4f vector4_f_intersect_line(vector4f plane_p, vector4f plane_n, vector4f line_start, vector4f line_end, float *t) +{ + plane_n = vector4_f_normalise(plane_n); + float plane_d = -vector4_f_dot_product(plane_n, plane_p); + float ad = vector4_f_dot_product(line_start, plane_n); + float bd = vector4_f_dot_product(line_end, plane_n); + *t = (-plane_d - ad) / (bd - ad); + vector4f line_start_to_end = vector4_f_sub(line_end, line_start); + vector4f line_to_intersect = vector4_f_mul(line_start_to_end, *t); + return vector4_f_add(line_start, line_to_intersect); +} + +void vector4_f_print(vector4f v) { + printf("[vector4f]: (%f, %f, %f, %f)\n", v.x, v.y, v.z, v.w); +} diff --git a/Engine/Engine/Math/engine_math.h b/Engine/Engine/Math/engine_math.h new file mode 100644 index 0000000..594ca21 --- /dev/null +++ b/Engine/Engine/Math/engine_math.h @@ -0,0 +1,25 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** math +*/ + +#ifndef MATH_H_ + #define MATH_H_ + +//////////////////////////////////////////////////////////// +// Include the Engine module header for the math module +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Include the other headers of the math module +//////////////////////////////////////////////////////////// +#include "math_point.h" +#include "math_vector.h" +#include "math_matrix.h" +#include "math_geometry.h" + +#endif /* !MATH_H_ */ diff --git a/Engine/Engine/Window/engine_window.h b/Engine/Engine/Window/engine_window.h new file mode 100644 index 0000000..96d67f3 --- /dev/null +++ b/Engine/Engine/Window/engine_window.h @@ -0,0 +1,136 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-13 +** File description: +** window +*/ + +#ifndef WINDOW_H_ + #define WINDOW_H_ + +//////////////////////////////////////////////////////////// +// Include the Engine module header for the window module +//////////////////////////////////////////////////////////// +#include "config.h" +#include "engine_math.h" + +//////////////////////////////////////////////////////////// +// Include necessary headers for the window module +//////////////////////////////////////////////////////////// +#ifdef __cplusplus + #include +#else + #include +#endif + +/** + * @brief Structure containing the window module of the engine + * + * @param window The window of the game engine + */ +typedef struct { + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow *window; + #elif GRAPHICS_LIBRARY == SFML + sf::RenderWindow *window; + #elif GRAPHICS_LIBRARY == SDL + SDL_Window *window; + SDL_Renderer *renderer; + #elif GRAPHICS_LIBRARY == OPENGL + GL_Window *window; + #elif GRAPHICS_LIBRARY == VULKAN + VK_Window *window; + #elif GRAPHICS_LIBRARY == DIRECTX + DX_Window *window; + #endif +} engine_window_t; + +/** + * @brief Create a window module + * + * @param title {char *} - The title of the window + * @param width {unsigned} - The width of the window + * @param height {unsigned} - The height of the window + * @return {engine_window_t *} - The window module + */ +extern engine_window_t *window_create(const char *title, unsigned width, unsigned height); + +/** + * @brief Destroy a window module + * + * @param window {engine_window_t *} - The window module + */ +extern void window_destroy(engine_window_t *window); + +/** + * @brief Check if the window is open + * + * @param window {engine_window_t *} - The window module + * @return {bool} - The status of the window + */ +extern bool window_is_open(engine_window_t *window); + +/** + * @brief Close the window + * + * @param window {engine_window_t *} - The window module + */ +extern void window_close(engine_window_t *window); + +/** + * @brief Clear the window + * + * @param window {engine_window_t *} - The window module + */ +extern void window_clear(engine_window_t *window); + +/** + * @brief Display the window + * + * @param window {engine_window_t *} - The window module + */ +extern void window_display(engine_window_t *window); + +/** + * @brief Get the size of the window + * + * @param window {engine_window_t *} - The window module + * @return {point_f} - The size of the window + */ +extern point_f window_get_size(engine_window_t *window); + +/** + * @brief Get the position of the window + * + * @param window {engine_window_t *} - The window module + * @return {point_f} - The position of the window + */ +extern point_f window_get_position(engine_window_t *window); + +/** + * @brief Set the position of the window + * + * @param window {engine_window_t *} - The window module + * @param position {point_f} - The position of the window + */ +extern void window_set_position(engine_window_t *window, point_f position); + +/** + * @brief Set the size of the window + * + * @param window {engine_window_t *} - The window module + * @param size {point_f} - The size of the window + */ +extern void window_set_size(engine_window_t *window, point_f size); + +/** + * @brief Set the title of the window + * + * @param window {engine_window_t *} - The window module + * @param title {char *} - The title of the window + */ +extern void window_set_title(engine_window_t *window, const char *title); + +#endif /* !WINDOW_H_ */ diff --git a/Engine/Engine/Window/window.c b/Engine/Engine/Window/window.c new file mode 100644 index 0000000..c00a0a3 --- /dev/null +++ b/Engine/Engine/Window/window.c @@ -0,0 +1,175 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** window +*/ + +#include "engine_window.h" + +engine_window_t *window_create(const char *title, unsigned width, unsigned height) +{ + engine_window_t *window = malloc(sizeof(engine_window_t)); + + if (!window) + return (NULL); + + #if GRAPHICS_LIBRARY == CSFML + window->window = sfRenderWindow_create((sfVideoMode){width, height, 32}, title, sfDefaultStyle, NULL); + #elif GRAPHICS_LIBRARY == SFML + window->window = new sf::RenderWindow(sf::VideoMode(width, height, 32), title.c_str()); + #elif GRAPHICS_LIBRARY == SDL + SDL_Init(SDL_INIT_VIDEO); + if (!(window->window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN))) { + SDL_Quit(); + free(window); + return (NULL); + } + if (!(window->renderer = SDL_CreateRenderer(window->window, -1, SDL_RENDERER_ACCELERATED))) { + SDL_DestroyWindow(window->window); + SDL_Quit(); + free(window); + return (NULL); + } + SDL_SetRenderDrawColor(window->renderer, 0, 0, 0, 255); + #elif GRAPHICS_LIBRARY == OPENGL + window->window = glCreateWindow( + title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width, height, SDL_WINDOW_SHOWN); + #elif GRAPHICS_LIBRARY == VULKAN + window->window = vkCreateWindow( + title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width, height, SDL_WINDOW_SHOWN); + #endif + + if (!window->window) { + free(window); + return (NULL); + } + return window; +} + +void window_destroy(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_destroy(window->window); + #elif GRAPHICS_LIBRARY == SFML + delete window->window; + #elif GRAPHICS_LIBRARY == SDL + SDL_DestroyRenderer(window->renderer); + SDL_DestroyWindow(window->window); + SDL_Quit(); + #elif GRAPHICS_LIBRARY == OPENGL + #endif +} + +bool window_is_open(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + return sfRenderWindow_isOpen(window->window); + #elif GRAPHICS_LIBRARY == SFML + return window->window->isOpen(); + #elif GRAPHICS_LIBRARY == SDL + return true; + #elif GRAPHICS_LIBRARY == OPENGL + #endif +} + +void window_close(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_close(window->window); + #elif GRAPHICS_LIBRARY == SFML + window->window->close(); + #elif GRAPHICS_LIBRARY == OPENGL + #endif +} + +void window_clear(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_clear(window->window, sfBlack); + #elif GRAPHICS_LIBRARY == SFML + window->window->clear(sf::Color::Black); + #elif GRAPHICS_LIBRARY == SDL + SDL_RenderClear(window->renderer); + #endif +} + +void window_display(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_display(window->window); + #elif GRAPHICS_LIBRARY == SFML + window->window->display(); + #elif GRAPHICS_LIBRARY == SDL + SDL_RenderPresent(window->renderer); + #endif +} + +point_f window_get_size(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfVector2u size = sfRenderWindow_getSize(window->window); + return (point_f){size.x, size.y}; + #elif GRAPHICS_LIBRARY == SFML + sf::Vector2u size = window->window->getSize(); + return (point_f){size.x, size.y}; + #elif GRAPHICS_LIBRARY == SDL + int w, h; + SDL_GetWindowSize(window->window, &w, &h); + return (point_f){w, h}; + #elif GRAPHICS_LIBRARY == OPENGL + #endif +} + +point_f window_get_position(engine_window_t *window) +{ + #if GRAPHICS_LIBRARY == CSFML + sfVector2i position = sfRenderWindow_getPosition(window->window); + return (point_f){position.x, position.y}; + #elif GRAPHICS_LIBRARY == SFML + sf::Vector2i position = window->window->getPosition(); + return (point_f){position.x, position.y}; + #elif GRAPHICS_LIBRARY == SDL + int x, y; + SDL_GetWindowPosition(window->window, &x, &y); + return (point_f){x, y}; + #elif GRAPHICS_LIBRARY == OPENGL + #endif +} + +void window_set_position(engine_window_t *window, point_f position) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_setPosition(window->window, (sfVector2i){position.x, position.y}); + #elif GRAPHICS_LIBRARY == SFML + window->window->setPosition(sf::Vector2i(position.x, position.y)); + #elif GRAPHICS_LIBRARY == SDL + SDL_SetWindowPosition(window->window, (int)position.x, (int)position.y); + #endif +} + +void window_set_size(engine_window_t *window, point_f size) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_setSize(window->window, (sfVector2u){size.x, size.y}); + #elif GRAPHICS_LIBRARY == SFML + window->window->setSize(sf::Vector2u(size.x, size.y)); + #elif GRAPHICS_LIBRARY == SDL + SDL_SetWindowSize(window->window, (int)size.x, (int)size.y); + #endif +} + +void window_set_title(engine_window_t *window, const char *title) +{ + #if GRAPHICS_LIBRARY == CSFML + sfRenderWindow_setTitle(window->window, title); + #elif GRAPHICS_LIBRARY == SFML + window->window->setTitle(title.c_str()); + #elif GRAPHICS_LIBRARY == SDL + SDL_SetWindowTitle(window->window, title); + #endif +} diff --git a/Engine/Engine/engine.c b/Engine/Engine/engine.c new file mode 100644 index 0000000..990877f --- /dev/null +++ b/Engine/Engine/engine.c @@ -0,0 +1,26 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-17 +** File description: +** engine +*/ + +#include "engine.h" + +engine_t *engine_init(const char *title, unsigned width, unsigned height) +{ + engine_t *engine = malloc(sizeof(engine_t)); + + engine->clock = clock_create(); + engine->window = window_create(title, width, height); + return engine; +} + +void engine_destroy(engine_t *engine) +{ + clock_destroy(engine->clock); + window_destroy(engine->window); + free(engine); +} diff --git a/Engine/Engine/engine.h b/Engine/Engine/engine.h new file mode 100644 index 0000000..0725f30 --- /dev/null +++ b/Engine/Engine/engine.h @@ -0,0 +1,51 @@ +/* +** EPITECH PROJECT, 2023 +** Title: Engine-3D +** Author: MasterLaplace +** Created: 2023-10-12 +** File description: +** engine +*/ + +#ifndef ENGINE_H_ + #define ENGINE_H_ + +//////////////////////////////////////////////////////////// +// Include the appropriate header based on the platform used +//////////////////////////////////////////////////////////// +#include "config.h" + +//////////////////////////////////////////////////////////// +// Include the other headers of the engine module +//////////////////////////////////////////////////////////// +#include "engine_clock.h" +#include "engine_window.h" +#include "engine_math.h" + +/** + * @brief Structure containing the engine module + * + * @param clock {engine_clock_t *} - The clock module + * @param window {window_t *} - The window module + * @return {engine_t *} - The engine module + */ +typedef struct { + engine_clock_t *clock; + engine_window_t *window; +} engine_t; + +/** + * @brief Initialize the engine module + * + * @return {engine_t *} - The engine module + */ +extern engine_t *engine_init(const char *title, unsigned width, unsigned height); + +/** + * @brief Destroy the engine module + * + * @param engine {engine_t *} - The engine module + */ +extern void engine_destroy(engine_t *engine); + +#endif /* !ENGINE_H_ */ diff --git a/Engine/core.c b/Engine/core.c index 8160250..c5fc570 100644 --- a/Engine/core.c +++ b/Engine/core.c @@ -7,8 +7,8 @@ ** core */ +#include "engine.h" #include -#include #ifdef ENGINE_SYSTEM_WINDOWS #include @@ -17,10 +17,19 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine #else int main(int ac, const char *av[]) { #endif + // Initialize the game engine and its components. if (ac != 2) { printf("Usage: ./engine.out [config.xml]\n"); return EXIT_FAILURE; } printf("Loading config file: %s\n", av[1]); + printf("Engine version: %s\n", ENGINE_VERSION_STRING); + engine_t *engine = engine_init(av[1], 600, 600); // using the xml_parser to load the config file + if (!engine) + return EXIT_FAILURE; + + // Clean up resources and perform any necessary shutdown tasks. + engine_destroy(engine); + return EXIT_SUCCESS; } diff --git a/Launcher/Makefile b/Launcher/Makefile index 2f2c496..5c4d991 100644 --- a/Launcher/Makefile +++ b/Launcher/Makefile @@ -17,8 +17,11 @@ PIP = pip3 all: install install: - @$(PIP) freeze | grep -v moddb > ./requirements.txt - @$(PIP) install -r ./requirements.txt + @$(ECHO) $(BOLD) $(GREEN)"\nā–ŗ INSTALL Launcher šŸ“¦ !\n"$(DEFAULT) + @$(PYTHON) -m pip install --upgrade pip -q + @$(PIP) freeze | grep -v moddb > ./requirements.txt 2> /dev/null + @$(PIP) install -r ./requirements.txt -q + @$(ECHO) $(BOLD) $(GREEN)āœ“$(LIGHT_BLUE)" INSTALL Launcher šŸ“¦"$(DEFAULT) lint: @$(PYTHON) -m pylint src/*.py diff --git a/Makefile b/Makefile index 8922d79..35cbcb1 100644 --- a/Makefile +++ b/Makefile @@ -23,14 +23,27 @@ DEFAULT_GRAPHICAL_LIB := csfml SRC_DIR = Engine/ BIN = bin/ +SRC = $(SRC_DIR)Engine/engine.c \ + $(SRC_DIR)Engine/Window/window.c \ + $(SRC_DIR)Engine/Math/Vector/vector4.c \ + $(SRC_DIR)Engine/Math/Vector/vector3.c \ + $(SRC_DIR)Engine/Math/Point/point.c \ + $(SRC_DIR)Engine/Math/Matrix/matrix.c \ + $(SRC_DIR)Engine/Math/Geometry/triangle.c \ + $(SRC_DIR)Engine/Clock/clock.c \ + MAIN = $(SRC_DIR)core.c -OBJ = $(MAIN:.c=.o) +OBJ = $(MAIN:.c=.o) $(SRC:.c=.o) INCLUDES = -iquote ./Libs/LaplaceLib/include -iquote ./Libs/LaplaceLink/include \ -iquote ./Libs/LaplaceMap/include -iquote ./Libs/LaplaceError/include \ - -iquote ./Engine/Engine + -iquote ./Engine/Engine -iquote ./Engine/Engine/Window \ + -iquote ./Engine/Engine/Math/Vector -iquote ./Engine/Engine/Math/Point \ + -iquote ./Engine/Engine/Math/Matrix -iquote ./Engine/Engine/Math/Geometry \ + -iquote ./Engine/Engine/Clock -iquote ./Engine/Config \ + -iquote ./Engine/Engine/Math LIB_NAME = -L ./Libs -l LaplaceLib -l LaplaceLink -l LaplaceMap @@ -90,27 +103,28 @@ CFLAGS = $(FLAGS) $(LDFLAGS) $(OPTI) $(IGNORE) $(D_FLAGS) ifeq ($(OS), linux) CC := gcc +CPP := g++ NAME := $(BIN)engine.out SHARE_NAME := $(BIN)libengine.so TEST_NAME := $(BIN)test_engine.out endif ifeq ($(OS), windows) CC := gcc +CPP := g++ NAME := $(BIN)engine.exe SHARE_NAME := $(BIN)libengine.dll TEST_NAME := $(BIN)test_engine.exe endif -ifeq ($(OS), macos || $(OS), ios) +ifeq ($(OS), macos || $(OS), ios || $(OS), bsd) CC := clang +CPP := clang++ NAME := $(BIN)engine.out SHARE_NAME := $(BIN)libengine.dylib TEST_NAME := $(BIN)test_engine.out endif -ifeq ($(OS), bsd) -CC := clang -NAME := $(BIN)engine.out -SHARE_NAME := $(BIN)libengine.dylib -TEST_NAME := $(BIN)test_engine.out + +ifeq ($(GRAPHICAL_LIB), sfml) +CC := $(CPP) endif SRC_COUNT := $(words $(SRC))