Vector2 partial implementation

This commit is contained in:
scientiist
2023-12-13 21:16:54 -06:00
parent 364fd7fd9a
commit 677bb1932c
3 changed files with 65 additions and 10 deletions

View File

@@ -4,7 +4,7 @@
#include <fstream>
#include <sstream>
#include <iostream>
#include "../vector3.h"
#include "../vector.h"
#include "../../engine/engine.h"
#include "../entityList.h"
//A "scripted move" is a vector of points and angles that function as keyframes.

View File

@@ -22,22 +22,40 @@ class vector2 : public numeric_vector<2>
public:
float x = 0;
float y = 0;
float z = 0;
vector2();
vector2(float X, float Y) : x(X), y(Y) {}
vector2(const vector2&) = default; // Copy Constructor
vector2(vector2&&) = default; // Move Constructor
float operator[](std::size_t index) override;
bool IsWithinMarginOfError(const vector2& rhs, float margin=0.001f) const;
bool operator == (const vector2& rhs) const;
bool operator != (const vector2& rhs) const;
vector2 min(const vector2& min) const;
vector2 max(const vector2& max) const;
vector2 clamp(const vector2& min, const vector2& max) const;
float distance(const vector2& to) const;
float length() const;
float lengthSquared() const;
float magnitude() const;
float dot(const vector2& rhs) const;
vector2 project(const vector2& rhs);
vector2 normalize() const;
vector2 lerp(const vector2& rhs, float alpha) const;
vector2 operator+(const vector2& rhs) const;
vector2 operator-(const vector2& rhs) const;
vector2 operator*(float rhs) const;
vector2 operator/(float rhs) const;
vector2 operator+() const;
vector2 operator-() const;
};
class vector3 : public numeric_vector<3>
{
public:
float x = 0;
float y = 0;
float z = 0;
class vector3 : public numeric_vector<3> {
public:
vector3() : x(0), y(0), z(0) {}
vector3(float X, float Y, float Z): x(X), y(Y), z(Z) {}
vector3(const vector3&); // Copy
vector3(vector3&&) = default;
vector3(const vector2&);
float operator[](std::size_t index) override;
bool IsWithinMarginOfError(const vector3& rhs, float margin=0.001f) const;
bool operator == (const vector3& rhs) const;
@@ -60,6 +78,10 @@ public:
vector3 operator/(float rhs) const;
vector3 operator+() const;
vector3 operator-() const;
public:
float x = 0;
float y = 0;
float z = 0;
};
class vector4 : public numeric_vector<4> {};

View File

@@ -1,5 +1,37 @@
#include <types/vector3.h>
#include <types/vector.h>
#pragma region vector2
vector2 vector2::operator+(const vector2& rhs) const
{
return {this->x + rhs.x, this->y + rhs.y};
}
vector2 vector2::operator-(const vector2& rhs) const
{
return {this->x - rhs.x, this->y - rhs.y};
}
vector2 vector2::operator*(float rhs) const
{
return {
this->x * rhs,
this->y * rhs
};
}
vector2 vector2::operator/(float rhs) const
{
return {
this->x / rhs,
this->y / rhs
};
}
#pragma endregion
#pragma region vector3
vector3 vector3::operator+(const vector3& rhs) const
{
return {this->x + rhs.x, this->y + rhs.y, this->z + rhs.z};
@@ -147,3 +179,4 @@ vector3 vector3::lerp(const vector3& goal, float alpha) const
#pragma endregion