-
Notifications
You must be signed in to change notification settings - Fork 3
Area3d
Area3d is the interface used to provide efficient raycasting methods to arbitrary 3d shapes.
The most common usage of this interface would be casting rays to intersect an area3d.
Here is an example:
// Create a rectangular prism with random coordinates
Area3d rectangularPrism = Area3dRectangularPrism.of(
Math.random(), Math.random(), Math.random(), // Min position
Math.random(), Math.random(), Math.random() // Max position
);
// Cast a ray though it, and check if it was intersected
Vector3d intersection = rectangularPrism.lineIntersection(
Math.random(), Math.random(), Math.random(), // Line point
Math.random(), Math.random(), Math.random() // Line direction
);
System.out.println("Line Intersected: " + (intersection != null));
These systems are particularly useful for entity bounding boxes in 3d games.
Area3ds can change their properties at any time. Therefore they are useful to use in relation to persistent entities within 3d games that have variable spatial properties. However by nature, immutable shapes are also supported and work just as well, assuming you compensate for the origin point.
An example of a mutable entity can be found in our demo package here.
Using this example found in the demo package, you can register a conversion between ExampleRaycastEntity
and Area3d
like so:
Area3d.CONVERTER.register(ExampleRaycastEntity.class, ExampleRaycastEntity::getBoundingBox);
Then you can convert between them efficiently like so:
Area3d entityArea = Area3d.CONVERTER.from(null);
// Now we can perform intersections
double[] intersection = entityArea.lineIntersection(...);
This works because the bounding box class returned by ExampleRaycastEntity#getBoundingBox
is an instance of Area3d
, and can therefore be given to Area3d.CONVERTER#register
.
Rayfast is a geometry library designed for use in java game servers. It features efficient ray and block casting.