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 readonly int[] _p;
private static double _perlinTime = 0.0; 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 _windX = 0.0;
private static double _windY = 0.0; private static double _windY = 0.0;
private static double _velocityX = 0.0; private static double _velocityX = 0.0;
@@ -57,8 +57,8 @@
public static Point CubicBezierMovement(Point start, Point end, double t) public static Point CubicBezierMovement(Point start, Point end, double t)
{ {
t = Clamp01(t); t = Clamp01(t);
Point control1 = new Point(start.X + (end.X - start.X) / 3, start.Y + (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 Point(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (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); return CubicBezier(start, end, control1, control2, t);
} }
@@ -91,14 +91,18 @@
double dx = end.X - start.X; double dx = end.X - start.X;
double dy = end.Y - start.Y; double dy = end.Y - start.Y;
double distance = Math.Sqrt(dx * dx + dy * dy); double distance = Math.Sqrt(dx * dx + dy * dy);
if (distance == 0) return start; if (distance < 1) return end;
double stepSize = Math.Max(0, sensitivity) * distance; 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); stepSize = Math.Min(stepSize, distance);
double directionX = dx / distance; double ux = dx / distance;
double directionY = dy / distance; double uy = dy / distance;
int newX = (int)Math.Round(start.X + directionX * stepSize); double jitterMag = Math.Min(Math.Sqrt(distance), 20.0) * sensitivity * 0.15;
int newY = (int)Math.Round(start.Y + directionY * stepSize); double jitter = (Random.Shared.NextDouble() - 0.5) * jitterMag;
return new Point(newX, newY); 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) public static Point PerlinNoiseMovement(Point start, Point end, double t, double amplitudeFraction = 0.2, double frequency = 1.5)
{ {