Skip to content

Commit

Permalink
Upload code
Browse files Browse the repository at this point in the history
  • Loading branch information
desatur committed Aug 28, 2024
1 parent 9e2c384 commit a4a4690
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
9 changes: 9 additions & 0 deletions FutureEngine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

namespace Future
{
class FutureEngine
{

};
}
54 changes: 54 additions & 0 deletions Structs/Vector2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <cmath>

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;
}
};
73 changes: 73 additions & 0 deletions Structs/Vector3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <cmath>

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);
}
};

0 comments on commit a4a4690

Please sign in to comment.