mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-29 17:08:56 +08:00
angle utility methods
This commit is contained in:
parent
1af8669441
commit
474ee631b2
|
@ -119,6 +119,12 @@ float Calc::angle_diff(float radians_a, float radians_b)
|
||||||
return mod((radians_b - radians_a) + PI, TAU) - PI;
|
return mod((radians_b - radians_a) + PI, TAU) - PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Calc::angle_lerp(float radians_a, float radians_b, float p)
|
||||||
|
{
|
||||||
|
const auto shortest_angle = mod(mod(radians_b - radians_a, TAU) + (TAU + PI), TAU) - PI;
|
||||||
|
return radians_a + mod(shortest_angle * p, TAU);
|
||||||
|
}
|
||||||
|
|
||||||
float Calc::lerp(float a, float b, float t)
|
float Calc::lerp(float a, float b, float t)
|
||||||
{
|
{
|
||||||
return a + (b - a) * t;
|
return a + (b - a) * t;
|
||||||
|
|
|
@ -61,6 +61,8 @@ namespace Blah
|
||||||
float snap(float val, float interval);
|
float snap(float val, float interval);
|
||||||
|
|
||||||
float angle_diff(float radians_a, float radians_b);
|
float angle_diff(float radians_a, float radians_b);
|
||||||
|
|
||||||
|
float angle_lerp(float radians_a, float radians_b, float p);
|
||||||
|
|
||||||
float lerp(float a, float b, float t);
|
float lerp(float a, float b, float t);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,17 @@ Vec2 Vec2::normal() const
|
||||||
float length = this->length();
|
float length = this->length();
|
||||||
return Vec2(x / length, y / length);
|
return Vec2(x / length, y / length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vec2 Vec2::turn_right() const
|
||||||
|
{
|
||||||
|
return Vec2(y, -x);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 Vec2::turn_left() const
|
||||||
|
{
|
||||||
|
return Vec2(-y, x);
|
||||||
|
}
|
||||||
|
|
||||||
float Vec2::length() const { return sqrtf(x * x + y * y); }
|
float Vec2::length() const { return sqrtf(x * x + y * y); }
|
||||||
float Vec2::length_squared() const { return x * x + y * y; }
|
float Vec2::length_squared() const { return x * x + y * y; }
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace Blah
|
||||||
bool operator !=(const Vec2& rhs);
|
bool operator !=(const Vec2& rhs);
|
||||||
|
|
||||||
Vec2 normal() const;
|
Vec2 normal() const;
|
||||||
|
Vec2 turn_right() const;
|
||||||
|
Vec2 turn_left() const;
|
||||||
float length() const;
|
float length() const;
|
||||||
float length_squared() const;
|
float length_squared() const;
|
||||||
Vec2 perpendicular() const;
|
Vec2 perpendicular() const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user