Class AABBf
- java.lang.Object
-
- org.joml.AABBf
-
- All Implemented Interfaces:
Externalizable,Serializable
public class AABBf extends Object implements Externalizable
Represents an axis-aligned box defined via the minimum and maximum corner coordinates.- Author:
- Kai Burjack
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description floatmaxXThe x coordinate of the maximum corner.floatmaxYThe y coordinate of the maximum corner.floatmaxZThe z coordinate of the maximum corner.floatminXThe x coordinate of the minimum corner.floatminYThe y coordinate of the minimum corner.floatminZThe z coordinate of the minimum corner.
-
Constructor Summary
Constructors Constructor Description AABBf()Create a newAABBfrepresenting the box with(minX, minY, minZ)=(+inf, +inf, +inf)and(maxX, maxY, maxZ)=(-inf, -inf, -inf).AABBf(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)Create a newAABBfwith the given minimum and maximum corner coordinates.AABBf(AABBf source)Create a newAABBfas a copy of the givensource.AABBf(Vector3fc min, Vector3fc max)Create a newAABBfwith the given minimum and maximum corner coordinates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AABBfcorrectBounds()Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping them if necessary.booleanequals(Object obj)floatgetMax(int component)Get the maximum corner coordinate of the given component.floatgetMin(int component)Get the minimum corner coordinate of the given component.inthashCode()intintersectLineSegment(float p0X, float p0Y, float p0Z, float p1X, float p1Y, float p1Z, Vector2f result)Determine whether the undirected line segment with the end points(p0X, p0Y, p0Z)and(p1X, p1Y, p1Z)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.intintersectLineSegment(LineSegmentf lineSegment, Vector2f result)Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.booleanintersectRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ, Vector2f result)Determine whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.booleanintersectRay(Rayf ray, Vector2f result)Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.voidreadExternal(ObjectInput in)AABBfsetMax(float maxX, float maxY, float maxZ)Set the maximum corner coordinates.AABBfsetMax(Vector3fc max)Set the maximum corner coordinates.AABBfsetMin(float minX, float minY, float minZ)Set the minimum corner coordinates.AABBfsetMin(Vector3fc min)Set the minimum corner coordinates.booleantestAABB(AABBf other)Test whetherthisandotherintersect.booleantestPlane(float a, float b, float c, float d)Test whether the plane given via its plane equationa*x + b*y + c*z + d = 0intersects this AABB.booleantestPlane(Planef plane)Test whether the given plane intersects this AABB.booleantestPoint(float x, float y, float z)Test whether the point(x, y, z)lies inside this AABB.booleantestPoint(Vector3fc point)Test whether the given point lies inside this AABB.booleantestRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ)Test whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB.booleantestRay(Rayf ray)Test whether the given ray intersects this AABB.booleantestSphere(float centerX, float centerY, float centerZ, float radiusSquared)Test whether this AABB intersects the given sphere with equation(x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0.booleantestSphere(Spheref sphere)Test whether this AABB intersects the given sphere.StringtoString()Return a string representation of this AABB.StringtoString(NumberFormat formatter)Return a string representation of this AABB by formatting the vector components with the givenNumberFormat.AABBftransform(Matrix4fc m)AABBftransform(Matrix4fc m, AABBf dest)AABBftranslate(float x, float y, float z)Translatethisby the vector(x, y, z).AABBftranslate(float x, float y, float z, AABBf dest)Translatethisby the vector(x, y, z)and store the result indest.AABBftranslate(Vector3fc xyz)Translatethisby the given vectorxyz.AABBftranslate(Vector3fc xyz, AABBf dest)Translatethisby the given vectorxyzand store the result indest.AABBfunion(float x, float y, float z)Setthisto the union ofthisand the given point(x, y, z).AABBfunion(float x, float y, float z, AABBf dest)Compute the union ofthisand the given point(x, y, z)and store the result indest.AABBfunion(AABBf other)Setthisto the union ofthisandother.AABBfunion(AABBf other, AABBf dest)Compute the union ofthisandotherand store the result indest.AABBfunion(Vector3fc p)Setthisto the union ofthisand the given pointp.AABBfunion(Vector3fc p, AABBf dest)Compute the union ofthisand the given pointpand store the result indest.voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
minX
public float minX
The x coordinate of the minimum corner.
-
minY
public float minY
The y coordinate of the minimum corner.
-
minZ
public float minZ
The z coordinate of the minimum corner.
-
maxX
public float maxX
The x coordinate of the maximum corner.
-
maxY
public float maxY
The y coordinate of the maximum corner.
-
maxZ
public float maxZ
The z coordinate of the maximum corner.
-
-
Constructor Detail
-
AABBf
public AABBf()
Create a newAABBfrepresenting the box with(minX, minY, minZ)=(+inf, +inf, +inf)and(maxX, maxY, maxZ)=(-inf, -inf, -inf).
-
AABBf
public AABBf(AABBf source)
Create a newAABBfas a copy of the givensource.- Parameters:
source- theAABBfto copy from
-
AABBf
public AABBf(Vector3fc min, Vector3fc max)
Create a newAABBfwith the given minimum and maximum corner coordinates.- Parameters:
min- the minimum coordinatesmax- the maximum coordinates
-
AABBf
public AABBf(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)Create a newAABBfwith the given minimum and maximum corner coordinates.- Parameters:
minX- the x coordinate of the minimum cornerminY- the y coordinate of the minimum cornerminZ- the z coordinate of the minimum cornermaxX- the x coordinate of the maximum cornermaxY- the y coordinate of the maximum cornermaxZ- the z coordinate of the maximum corner
-
-
Method Detail
-
setMin
public AABBf setMin(float minX, float minY, float minZ)
Set the minimum corner coordinates.- Parameters:
minX- the x coordinate of the minimum cornerminY- the y coordinate of the minimum cornerminZ- the z coordinate of the minimum corner- Returns:
- this
-
setMax
public AABBf setMax(float maxX, float maxY, float maxZ)
Set the maximum corner coordinates.- Parameters:
maxX- the x coordinate of the maximum cornermaxY- the y coordinate of the maximum cornermaxZ- the z coordinate of the maximum corner- Returns:
- this
-
setMin
public AABBf setMin(Vector3fc min)
Set the minimum corner coordinates.- Parameters:
min- the minimum coordinates- Returns:
- this
-
setMax
public AABBf setMax(Vector3fc max)
Set the maximum corner coordinates.- Parameters:
max- the maximum coordinates- Returns:
- this
-
getMax
public float getMax(int component) throws IllegalArgumentExceptionGet the maximum corner coordinate of the given component.- Parameters:
component- the component, within[0..2]- Returns:
- the maximum coordinate
- Throws:
IllegalArgumentException- ifcomponentis not within[0..2]
-
getMin
public float getMin(int component) throws IllegalArgumentExceptionGet the minimum corner coordinate of the given component.- Parameters:
component- the component, within[0..2]- Returns:
- the maximum coordinate
- Throws:
IllegalArgumentException- ifcomponentis not within[0..2]
-
union
public AABBf union(float x, float y, float z)
Setthisto the union ofthisand the given point(x, y, z).- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the point- Returns:
- this
-
union
public AABBf union(Vector3fc p)
Setthisto the union ofthisand the given pointp.- Parameters:
p- the point- Returns:
- this
-
union
public AABBf union(float x, float y, float z, AABBf dest)
Compute the union ofthisand the given point(x, y, z)and store the result indest.- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the pointdest- will hold the result- Returns:
- dest
-
union
public AABBf union(Vector3fc p, AABBf dest)
Compute the union ofthisand the given pointpand store the result indest.- Parameters:
p- the pointdest- will hold the result- Returns:
- dest
-
union
public AABBf union(AABBf other)
Setthisto the union ofthisandother.- Parameters:
other- the otherAABBf- Returns:
- this
-
union
public AABBf union(AABBf other, AABBf dest)
Compute the union ofthisandotherand store the result indest.- Parameters:
other- the otherAABBfdest- will hold the result- Returns:
- dest
-
correctBounds
public AABBf correctBounds()
Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping them if necessary.- Returns:
- this
-
translate
public AABBf translate(Vector3fc xyz)
Translatethisby the given vectorxyz.- Parameters:
xyz- the vector to translate by- Returns:
- this
-
translate
public AABBf translate(Vector3fc xyz, AABBf dest)
Translatethisby the given vectorxyzand store the result indest.- Parameters:
xyz- the vector to translate bydest- will hold the result- Returns:
- dest
-
translate
public AABBf translate(float x, float y, float z)
Translatethisby the vector(x, y, z).- Parameters:
x- the x coordinate to translate byy- the y coordinate to translate byz- the z coordinate to translate by- Returns:
- this
-
translate
public AABBf translate(float x, float y, float z, AABBf dest)
Translatethisby the vector(x, y, z)and store the result indest.- Parameters:
x- the x coordinate to translate byy- the y coordinate to translate byz- the z coordinate to translate bydest- will hold the result- Returns:
- dest
-
testPoint
public boolean testPoint(float x, float y, float z)Test whether the point(x, y, z)lies inside this AABB.- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the point- Returns:
trueiff the given point lies inside this AABB;falseotherwise
-
testPoint
public boolean testPoint(Vector3fc point)
Test whether the given point lies inside this AABB.- Parameters:
point- the coordinates of the point- Returns:
trueiff the given point lies inside this AABB;falseotherwise
-
testPlane
public boolean testPlane(float a, float b, float c, float d)Test whether the plane given via its plane equationa*x + b*y + c*z + d = 0intersects this AABB.Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II")
- Parameters:
a- the x factor in the plane equationb- the y factor in the plane equationc- the z factor in the plane equationd- the constant in the plane equation- Returns:
trueiff the plane intersects this AABB;falseotherwise
-
testPlane
public boolean testPlane(Planef plane)
Test whether the given plane intersects this AABB.Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II")
- Parameters:
plane- the plane- Returns:
trueiff the plane intersects this AABB;falseotherwise
-
testAABB
public boolean testAABB(AABBf other)
Test whetherthisandotherintersect.- Parameters:
other- the other AABB- Returns:
trueiff both AABBs intersect;falseotherwise
-
testSphere
public boolean testSphere(float centerX, float centerY, float centerZ, float radiusSquared)Test whether this AABB intersects the given sphere with equation(x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0.Reference: http://stackoverflow.com
- Parameters:
centerX- the x coordinate of the center of the spherecenterY- the y coordinate of the center of the spherecenterZ- the z coordinate of the center of the sphereradiusSquared- the square radius of the sphere- Returns:
trueiff this AABB and the sphere intersect;falseotherwise
-
testSphere
public boolean testSphere(Spheref sphere)
Test whether this AABB intersects the given sphere.Reference: http://stackoverflow.com
- Parameters:
sphere- the sphere- Returns:
trueiff this AABB and the sphere intersect;falseotherwise
-
testRay
public boolean testRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ)Test whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
originX- the x coordinate of the ray's originoriginY- the y coordinate of the ray's originoriginZ- the z coordinate of the ray's origindirX- the x coordinate of the ray's directiondirY- the y coordinate of the ray's directiondirZ- the z coordinate of the ray's direction- Returns:
trueif this AABB and the ray intersect;falseotherwise
-
testRay
public boolean testRay(Rayf ray)
Test whether the given ray intersects this AABB.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
ray- the ray- Returns:
trueif this AABB and the ray intersect;falseotherwise
-
intersectRay
public boolean intersectRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ, Vector2f result)Determine whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
originX- the x coordinate of the ray's originoriginY- the y coordinate of the ray's originoriginZ- the z coordinate of the ray's origindirX- the x coordinate of the ray's directiondirY- the y coordinate of the ray's directiondirZ- the z coordinate of the ray's directionresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection iff the ray intersects this AABB- Returns:
trueif the given ray intersects this AABB;falseotherwise
-
intersectRay
public boolean intersectRay(Rayf ray, Vector2f result)
Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
ray- the rayresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection iff the ray intersects this AABB- Returns:
trueif the given ray intersects this AABB;falseotherwise
-
intersectLineSegment
public int intersectLineSegment(float p0X, float p0Y, float p0Z, float p1X, float p1Y, float p1Z, Vector2f result)Determine whether the undirected line segment with the end points(p0X, p0Y, p0Z)and(p1X, p1Y, p1Z)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.This method returns
truefor a line segment whose either end point lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
p0X- the x coordinate of the line segment's first end pointp0Y- the y coordinate of the line segment's first end pointp0Z- the z coordinate of the line segment's first end pointp1X- the x coordinate of the line segment's second end pointp1Y- the y coordinate of the line segment's second end pointp1Z- the z coordinate of the line segment's second end pointresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection iff the line segment intersects this AABB- Returns:
Intersectionf.INSIDEif the line segment lies completely inside of this AABB; orIntersectionf.OUTSIDEif the line segment lies completely outside of this AABB; orIntersectionf.ONE_INTERSECTIONif one of the end points of the line segment lies inside of this AABB; orIntersectionf.TWO_INTERSECTIONif the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB
-
intersectLineSegment
public int intersectLineSegment(LineSegmentf lineSegment, Vector2f result)
Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.This method returns
truefor a line segment whose either end point lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
lineSegment- the line segmentresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection iff the line segment intersects this AABB- Returns:
Intersectionf.INSIDEif the line segment lies completely inside of this AABB; orIntersectionf.OUTSIDEif the line segment lies completely outside of this AABB; orIntersectionf.ONE_INTERSECTIONif one of the end points of the line segment lies inside of this AABB; orIntersectionf.TWO_INTERSECTIONif the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB
-
transform
public AABBf transform(Matrix4fc m)
- Parameters:
m- the affine transformation matrix- Returns:
- this
-
transform
public AABBf transform(Matrix4fc m, AABBf dest)
Apply the givenaffinetransformation to thisAABBfand store the resulting AABB intodest.The matrix in
mmust beaffine.- Parameters:
m- the affine transformation matrixdest- will hold the result- Returns:
- dest
-
toString
public String toString()
Return a string representation of this AABB.This method creates a new
DecimalFormaton every invocation with the format string "0.000E0;-".
-
toString
public String toString(NumberFormat formatter)
Return a string representation of this AABB by formatting the vector components with the givenNumberFormat.- Parameters:
formatter- theNumberFormatused to format the vector components with- Returns:
- the string representation
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-