Alright, tried implementing it in a for loop... Now it's colliding with itself! Help is appreciated. (Don't mind the other variables, I'm also making a "trail" effect with some of pyrochild's code as reference.)
protected unsafe override void OnRender(Rectangle[] renderRects, int startIndex, int length)
{
Surface destination = DstArgs.Surface;
Surface source = SrcArgs.Surface;
Rectangle bounds = SrcArgs.Bounds;
Surface customSurface = new Surface(source.Width, source.Height);
customSurface.FitSurface(ResamplingAlgorithm.Fant, source);
destination.CopySurface(source, renderRects);
double cx = (source.Width - 1) / 2;
double cy = (source.Height - 1) / 2;
double ix, iy, nx, ny, tx, ty;
int fx, fy;
foreach (Rectangle rect in renderRects)
{
for (
double xOffset = 0, yOffset = 0;
xOffset <= DistanceX && yOffset <= DistanceY;
xOffset += SpacingX, yOffset += SpacingY
)
{
if (IsCancelRequested) return;
float xDirectionOffset = -(float)xOffset * DirectionX;
float yDirectionOffset = -(float)yOffset * DirectionY;
for (int y = rect.Top; y < rect.Bottom; ++y)
{
float sourceY = y + yDirectionOffset;
if (!(bounds.Top <= sourceY && sourceY < bounds.Bottom))
{
continue;
}
ColorBgra* destinationPoint = destination.GetPointAddressUnchecked(rect.Left, y);
ColorBgra* sourcePoint = source.GetPointAddressUnchecked(0, (int)sourceY);
for (int x = rect.Left; x < rect.Right; ++x)
{
double zoom = 1 + ((x + y) * 0.001);
ix = (double)(x) - cx;
iy = (double)(y) - cy;
nx = ix * zoom;
ny = iy * zoom;
tx = nx - ix;
ty = ny - iy;
fx = Math.Min(Math.Max(x + (int)(tx), 0), destination.Width - 1);
fy = Math.Min(Math.Max(y + (int)(ty), 0), destination.Height - 1);
destination[x, y] = destination[fx, fy];
}
}
}
}
}