feat: enhance adaptive movement with jitter for smoother transitions; simplify movement paths

This commit is contained in:
2026-01-16 14:09:15 -05:00
parent fa500f4c30
commit 4d7dfffc5c
+14 -10
View File
@@ -7,7 +7,7 @@
private static readonly int[] _p;
private static double _perlinTime = 0.0;
private static Point _lastMove = new Point(0, 0);
private static Point _lastMove = new(0, 0);
private static double _windX = 0.0;
private static double _windY = 0.0;
private static double _velocityX = 0.0;
@@ -57,8 +57,8 @@
public static Point CubicBezierMovement(Point start, Point end, double t)
{
t = Clamp01(t);
Point control1 = new Point(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
Point control2 = new Point(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
Point control1 = new(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
Point control2 = new(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
return CubicBezier(start, end, control1, control2, t);
}
@@ -91,14 +91,18 @@
double dx = end.X - start.X;
double dy = end.Y - start.Y;
double distance = Math.Sqrt(dx * dx + dy * dy);
if (distance == 0) return start;
double stepSize = Math.Max(0, sensitivity) * distance;
if (distance < 1) return end;
double maxStep = 50.0 + (sensitivity * 20.0);
double adaptiveStep = sensitivity * (1.0 + (distance / 800.0));
double stepSize = Math.Min(distance * adaptiveStep, maxStep);
stepSize = Math.Min(stepSize, distance);
double directionX = dx / distance;
double directionY = dy / distance;
int newX = (int)Math.Round(start.X + directionX * stepSize);
int newY = (int)Math.Round(start.Y + directionY * stepSize);
return new Point(newX, newY);
double ux = dx / distance;
double uy = dy / distance;
double jitterMag = Math.Min(Math.Sqrt(distance), 20.0) * sensitivity * 0.15;
double jitter = (Random.Shared.NextDouble() - 0.5) * jitterMag;
int nx = (int)Math.Round(start.X + ux * stepSize + (-uy * jitter));
int ny = (int)Math.Round(start.Y + uy * stepSize + (ux * jitter));
return new Point(nx, ny);
}
public static Point PerlinNoiseMovement(Point start, Point end, double t, double amplitudeFraction = 0.2, double frequency = 1.5)
{