Vector2 partial implementation
This commit is contained in:
@@ -88,6 +88,11 @@ class vector4 : public numeric_vector<4> {};
|
||||
|
||||
class Angle {
|
||||
public:
|
||||
// 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 pitch;
|
||||
float yaw;
|
||||
float roll;
|
||||
@@ -95,26 +100,28 @@ public:
|
||||
return (pitch == a.pitch) && (yaw == a.yaw) && (roll == a.roll);
|
||||
}
|
||||
void clamp() {
|
||||
if (this->x > 89.0f)
|
||||
this->x = 89.0f;
|
||||
if (this->x <= -89.0f)
|
||||
this->x = -89.0f;
|
||||
|
||||
if (this->pitch > 89.0f)
|
||||
this->pitch = 89.0f;
|
||||
if (this->pitch <= -89.0f)
|
||||
this->pitch = -89.0f;
|
||||
//TODO: Make this entirely seamless by getting the amount they rotated passed -180 and +180 by.
|
||||
if (this->y <= -180.0f)
|
||||
this->y = 180.0f;
|
||||
if (this->y >= 180.01f)
|
||||
this->y = -179.9f;
|
||||
|
||||
if (this->z >= 360.0f)
|
||||
this->z = 0.0;
|
||||
if(this->z <= -360.0f)
|
||||
this->z = 0.0;
|
||||
if (this->yaw <= -180.0f)
|
||||
this->yaw = 180.0f;
|
||||
if (this->yaw >= 180.01f)
|
||||
this->yaw = -179.9f;
|
||||
if (this->roll >= 360.0f)
|
||||
this->roll = 0.0;
|
||||
if (this->roll <= -360.0f)
|
||||
this->roll = 0.0;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
// TODO: Implement
|
||||
vector3 unitVector() const;
|
||||
|
||||
Angle movementAngle() {
|
||||
Angle a;
|
||||
|
Reference in New Issue
Block a user