Class Bresenham3DRaycastCollisionDetector<P extends com.github.tommyettinger.crux.Point3<P>>
java.lang.Object
com.github.tommyettinger.gand.smoothing.Bresenham3DRaycastCollisionDetector<P>
- Type Parameters:
P
- typicallyPointI3
orPointF3
- All Implemented Interfaces:
RaycastCollisionDetector<P>
public class Bresenham3DRaycastCollisionDetector<P extends com.github.tommyettinger.crux.Point3<P>>
extends Object
implements RaycastCollisionDetector<P>
A raycast collision detector used for path smoothing in 3D, with cells considered passable if a predicate returns
true. This treats diagonally-connected passable cells as connected. It uses Bresenham's line algorithm.
See Wikipedia for more info.
This is typically used by passing in a lambda that either looks up a value in a 3D array (and should check the bounds of the array against the indices given), or sets a
This is typically used by passing in a lambda that either looks up a value in a 3D array (and should check the bounds of the array against the indices given), or sets a
PointI3
with the int
parameters and looks that up in a map or set. The former might look like:
(x, y, z) -> x >= 0 && x < booleanWorld.length && y >= 0 && y < booleanWorld[x].length && z >= 0 && z < booleanWorld[x][y].length && booleanWorld[x][y][z]
.-
Constructor Summary
ConstructorDescriptionCreates a Bresenham3DRaycastCollisionDetector that uses the givenpredicate
to determine if an x,y,z cell is passable. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Draws a line using Bresenham's line algorithm to see if all cells in the line are passable; if any cell was not passable, then this returns true (meaning there is a collision).static <P extends com.github.tommyettinger.crux.Point3<P>>
booleancollides
(com.github.tommyettinger.crux.PointPair<P> ray, IntIntIntPredicate predicate) Draws a line using Bresenham's line algorithm to see if all cells in the line are passable; if any cell was not passable, then this returns true (meaning there is a collision).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.tommyettinger.gand.smoothing.RaycastCollisionDetector
findCollision
-
Constructor Details
-
Bresenham3DRaycastCollisionDetector
Creates a Bresenham3DRaycastCollisionDetector that uses the givenpredicate
to determine if an x,y,z cell is passable.
predicate
is typically a lambda that either looks up a value in a 3D array (and should check the bounds of the array against the indices given), or sets aPointI2
with the int parameters and looks that up in a map or set. The former might look like:(x, y, z) -> x >= 0 && x < booleanWorld.length && y >= 0 && y < booleanWorld[x].length && z >= 0 && z < booleanWorld[x][y].length && booleanWorld[x][y][z]
.- Parameters:
predicate
- should bounds-check an x,y,z point and return true if it is considered passable
-
-
Method Details
-
collides
Draws a line using Bresenham's line algorithm to see if all cells in the line are passable; if any cell was not passable, then this returns true (meaning there is a collision). If the point type this uses allows floating-point values for coordinates, then this rounds coordinates to their nearest integers.
See Wikipedia for more info.- Specified by:
collides
in interfaceRaycastCollisionDetector<P extends com.github.tommyettinger.crux.Point3<P>>
- Parameters:
ray
- the ray to cast; will not be modified- Returns:
- true if any cell in the line is blocked, as per the given predicate
-
collides
public static <P extends com.github.tommyettinger.crux.Point3<P>> boolean collides(com.github.tommyettinger.crux.PointPair<P> ray, IntIntIntPredicate predicate) Draws a line using Bresenham's line algorithm to see if all cells in the line are passable; if any cell was not passable, then this returns true (meaning there is a collision). If the point type this uses allows floating-point values for coordinates, then this rounds coordinates to their nearest integers.
See Wikipedia for more info.- Parameters:
ray
- the ray to cast; will not be modifiedpredicate
- should bounds-check an x,y,z point and return true if it is considered passable- Returns:
- true if any cell in the line is blocked, as per the given predicate
-