28package com.jogamp.math.geom;
30import com.jogamp.math.FovHVHalves;
31import com.jogamp.math.Matrix4f;
32import com.jogamp.math.Vec3f;
33import com.jogamp.math.Vec4f;
100 throw new IllegalArgumentException(
"Requirements zNear > 0 and zFar > zNear, but zNear "+
zNear+
", zFar "+
zFar);
222 public void toFloats(
final float[] out,
final int off) {
244 public final float distanceTo(
final float x,
final float y,
final float z) {
245 return n.x() * x +
n.y() * y +
n.z() * z +
d;
255 return "Plane[ [ " +
n +
" ], " +
d +
"]";
260 public static final int LEFT = 0;
266 public static final int TOP = 3;
268 public static final int NEAR = 4;
270 public static final int FAR = 5;
317 public void getPlanes(
final float[] out,
final int off) {
331 for (
int i = 0; i < 6; ++i) {
333 final Plane pS = src[i];
335 System.arraycopy(pS.
n, 0, pD.
n, 0, 3);
404 private static final boolean intersects(
final Plane p,
final AABBox box) {
408 return p.
distanceTo(lo.x(), lo.y(), lo.z()) > 0.0f ||
409 p.
distanceTo(hi.x(), lo.y(), lo.z()) > 0.0f ||
410 p.
distanceTo(lo.x(), hi.y(), lo.z()) > 0.0f ||
411 p.
distanceTo(hi.x(), hi.y(), lo.z()) > 0.0f ||
412 p.
distanceTo(lo.x(), lo.y(), hi.z()) > 0.0f ||
413 p.
distanceTo(hi.x(), lo.y(), hi.z()) > 0.0f ||
414 p.
distanceTo(lo.x(), hi.y(), hi.z()) > 0.0f ||
425 return !intersects(
planes[0], box) ||
426 !intersects(
planes[1], box) ||
427 !intersects(
planes[2], box) ||
428 !intersects(
planes[3], box) ||
429 !intersects(
planes[4], box) ||
430 !intersects(
planes[5], box);
433 private static final boolean intersects(
final Plane p,
final Cube c) {
451 return !intersects(
planes[0], c) ||
452 !intersects(
planes[1], c) ||
453 !intersects(
planes[2], c) ||
454 !intersects(
planes[3], c) ||
455 !intersects(
planes[4], c) ||
456 !intersects(
planes[5], c);
471 for (
int i = 0; i < 6; ++i) {
475 }
else if ( d == 0.0f ) {
507 for (
int i = 0; i < 6; ++i) {
512 }
else if (d < radius ) {
533 sb =
new StringBuilder();
535 sb.append(
"Frustum[Planes[").append(System.lineSeparator())
536 .append(
" L: ").append(
planes[0]).append(
", ").append(System.lineSeparator())
537 .append(
" R: ").append(
planes[1]).append(
", ").append(System.lineSeparator())
538 .append(
" B: ").append(
planes[2]).append(
", ").append(System.lineSeparator())
539 .append(
" T: ").append(
planes[3]).append(
", ").append(System.lineSeparator())
540 .append(
" N: ").append(
planes[4]).append(
", ").append(System.lineSeparator())
541 .append(
" F: ").append(
planes[5]).append(
"], ").append(System.lineSeparator())
Horizontal and vertical field of view (FOV) halves, allowing a non-centered projection.
final String toStringInDegrees()
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
Frustum getFrustum(final Frustum frustum)
Calculate the frustum planes in world coordinates using this column major order matrix,...
Matrix4f setToPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Set this matrix to perspective frustum projection.
3D Vector based upon three float components.
Vec3f scale(final float s)
this = this * s, returns this.
Vec3f normalize()
Normalize this vector in place.
float dot(final Vec3f o)
Return the dot product of this vector and the given one.
Vec3f minus(final Vec3f arg)
Returns this - arg; creates new vector.
Vec3f cross(final Vec3f arg)
Returns this cross arg; creates new vector.
Vec3f set(final Vec3f o)
this = o, returns this.
4D Vector based upon four float components.
Vec4f set(final Vec4f o)
this = o, returns this.
Axis Aligned Bounding Box.
final Vec3f getHigh()
Returns the maximum right-top-near (xyz) coordinate.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
Simple 8-point Vec3f cube compound having z-far <= z-near @endiliteral.
Frustum updateFrustumPlanes(final Frustum frustum)
Calculate the frustum planes using this Cube.
final Vec3f ltf
left -top -far (xyz) in AABB case, otherwise arbitrary
final Vec3f ltn
left -top -near (xyz) in AABB case, otherwise arbitrary
final Vec3f rtn
right-top -near (xyz) in AABB case, otherwise arbitrary
final Vec3f lbn
left -bottom-near (xyz) in AABB case, otherwise arbitrary
final Vec3f rbn
right-bottom-near (xyz) in AABB case, otherwise arbitrary
final Vec3f rtf
right-top -far (xyz) in AABB case, otherwise arbitrary
final Vec3f rbf
right-bottom-far (xyz) in AABB case, otherwise arbitrary
final Vec3f lbf
left -bottom-far (xyz) in AABB case, otherwise arbitrary
Frustum description by fovhv and zNear, zFar.
final FovHVHalves fovhv
Field of view in both directions, may not be centered, either FovHVHalves#inTangents or radians.
FovDesc(final FovHVHalves fovhv, final float zNear, final float zFar)
Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0.
final float distanceTo(final float x, final float y, final float z)
Return signed distance of plane to given point.
final Vec3f n
Normal of the plane.
Vec4f toVec4f(final Vec4f out)
Sets the given Vec4f out to ( n, d ).
void toFloats(final float[] out, final int off)
Sets the given [float[off]..float[off+4]) out to ( n, d ).
float d
Distance to origin.
final float distanceTo(final Vec3f p)
Return distance of plane to given point, see distanceTo(float, float, float).
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
static final int NEAR
Index for near plane: {@value}.
final Location classifyPoint(final Vec3f p)
Classifies the given Vec3f point whether it is outside, inside or on a plane of this frustum.
Frustum setFromMat(final Matrix4f pmv)
Calculate the frustum planes in world coordinates using the passed column major order matrix,...
Matrix4f updateByFovDesc(final Matrix4f m, final FovDesc fovDesc)
Calculate the frustum planes in world coordinates using the passed FovDesc.
Frustum updateFrustumPlanes(final Cube c)
Calculate the frustum planes using the given Cube.
final Location classifySphere(final Vec3f p, final float radius)
Classifies the given sphere whether it is is outside, intersecting or inside of this frustum.
static final int BOTTOM
Index for bottom plane: {@value}.
final Plane[] getPlanes()
Planes are ordered in the returned array as follows:
void getPlanes(final float[] out, final int off)
Sets the given [float[off]..float[off+4*6]) out to ( n, d ).
final boolean isOutside(final AABBox box)
Returns whether the given AABBox is completely outside of this frustum.
final void updateByPlanes(final Plane[] src)
Copy the given src planes into this this instance's planes.
final boolean isOutside(final Vec3f p)
Returns whether the given Vec3f point is completely outside of this frustum.
static final int RIGHT
Index for right plane: {@value}.
Frustum()
Creates an undefined instance w/o calculating the frustum.
final boolean isOutside(final Cube c)
Returns whether the given Cube is completely outside of this frustum.
Vec4f[] getPlanes(final Vec4f[] out)
Sets each of the given Vec4f[6] out to Plane#toVec4f(Vec4f) in the order LEFT, RIGHT,...
StringBuilder toString(StringBuilder sb)
static final int TOP
Index for top plane: {@value}.
static final int LEFT
Index for left plane: {@value}.
final Plane[] planes
Normalized planes[l, r, b, t, n, f].
static final int FAR
Index for far plane: {@value}.
final boolean isSphereOutside(final Vec3f p, final float radius)
Returns whether the given sphere is completely outside of this frustum.