-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <iostream> | ||
|
||
namespace Future | ||
{ | ||
class FutureEngine | ||
{ | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |