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

View File

@ -118,15 +118,15 @@ float Vector2::SignedAngle(Vector2 from, Vector2 to) {
return (angleTo - angleFrom) * Angle::Rad2Deg;
}
Vector2 Rotate(Vector2 v, float angle) {
float sin = (float)sinf(angle * Angle::Deg2Rad);
float cos = (float)cosf(angle * Angle::Deg2Rad);
Vector2 Vector2::Rotate(Vector2 v, float angle) {
float sin = (float)sinf(angle * Angle::Deg2Rad);
float cos = (float)cosf(angle * Angle::Deg2Rad);
float tx = v.x;
float ty = v.y;
v.x = (cos * tx) - (sin * ty);
v.y = (sin * tx) + (cos * ty);
return v;
float tx = v.x;
float ty = v.y;
v.x = (cos * tx) - (sin * ty);
v.y = (sin * tx) + (cos * ty);
return v;
}
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) {
return (1 - Vector2::Dot(a, b)) / 2;
}