mirror of
https://github.com/NoelFB/blah.git
synced 2025-04-18 03:46:04 +08:00
added Calc::approach for Vec2
This commit is contained in:
parent
30cfbf203e
commit
d8930f15ac
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <blah/math/vec2.h>
|
||||||
|
|
||||||
namespace Blah
|
namespace Blah
|
||||||
{
|
{
|
||||||
@ -22,7 +23,9 @@ namespace Blah
|
|||||||
|
|
||||||
int rand_int();
|
int rand_int();
|
||||||
|
|
||||||
float approach(float t, float target, float maxDelta);
|
float approach(float t, float target, float delta);
|
||||||
|
|
||||||
|
Vec2 approach(const Vec2& t, const Vec2& target, float delta);
|
||||||
|
|
||||||
float clamp(float t, float min, float max);
|
float clamp(float t, float min, float max);
|
||||||
|
|
||||||
|
@ -31,9 +31,16 @@ int Calc::rand_int()
|
|||||||
return rand();
|
return rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Calc::approach(float t, float target, float maxDelta)
|
float Calc::approach(float t, float target, float delta)
|
||||||
{
|
{
|
||||||
return t < target ? min(t + maxDelta, target) : max(t - maxDelta, target);
|
return t < target ? min(t + delta, target) : max(t - delta, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 Calc::approach(const Vec2& t, const Vec2& target, float delta)
|
||||||
|
{
|
||||||
|
if ((target - t).length() <= delta)
|
||||||
|
return target;
|
||||||
|
return t + (target - t).normal() * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Calc::clamp(float t, float min, float max)
|
float Calc::clamp(float t, float min, float max)
|
||||||
|
Loading…
Reference in New Issue
Block a user