Fixed Vector2::Rotation

This commit is contained in:
Pascal Serrarens 2023-01-25 15:54:41 +01:00
parent 71bbef7d13
commit 4448ee150d
2 changed files with 12 additions and 16 deletions

View File

@ -8,8 +8,7 @@
/// <summary> /// <summary>
/// A polar vector /// A polar vector
/// </summary> /// </summary>
/// This will use the polar coordinate system consisting of a angle from a /// This will use the polar coordinate system consisting of a angle from a reference direction and a distance.
/// reference direction and a distance.
struct Polar { struct Polar {
public: public:
/// <summary> /// <summary>
@ -44,7 +43,7 @@ struct Polar {
/// </summary> /// </summary>
/// This will rotate the vector by 180 degrees. Distance will stay the same. /// This will rotate the vector by 180 degrees. Distance will stay the same.
/// <returns>The negated vector</returns> /// <returns>The negated vector</returns>
Polar operator-(); Polar operator-();
/// <summary> /// <summary>
/// Substract a polar vector from this coordinate /// Substract a polar vector from this coordinate
@ -65,8 +64,7 @@ struct Polar {
/// </summary> /// </summary>
/// <param name="factor">The scaling factor</param> /// <param name="factor">The scaling factor</param>
/// <returns>The scaled vector</returns> /// <returns>The scaled vector</returns>
/// This operation will scale the distance of the vector. The angle will be /// This operation will scale the distance of the vector. The angle will be unaffected.
/// unaffected.
Polar operator*(float factor) const; Polar operator*(float factor) const;
/// <summary> /// <summary>
@ -74,8 +72,7 @@ struct Polar {
/// </summary> /// </summary>
/// <param name="factor">The scaling factor</param> /// <param name="factor">The scaling factor</param>
/// <returns>The scaled vector</returns> /// <returns>The scaled vector</returns>
/// This operation will scale the distance of the vector. The angle will be /// This operation will scale the distance of the vector. The angle will be unaffected.
/// unaffected.
Polar operator/(const float& factor); Polar operator/(const float& factor);
/// <summary> /// <summary>

View File

@ -118,15 +118,15 @@ float Vector2::SignedAngle(Vector2 from, Vector2 to) {
return (angleTo - angleFrom) * Angle::Rad2Deg; return (angleTo - angleFrom) * Angle::Rad2Deg;
} }
Vector2 Rotate(Vector2 v, float angle) { Vector2 Vector2::Rotate(Vector2 v, float angle) {
float sin = (float)sinf(angle * Angle::Deg2Rad); float sin = (float)sinf(angle * Angle::Deg2Rad);
float cos = (float)cosf(angle * Angle::Deg2Rad); float cos = (float)cosf(angle * Angle::Deg2Rad);
float tx = v.x; float tx = v.x;
float ty = v.y; float ty = v.y;
v.x = (cos * tx) - (sin * ty); v.x = (cos * tx) - (sin * ty);
v.y = (sin * tx) + (cos * ty); v.y = (sin * tx) + (cos * ty);
return v; return v;
} }
Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) { Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) {
@ -137,4 +137,3 @@ Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) {
float Vector2::ToFactor(Vector2 a, Vector2 b) { float Vector2::ToFactor(Vector2 a, Vector2 b) {
return (1 - Vector2::Dot(a, b)) / 2; return (1 - Vector2::Dot(a, b)) / 2;
} }