Added equality operator for vector2

This commit is contained in:
2023-12-15 11:53:20 -06:00
parent 422ff3be79
commit cd44abd6dc

View File

@@ -3,7 +3,8 @@
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <glm/glm.hpp>
#include <glm/ext/scalar_constants.hpp>
inline float lerp(float a, float b, float t) {
@@ -56,6 +57,12 @@ public:
vector3(const vector3&); // Copy
vector3(vector3&&) = default;
vector3(const vector2&);
vector3 operator=(const vector3& rhs)
{
this->x = rhs.x;
this->y = rhs.y;
this->z = rhs.z;
}
float operator[](std::size_t index) override;
bool IsWithinMarginOfError(const vector3& rhs, float margin=0.001f) const;
bool operator == (const vector3& rhs) const;
@@ -90,11 +97,13 @@ class vector4 : public numeric_vector<4> {};
// http://www.essentialmath.com/GDC2012/GDC2012_JMV_Rotations.pdf
class Angle {
public:
// TODO: Implement separate upper and lower bounds
// Preserves internal value of euler angles, normalizes and clamps the output.
// This does not solve gimbal lock!!!
float GetPitch() const { return std::clamp(pitch%360.f, -pitch_limit, pitch_limit); }
float GetYaw() const { return std::clamp(yaw%360.f, -yaw_limit, yaw_limit); }
float GetRoll() const { return std::clamp(roll%360.f, -roll_limit, roll_limit); }
float GetPitch(float pitch_limit) const { return std::clamp( std::remainderf(pitch,360.f), -pitch_limit, pitch_limit); }
float GetYaw(float yaw_limit) const { return std::clamp(std::remainderf(yaw, 360.f), -yaw_limit, yaw_limit); }
float GetRoll(float roll_limit) const { return std::clamp(std::remainderf(roll, 360.f), -roll_limit, roll_limit); }
float pitch;
float yaw;
float roll;
@@ -120,16 +129,16 @@ public:
// TODO: Euler Angles do not represent a vector, length doesn't apply, nor is this information meaningful for this data type.
// If you need a meaningful representation of length in 3d space, use a vector!!
[[nodiscard]] float length() const {
return sqrt(x * x + y * y + z * z);
return 0;
}
// TODO: Implement
vector3 unitVector() const;
Angle movementAngle() {
Angle a;
a.x = (cos(glm::radians(y)) * cos(glm::radians(x)));
a.y = -sin(glm::radians(x));
a.z = (sin(glm::radians(y)) * cos(glm::radians(x)));
a.pitch = (cos(glm::radians(yaw)) * cos(glm::radians(pitch)));
a.yaw = -sin(glm::radians(pitch));
a.roll = (sin(glm::radians(yaw)) * cos(glm::radians(pitch)));
return a;
}
};
@@ -179,6 +188,18 @@ public:
return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2) + pow(this->z - p.z, 2));
}
};
// The CFrame is fundamentally 4 vectors (position, forward, right, up vector)
class CoordinateFrame
{
glm::mat4x4 matrix;
vector3 getPosition();
vector3 getLookVector();
vector3 getRightVector();
vector3 getUpVector();
AxisAngle GetAxisAngle();
Angle GetEulerAngleXYZ();
Angle GetWorldAngleYZX();
};
struct Movement {
Angle angle;