mirror of
				https://github.com/NoelFB/blah.git
				synced 2025-11-03 01:31:33 +08:00 
			
		
		
		
	angle utility methods
This commit is contained in:
		@ -119,6 +119,12 @@ float Calc::angle_diff(float radians_a, float radians_b)
 | 
			
		||||
	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)
 | 
			
		||||
{
 | 
			
		||||
	return a + (b - a) * t;
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,8 @@ namespace Blah
 | 
			
		||||
		float snap(float val, float interval);
 | 
			
		||||
 | 
			
		||||
		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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,17 @@ Vec2 Vec2::normal() const
 | 
			
		||||
	float length = this->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_squared() const { return x * x + y * y; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,8 @@ namespace Blah
 | 
			
		||||
		bool operator !=(const Vec2& rhs);
 | 
			
		||||
		
 | 
			
		||||
		Vec2 normal() const;
 | 
			
		||||
		Vec2 turn_right() const;
 | 
			
		||||
		Vec2 turn_left() const;
 | 
			
		||||
		float length() const;
 | 
			
		||||
		float length_squared() const;
 | 
			
		||||
		Vec2 perpendicular() const;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user