Package org.lazywizard.lazylib
Class CollisionUtils
Object
CollisionUtils
Contains methods for line intersection, bounds and collision detection tests.
- Since:
- 1.0
- Author:
- LazyWizard
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleangetCollides(Vector2f lineStart, Vector2f lineEnd, Vector2f circleCenter, float circleRadius) Checks if a line connects with a circle.static Vector2fgetCollisionPoint(Vector2f lineStart, Vector2f lineEnd, CombatEntityAPI target) Finds the part of the ship that would be intersected by a given path.static Vector2fgetCollisionPoint(Vector2f start1, Vector2f end1, Vector2f start2, Vector2f end2) Finds the point of intersection between two lines.static Vector2fgetNearestPointOnBounds(Vector2f source, CombatEntityAPI entity) Returns the closest point on aCombatEntityAPI's collision bounds to a point.static booleanisPointOnSegment(Vector2f point, BoundsAPI.SegmentAPI segment) Check if a point is along aBoundsAPI.SegmentAPI.static booleanisPointWithinBounds(Vector2f point, CombatEntityAPI entity) Checks if a point is inside or on the bounds of aCombatEntityAPI.static booleanisPointWithinCollisionCircle(Vector2f point, CombatEntityAPI entity) Checks if a point is inside the collision circle of aCombatEntityAPI.
-
Method Details
-
getCollisionPoint
@Nullable public static Vector2f getCollisionPoint(Vector2f lineStart, Vector2f lineEnd, CombatEntityAPI target) Finds the part of the ship that would be intersected by a given path.Important note: if the line is completely within
target's bounds, no collision will be detected!- Parameters:
target- The CombatEntityAPI to check collision with.lineStart- The start of the line to test collision with.lineEnd- The end of the line to test collision with.- Returns:
- The
Vector2fof the point the line would hit at, ornullif it doesn't hit. - Since:
- 1.0
-
getCollisionPoint
@Nullable public static Vector2f getCollisionPoint(Vector2f start1, Vector2f end1, Vector2f start2, Vector2f end2) Finds the point of intersection between two lines. Accurate to within 1/3 su.- Parameters:
start1- The start of the first line to test collision with.end1- The end of the first line to test collision with.start2- The start of the second line to test collision with.end2- The end of the second line to test collision with.- Returns:
- The
Vector2fthat the two lines intersect at,nullif they don't collide. - Since:
- 1.0
-
getCollides
public static boolean getCollides(Vector2f lineStart, Vector2f lineEnd, Vector2f circleCenter, float circleRadius) Checks if a line connects with a circle.- Parameters:
lineStart- The start point of the line to test.lineEnd- The end point of the line to test.circleCenter- The center point of the circle.circleRadius- The radius of the circle.- Returns:
trueif the line collides with the circle,falseotherwise.- Since:
- 1.0
-
getNearestPointOnBounds
Returns the closest point on aCombatEntityAPI's collision bounds to a point. If the entity lacks collision bounds, the closest point on its collision radius will be returned instead.- Parameters:
source- The point to check distance from.entity- The entity whose bounds will be checked.- Returns:
- The closest point to
sourceonentity'sBoundsAPI, or the closest point on its collision radius if it lacks collision bounds. - Since:
- 2.3
-
isPointWithinCollisionCircle
Checks if a point is inside the collision circle of aCombatEntityAPI.- Parameters:
point- TheVector2fto check.entity- TheCombatEntityAPIwhoseBoundsAPIwe are checking against.- Returns:
trueifpointis within the collision circle ofentity,falseotherwise.- Since:
- 1.4
-
isPointOnSegment
Check if a point is along aBoundsAPI.SegmentAPI. Accurate to within 1/3 su, useMathUtils.isPointOnLine(Vector2f, Vector2f, Vector2f)if you need higher precision.- Parameters:
point- The point to check.segment- TheBoundsAPI.SegmentAPIto check for collision with.- Returns:
trueif the point is along the line,falseotherwise.- Since:
- 1.6b
-
isPointWithinBounds
Checks if a point is inside or on the bounds of aCombatEntityAPI.- Parameters:
point- TheVector2fto check.entity- TheCombatEntityAPIwhoseBoundsAPIwe are checking against.- Returns:
trueifpointis within or on the bounds ofentity,falseotherwise.- Since:
- 1.0
-