990 B
990 B
title | date | weight |
---|---|---|
Sweep Test | 2020-07-18T12:37:29-07:00 | 15 |
Sweep testing is an efficient way to check collision positions on moving objects.
At the moment, Bonk only implements sweep testing on Rectangles.
Example:
var rectangle = new Rectangle(-2, -2, 4, 4);
var transform = new Transform2D(new Position2D(-6, 0));
var otherRectangle = new Rectangle(-2, -2, 4, 4);
var otherTransform = new Transform2D(new Position2D(6, 0));
var farthestRectangle = new Rectangle(-2, -2, 4, 4);
var farthestTransform = new Transform2D(new Position2D(12, 0));
var downRectangle = new Rectangle(-6, -2, 12, 4);
var downTransform = new Transform2D(new Position2D(-6, 20));
var spatialHash = new SpatialHash<int>(16);
spatialHash.Insert(1, otherRectangle, otherTransform);
spatialHash.Insert(2, farthestRectangle, farthestTransform);
spatialHash.Insert(3, downRectangle, downTransform);
var result = SweepTest.Test(spatialHash, rectangle, transform, new Vector2(12, 0)); // hits