From a4a46909b1c49fe561b186587271b938991c2b4a Mon Sep 17 00:00:00 2001 From: Kohaku <51972322+kohakow@users.noreply.github.com> Date: Wed, 28 Aug 2024 23:27:36 +0200 Subject: [PATCH] Upload code --- .gitignore | 17 +++++++++++ CMakeLists.txt | 9 ++++++ FutureEngine.cpp | 9 ++++++ Structs/Vector2.cpp | 54 +++++++++++++++++++++++++++++++++ Structs/Vector3.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 FutureEngine.cpp create mode 100644 Structs/Vector2.cpp create mode 100644 Structs/Vector3.cpp diff --git a/.gitignore b/.gitignore index 259148f..f6190b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,20 @@ +# Clion +.idea + +# CMake +**/cmake-build-debug +**/CMakeCache.txt +**/cmake_install.cmake +**/install_manifest.txt +**/CMakeFiles/ +**/CTestTestfile.cmake +**/Makefile +**/*.cbp +**/CMakeScripts +**/compile_commands.json + +include/divisible/* + # Prerequisites *.d diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..511a5d0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.29) +project(Future) + +set(CMAKE_CXX_STANDARD 20) + +add_library(Future STATIC FutureEngine.cpp + Structs/Vector2.cpp + Structs/Vector3.cpp +) diff --git a/FutureEngine.cpp b/FutureEngine.cpp new file mode 100644 index 0000000..3db16cc --- /dev/null +++ b/FutureEngine.cpp @@ -0,0 +1,9 @@ +#include + +namespace Future +{ + class FutureEngine + { + + }; +} diff --git a/Structs/Vector2.cpp b/Structs/Vector2.cpp new file mode 100644 index 0000000..fd594ed --- /dev/null +++ b/Structs/Vector2.cpp @@ -0,0 +1,54 @@ +#include + +struct Vector2 { + float x, y; + + Vector2(float x = 0, float y = 0) { // Ctor + this->x = x; + this->y = y; + } + + // Magnitude of the vector + float magnitude() const { + return std::sqrt(x * x + y * y); + } + + // Normalized vector + Vector2 normalized() const { + float mag = magnitude(); + if (mag == 0) { + return Vector2(0, 0); + } + return Vector2(x / mag, y / mag); + } + + // Dot product + float dot(const Vector2& other) const { + return x * other.x + y * other.y; + } + + // Addition + Vector2 operator+(const Vector2& other) const { + return Vector2(x + other.x, y + other.y); + } + + // Subtraction + Vector2 operator-(const Vector2& other) const { + return Vector2(x - other.x, y - other.y); + } + + // Multiplication by scalar + Vector2 operator*(float scalar) const { + return Vector2(x * scalar, y * scalar); + } + + // Division by scalar + Vector2 operator/(float scalar) const { + return Vector2(x / scalar, y / scalar); + } + + // Equality check + bool operator==(const Vector2& other) const { + return x == other.x && y == other.y; + } +}; \ No newline at end of file diff --git a/Structs/Vector3.cpp b/Structs/Vector3.cpp new file mode 100644 index 0000000..c58e898 --- /dev/null +++ b/Structs/Vector3.cpp @@ -0,0 +1,73 @@ +#include + +struct Vector3 { + float x, y, z; + + Vector3(float x = 0, float y = 0, float z = 0) { // Ctor + this->x = x; + this->y = y; + this->z = z; + } + + // Magnitude of the vector + float magnitude() const { + return std::sqrt(x * x + y * y + z * z); + } + + // Normalized vector + Vector3 normalized() const { + float mag = magnitude(); + if (mag == 0) { + return Vector3(0, 0, 0); + } + return Vector3(x / mag, y / mag, z / mag); + } + + // Dot product + float dot(const Vector3& other) const { + return x * other.x + y * other.y + z * other.z; + } + + // Cross product + Vector3 cross(const Vector3& other) const { + return Vector3( + y * other.z - z * other.y, + z * other.x - x * other.z, + x * other.y - y * other.x + ); + } + + // Addition + Vector3 operator+(const Vector3& other) const { + return Vector3(x + other.x, y + other.y, z + other.z); + } + + // Subtraction + Vector3 operator-(const Vector3& other) const { + return Vector3(x - other.x, y - other.y, z - other.z); + } + + // Multiplication by scalar + Vector3 operator*(float scalar) const { + return Vector3(x * scalar, y * scalar, z * scalar); + } + + // Division by scalar + Vector3 operator/(float scalar) const { + if (scalar == 0) { + // Handle division by zero + return Vector3(0, 0, 0); + } + return Vector3(x / scalar, y / scalar, z / scalar); + } + + // Equality check + bool operator==(const Vector3& other) const { + return x == other.x && y == other.y && z == other.z; + } + + // Inequality check + bool operator!=(const Vector3& other) const { + return !(*this == other); + } +};