public class Box extends Object implements Extent, Renderable
Box is defined by three orthogonal axes and two positions along each of those axes. Each of the
positions specifies the location of a box side along the respective axis. The three axes are named by convention "R",
"S" and "T", and are ordered by decreasing length -- R is the longest axis, followed by S and then T.| Modifier and Type | Field and Description |
|---|---|
Vec4 |
bottomCenter |
protected Vec4 |
center |
protected Plane[] |
planes |
protected static int[][] |
ProjectionHullTable
ProjectionHullTable defines a table of all possible vertex combinations representing a
Box's 2D convex hull in screen coordinates. |
protected Vec4 |
r |
protected double |
rLength |
protected Vec4 |
ru |
protected Vec4 |
s |
protected double |
sLength |
protected Vec4 |
su |
protected Vec4 |
t |
protected double |
tLength |
Vec4 |
topCenter |
protected Vec4 |
tu |
| Modifier | Constructor and Description |
|---|---|
|
Box(Vec4 point)
Construct a unit-length cube centered at a specified point.
|
|
Box(Vec4[] axes,
double rMin,
double rMax,
double sMin,
double sMax,
double tMin,
double tMax)
Construct a box from three specified unit axes and the locations of the box faces relative to those axes.
|
protected |
Box(Vec4 bottomCenter,
Vec4 topCenter,
Vec4 center,
Vec4 r,
Vec4 s,
Vec4 t,
Vec4 ru,
Vec4 su,
Vec4 tu,
double rlength,
double sLength,
double tLength,
Plane[] planes) |
| Modifier and Type | Method and Description |
|---|---|
static Box |
computeBoundingBox(BufferWrapper coordinates,
int stride)
Computes a
Box that bounds a specified buffer of points. |
static Box |
computeBoundingBox(Iterable<? extends Vec4> points)
Compute a
Box that bounds a specified list of points. |
protected int |
computeProjectionHullCode(View view)
Computes an index into the
ProjectionHullTable for this Box given the specified
view. |
protected void |
drawBox(DrawContext dc,
Vec4 a,
Vec4 b,
Vec4 c,
Vec4 d) |
protected void |
drawOutline(DrawContext dc,
Vec4 a,
Vec4 b,
Vec4 c,
Vec4 d) |
boolean |
equals(Object o) |
Vec4 |
getBottomCenter()
Returns the point corresponding to the center of the box side left-most along the R (first) axis.
|
Vec4 |
getCenter()
Returns the box's center point.
|
Vec4[] |
getCorners()
Returns the eight corners of the box.
|
double |
getDiameter()
Returns the effective diameter of the box as if it were a sphere.
|
double |
getEffectiveRadius(Plane plane)
Computes the effective radius of the extent relative to a specified plane.
|
protected double |
getEffectiveRadius2(Plane plane)
Returns the effective radius of this box relative to a specified plane, using only this box's S and T axes.
|
Plane[] |
getPlanes()
Returns the six planes of the box.
|
double |
getProjectedArea(View view)
Computes the area in square pixels of this
Extent after it is projected into the specified
view's viewport. |
double |
getRadius()
Returns the effective radius of the box as if it were a sphere.
|
Vec4 |
getRAxis()
Returns the R (first) axis.
|
double |
getRLength()
Returns the length of the R axis.
|
Vec4 |
getSAxis()
Returns the S (second) axis.
|
double |
getSLength()
Returns the length of the S axis.
|
Vec4 |
getTAxis()
Returns the T (third) axis.
|
double |
getTLength()
Returns the length of the T axis.
|
Vec4 |
getTopCenter()
Returns the point corresponding to the center of the box side right-most along the R (first) axis.
|
Vec4 |
getUnitRAxis()
Returns the R (first) axis in unit length.
|
Vec4 |
getUnitSAxis()
Returns the S (second) axis in unit length.
|
Vec4 |
getUnitTAxis()
Returns the T (third) axis in unit length.
|
int |
hashCode() |
Intersection[] |
intersect(Line line)
Computes the intersections of this extent with
line. |
boolean |
intersects(Frustum frustum)
Determines whether or not this
Extent intersects frustum. |
boolean |
intersects(Line line)
Determines whether or not
line intersects this Extent. |
boolean |
intersects(Plane plane)
Calculate whether or not this
Extent is intersected by plane. |
protected double |
intersects(Plane plane,
double effectiveRadius) |
protected double |
intersectsAt(Plane plane,
double effectiveRadius,
Vec4[] endpoints) |
void |
render(DrawContext dc)
Draws a representation of the
Box. |
Box |
translate(Vec4 point) |
static Box |
union(Iterable<? extends Box> iterable)
Computes a
Box that represents the union of one or more Boxes. |
public Vec4 bottomCenter
protected final Vec4 center
protected final Plane[] planes
protected static final int[][] ProjectionHullTable
ProjectionHullTable defines a table of all possible vertex combinations representing a
Box's 2D convex hull in screen coordinates. The index to this table is a 6-bit code, where each bit
denotes whether one of the Box's six planes faces the View. This code is organized as
follows:
| Bit | 5 | 4 | 3 | 2 | 1 | 0 |
| Code | left | right | back | front | bottom | top |
Box's planes can be visible at one time, there are a total of 26 unique
vertex combinations that define a Box's 2D convex hull in the viewport. Index codes that represent a
valid combination of planes facing the View result in an array of 4 or 6 integers (depending on
whether one, two or three planes face the View), where each element in the array is an index for one
of the Box's eight vertices as follows:
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| Vertex | bottom-lower-left | bottom-lower-right | bottom-upper-right | bottom-upper-left | top-lower-left | top-lower-right | top-upper-right | top-upper-left |
View map to null.protected final Vec4 r
protected final double rLength
protected final Vec4 ru
protected final Vec4 s
protected final double sLength
protected final Vec4 su
protected final Vec4 t
protected final double tLength
public Vec4 topCenter
protected final Vec4 tu
public Box(Vec4 point)
point - the center of the cube.IllegalArgumentException - if the point is null.public Box(Vec4[] axes, double rMin, double rMax, double sMin, double sMax, double tMin, double tMax)
WWMath.computePrincipalAxes(Iterable).
Note: No check is made to ensure the order of the face locations.axes - the unit-length axes.rMin - the location along the first axis corresponding to the left-most box side relative to the axis.rMax - the location along the first axis corresponding to the right-most box side relative to the axis.sMin - the location along the second axis corresponding to the left-most box side relative to the axis.sMax - the location along the second axis corresponding to the right-most box side relative to the axis.tMin - the location along the third axis corresponding to the left-most box side relative to the axis.tMax - the location along the third axis corresponding to the right-most box side relative to the axis.IllegalArgumentException - if the axes array or one of its entries is null.public static Box computeBoundingBox(BufferWrapper coordinates, int stride)
Box that bounds a specified buffer of points. Principal axes are computed for the points
and used to form a Box.
The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride.
The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For
example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies
that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride
must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the
remaining elements that follow the last complete tuple.coordinates - the buffer containing the point coordinates for which to compute a bounding volume.stride - the number of elements between the first coordinate of consecutive points. If stride is 3,
this interprets the buffer has having tightly packed XYZ coordinate tuples.Box
class overview.IllegalArgumentException - if the buffer is null or empty, or if the stride is less than three.public static Box computeBoundingBox(Iterable<? extends Vec4> points)
Box that bounds a specified list of points. Principal axes are computed for the points and
used to form a Box.points - the points for which to compute a bounding volume.Box
class overview.IllegalArgumentException - if the point list is null or empty.protected int computeProjectionHullCode(View view)
ProjectionHullTable for this Box given the specified
view. The returned integer is a 6-bit code, where each bit denotes whether one of this
Box's six planes faces the View. See the documentation for ProjectionHullTable for details.
If the view is inside this Box, this returns 0 indicating that none of this
Box's planes face the view.view - the View to compute a lookup index for.ProjectionHullTable.protected void drawBox(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
protected void drawOutline(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
public Vec4 getBottomCenter()
public Vec4 getCenter()
public Vec4[] getCorners()
public double getDiameter()
getDiameter in interface Extentpublic double getEffectiveRadius(Plane plane)
getEffectiveRadius in interface Extentplane - the plane.protected double getEffectiveRadius2(Plane plane)
intersects(Frustum) method. See Lengyel, 2
Ed, Section 7.2.4.plane - the plane in question.public Plane[] getPlanes()
public double getProjectedArea(View view)
Extent after it is projected into the specified
view's viewport. The returned value is the screen area that this Extent covers in the
infinite plane defined by the view's viewport. This area is not limited to the size of the
view's viewport, and portions of this Extent are not clipped by the view's
frustum.
This returns Double.POSITIVE_INFINITY if the view's eye point is inside this
Extent, or if any portion of this Extent is behind the eye point. In either case, this
Extent has no finite projection on the view.getProjectedArea in interface Extentview - the View for which to compute a projected screen area.Extent in square pixels, or
Double.POSITIVE_INFINITY if the view's eye point is inside this
Extent or part of this Extent is behind the view's eye point.public double getRadius()
public Vec4 getRAxis()
public double getRLength()
public Vec4 getSAxis()
public double getSLength()
public Vec4 getTAxis()
public double getTLength()
public Vec4 getTopCenter()
public Vec4 getUnitRAxis()
public Vec4 getUnitSAxis()
public Vec4 getUnitTAxis()
public Intersection[] intersect(Line line)
line. The returned array may be either null or of
zero length if no intersections are discovered. It does not contain null elements. Tangential intersections are
marked as such. line is considered to have infinite length in both directions.public boolean intersects(Frustum frustum)
Extent intersects frustum. Returns true if any part of
these two objects intersect, including the case where either object wholly contains the other, false otherwise.intersects in interface Extentfrustum - the Frustum with which to test for intersection.public boolean intersects(Line line)
line intersects this Extent. This method may be faster than
checking the size of the array returned by intersect(Line). Implementing methods must ensure that
this method returns true if and only if intersect(Line) returns a non-null array containing at least
one element.intersects in interface Extentline - the Line with which to test for intersection.public boolean intersects(Plane plane)
Extent is intersected by plane.intersects in interface Extentplane - the Plane with which to test for intersection.plane is found to intersect this Extent.protected double intersects(Plane plane, double effectiveRadius)
public void render(DrawContext dc)
Box.render in interface Renderabledc - the DrawContext to be used.DrawContextpublic static Box union(Iterable<? extends Box> iterable)
Box that represents the union of one or more Boxes. If the iterable has two
or more non-null Boxes, the returned encloses the Boxes. In this case axes
and center point of the returned Box may differ from the Boxes. If the iterable has
only one non-null Box, this returns that sole Box. This returns
null if the iterable is empty or contains only null references.iterable - an iterable of Boxes to enclose.Box that encloses the specified iterable of Boxes.IllegalArgumentException - if the iterable is null.