crystalspace.jbind.impl.csgeom.box
Class csBox3

java.lang.Object
  extended bycrystalspace.jbind.impl.csNativeObject
      extended bycrystalspace.jbind.impl.csgeom.box.csBox3
All Implemented Interfaces:
iPointer

public class csBox3
extends csNativeObject

A bounding box in 3D space. In order to operate correctly, this bounding box assumes that all values entered or compared against lie within the range (-CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE). It is not recommended to use points outside of this range.

Author:
Jaca wrapper - Quentin Anciaux, c++ version - http://crystal.sourceforge.net/docs/online/pubapi/classcsBox3.php

Field Summary
 
Fields inherited from class crystalspace.jbind.impl.csNativeObject
ImplFactory, nPointer
 
Constructor Summary
csBox3()
          Initialize this box to empty.
csBox3(csVector3 v)
          Initialize this box with one point.
csBox3(csVector3 v1, csVector3 v2)
          Initialize this box with two points.
csBox3(float x1, float y1, float z1, float x2, float y2, float z2)
          Initialize this box with the given values.
csBox3(iPointer nPointer)
           
 
Method Summary
 csBox3 add(csBox3 box)
          Compute the union of two bounding boxes.
static csBox3 add(csBox3 box1, csBox3 box2)
          Compute the union of two bounding boxes.
static csBox3 add(csBox3 box, csVector3 point)
          Compute the union of a bounding box and a point.
 csBox3 add(csVector3 point)
          Compute the union of a point with this bounding box.
 void addBoundingVertex(csVector3 v)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertex(float x, float y, float z)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertexSmart(csVector3 v)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertexSmart(float x, float y, float z)
          Add a new vertex and recalculate the bounding box.
 int adjacent(csBox3 other)
          Test if this box is adjacent to the other one.
 boolean adjacentX(csBox3 other)
          Test if this box is adjacent to the other on the X side.
 boolean adjacentY(csBox3 other)
          Test if this box is adjacent to the other on the Y side.
 boolean adjacentZ(csBox3 other)
          Test if this box is adjacent to the other on the Z side.
 boolean between(csBox3 box1, csBox3 box2)
          Test if this box is between two others.
 int calculatePointSegment(csVector3 pos)
          Assume that 3D space is divided into 27 areas.
 boolean contains(csBox3 box)
          Test if this box contains the other box.
 boolean empty()
          Test if this box is empty.
static boolean equals(csBox3 box1, csBox3 box2)
          Tests if two bounding boxes are equal.
 csVector3 getCenter()
          Get the center of this box.
 void getConvexOutline(csVector3 pos, csVector3Array array)
          Get a convex outline (not a polygon unless projected to 2D) for for this box as seen from the given position.
 void getConvexOutline(csVector3 pos, csVector3Array array, boolean bVisible)
          Get a convex outline (not a polygon unless projected to 2D) for for this box as seen from the given position.
 csVector3 getCorner(int corner)
          Return every corner of this bounding box from 0 to 7.
 csSegment3 getEdge(int edge)
          Return every edge (segment) of this bounding box from 0 to 23 (use one of the CS_BOX_EDGE_Xyz_xyz etc. indices).
 void getEdge(int edge, csSegment3 e)
          Return every edge (segment) of this bounding box from 0 to 23 (use one of the CS_BOX_EDGE_Xyz_xyz etc. indices).
 int[] getEdgeInfo()
          Given an edge index (CS_BOX_EDGE_Xyz_xyz etc.) return the two vertices (index CS_BOX_CORNER_xyz etc.) and left/right faces (CS_BOX_SIDE_x etc.).
 csNativeByteArray getFaceEdges(int face)
          Given a face index (CS_BOX_SIDE_x etc.) return the four edges oriented clockwise around this face (CS_BOX_EDGE_Xyz_xyz etc.).
 csBox2 getSide(int side)
          Get a side of this box as a 2D box.
 int getVisibleSides(csVector3 pos, csNativeIntArray visible_sides)
          Fill the array (which should be three long at least) with all visible sides (CS_BOX_SIDE_x etc. defines) as seen from the given point.
static boolean greater(csBox3 box1, csBox3 box2)
          Tests if box1 is a superset of box2.
 boolean in(csVector3 v)
          Test if the given coordinate is in this box.
 boolean in(float x, float y, float z)
          Test if the given coordinate is in this box.
protected  boolean isNativePointerValidSafe(long nPointer)
           
static boolean less(csBox3 box1, csBox3 box2)
          Tests if box1 is a subset of box2.
static boolean less(csVector3 point, csBox3 box)
          Tests if a point is contained in a box.
 void manhattanDistance(csBox3 other, csVector3 dist)
          Calculate the minimum manhattan distance between this box and another one.
 csVector3 max()
          Get the 3d vector of maximum (x, y, z) values.
 float max(int idx)
          Get Max component for 0 (x), 1 (y), or 2 (z).
 float maxX()
          Get the maximum X value of the box.
 float maxY()
          Get the maximum Y value of the box.
 float maxZ()
          Get the maximum Z value of the box.
 csVector3 min()
          Get the 3d vector of minimum (x, y, z) values.
 float min(int idx)
          Get Min component for 0 (x), 1 (y), or 2 (z).
 float minX()
          Get the minimum X value of the box.
 float minY()
          Get the minimum Y value of the box.
 float minZ()
          Get the minimum Z value of the box.
 csBox3 mul(csBox3 box)
          Compute the intersection of two bounding boxes.
static csBox3 mul(csBox3 box1, csBox3 box2)
          Compute the intersection of two bounding boxes.
protected  void nDelete(long pointer)
           
static boolean nEquals(csBox3 box1, csBox3 box2)
          Tests if two bounding boxes are unequal.
static int otherSide(int side)
          Static function to get the 'other' side (i.e.
 boolean overlap(csBox3 box)
          Test if this box overlaps with the given box.
 boolean projectBox(csTransform trans, float fov, float sx, float sy, csBox2 sbox, float min_z, float max_z)
          Project this box to a 2D bounding box given the view point transformation and also the field-of-view and shift values (for perspective projection).
 boolean projectBoxAndOutline(csTransform trans, float fov, float sx, float sy, csBox2 sbox, csPoly2D poly, float min_z, float max_z)
          Project this box to the 2D outline given the view point transformation and also the field-of-view and shift values (for perspective correction).
 boolean projectOutline(csTransform trans, float fov, float sx, float sy, csPoly2D poly, float min_z, float max_z)
          Project this box to the 2D outline given the view point transformation and also the field-of-view and shift values (for perspective correction).
 void set(csVector3 bmin, csVector3 bmax)
          Sets the bounds of the box with the given values.
 void set(float x1, float y1, float z1, float x2, float y2, float z2)
          Sets the bounds of the box with the given values.
 void setCenter(csVector3 c)
          Set the center of this box.
 void setMax(int idx, float val)
          Set Max component for 0 (x), 1 (y), or 2 (z).
 void setMin(int idx, float val)
          Set Min component for 0 (x), 1 (y), or 2 (z).
 void setSize(csVector3 s)
          Set the size of the box but keep the center intact.
 float squaredOriginDist()
          Calculate the squared distance between (0,0,0) and the box This routine is extremely efficient.
 float squaredOriginMaxDist()
          Calculate the squared distance between (0,0,0) and the point on the box which is furthest away from (0,0,0).
 void startBoundingBox()
          Initialize this box to empty.
 void startBoundingBox(csVector3 v)
          Initialize this box to one vertex.
 boolean testIntersect(csBox3 box)
          Test if the two boxes have an intersection.
 
Methods inherited from class crystalspace.jbind.impl.csNativeObject
changePointer, equals, finalize, getPointer, getPointer, getPointerArray, hashCode, isMemoryOwner, isNativePointerValid, newNativeObject, setMemoryOwner, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

csBox3

public csBox3(iPointer nPointer)
Parameters:
nPointer -

csBox3

public csBox3()
Initialize this box to empty. Definition at line 751 of file box.h. References CS_BOUNDINGBOX_MAXVALUE.


csBox3

public csBox3(csVector3 v)
Initialize this box with one point. Definition at line 760 of file box.h.

Parameters:
v -

csBox3

public csBox3(csVector3 v1,
              csVector3 v2)
Initialize this box with two points. Definition at line 763 of file box.h. References Empty(), and StartBoundingBox().

Parameters:
v1 -
v2 -

csBox3

public csBox3(float x1,
              float y1,
              float z1,
              float x2,
              float y2,
              float z2)
Initialize this box with the given values. Definition at line 768 of file box.h. References Empty(), and StartBoundingBox().

Parameters:
x1 -
y1 -
z1 -
x2 -
y2 -
z2 -
Method Detail

nDelete

protected void nDelete(long pointer)
Specified by:
nDelete in class csNativeObject
See Also:
csNativeObject.nDelete(long)

isNativePointerValidSafe

protected boolean isNativePointerValidSafe(long nPointer)
Specified by:
isNativePointerValidSafe in class csNativeObject
See Also:
crystalspace.jbind.impl.csNativeObject#isNativePointerValidSafe()

addBoundingVertex

public final void addBoundingVertex(csVector3 v)
Add a new vertex and recalculate the bounding box. Reimplemented in csOBB. Definition at line 709 of file box.h. References AddBoundingVertex(), csVector3::x, csVector3::y, and csVector3::z.

Parameters:
v -

addBoundingVertex

public final void addBoundingVertex(float x,
                                    float y,
                                    float z)
Add a new vertex and recalculate the bounding box. Definition at line 701 of file box.h. References csVector3::x, csVector3::y, and csVector3::z. Referenced by AddBoundingVertex().

Parameters:
x -
y -
z -

addBoundingVertexSmart

public final void addBoundingVertexSmart(csVector3 v)
Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Definition at line 731 of file box.h. References AddBoundingVertexSmart(), csVector3::x, csVector3::y, and csVector3::z.

Parameters:
v -

addBoundingVertexSmart

public final void addBoundingVertexSmart(float x,
                                         float y,
                                         float z)
Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Definition at line 719 of file box.h. References csVector3::x, csVector3::y, and csVector3::z. Referenced by AddBoundingVertexSmart().

Parameters:
x -
y -
z -

adjacent

public final int adjacent(csBox3 other)
Test if this box is adjacent to the other one. Return -1 if not adjacent or else any of the CS_BOX_SIDE_x etc. flags to indicate the side of this box that the other box is adjacent with.

Parameters:
other -
Returns:

adjacentX

public final boolean adjacentX(csBox3 other)
Test if this box is adjacent to the other on the X side.

Parameters:
other -
Returns:

adjacentY

public final boolean adjacentY(csBox3 other)
Test if this box is adjacent to the other on the Y side.

Parameters:
other -
Returns:

adjacentZ

public final boolean adjacentZ(csBox3 other)
Test if this box is adjacent to the other on the Z side.

Parameters:
other -
Returns:

between

public final boolean between(csBox3 box1,
                             csBox3 box2)
Test if this box is between two others.

Parameters:
box1 -
box2 -
Returns:

calculatePointSegment

public final int calculatePointSegment(csVector3 pos)
Assume that 3D space is divided into 27 areas. One is inside the box. The other 26 are rectangular segments around the box. This function will calculate the right segment for a given point and return that.

Parameters:
pos -
Returns:

contains

public final boolean contains(csBox3 box)
Test if this box contains the other box. Definition at line 667 of file box.h. References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

Parameters:
box -
Returns:

empty

public final boolean empty()
Test if this box is empty. Definition at line 675 of file box.h. References csVector3::x, csVector3::y, and csVector3::z. Referenced by csBox3().

Returns:

getCenter

public final csVector3 getCenter()
Get the center of this box. Definition at line 585 of file box.h.

Returns:

getConvexOutline

public final void getConvexOutline(csVector3 pos,
                                   csVector3Array array)
Get a convex outline (not a polygon unless projected to 2D) for for this box as seen from the given position. The coordinates returned are world space coordinates. Note that you need place for at least six vectors in the array. If you set bVisible true, you will get all visible corners - this could be up to 7.

Parameters:
pos -
array -

getConvexOutline

public final void getConvexOutline(csVector3 pos,
                                   csVector3Array array,
                                   boolean bVisible)
Get a convex outline (not a polygon unless projected to 2D) for for this box as seen from the given position. The coordinates returned are world space coordinates. Note that you need place for at least six vectors in the array. If you set bVisible true, you will get all visible corners - this could be up to 7.

Parameters:
pos -
array -
bVisible -

getCorner

public final csVector3 getCorner(int corner)
Return every corner of this bounding box from 0 to 7. This contrasts with Min() and Max() because those are only the min and max corners. Corner 0 = xyz, 1 = xyZ, 2 = xYz, 3 = xYZ, 4 = Xyz, 5 = XyZ, 6 = XYz, 7 = XYZ. Use CS_BOX_CORNER_xyz etc. defines. CS_BOX_CENTER3 also works. Reimplemented in csOBB. Referenced by csPolygonMeshBox::SetBox().

Parameters:
corner -
Returns:

getEdge

public final void getEdge(int edge,
                          csSegment3 e)
Return every edge (segment) of this bounding box from 0 to 23 (use one of the CS_BOX_EDGE_Xyz_xyz etc. indices). The returned edge is undefined for any other index. Definition at line 636 of file box.h. References edges, csSegment3::SetEnd(), and csSegment3::SetStart().

Parameters:
edge -
e -

getEdge

public final csSegment3 getEdge(int edge)
Return every edge (segment) of this bounding box from 0 to 23 (use one of the CS_BOX_EDGE_Xyz_xyz etc. indices). The returned edge is undefined for any other index. Definition at line 626 of file box.h. References edges.


getEdgeInfo

public final int[] getEdgeInfo()
Given an edge index (CS_BOX_EDGE_Xyz_xyz etc.) return the two vertices (index CS_BOX_CORNER_xyz etc.) and left/right faces (CS_BOX_SIDE_x etc.). Definition at line 565 of file box.h. References edges.

Returns:

getFaceEdges

public csNativeByteArray getFaceEdges(int face)
Given a face index (CS_BOX_SIDE_x etc.) return the four edges oriented clockwise around this face (CS_BOX_EDGE_Xyz_xyz etc.). Definition at line 577 of file box.h. References faces.

Parameters:
face -
Returns:

getSide

public final csBox2 getSide(int side)
Get a side of this box as a 2D box. Use CS_BOX_SIDE_x etc. defines.

Parameters:
side -
Returns:

getVisibleSides

public final int getVisibleSides(csVector3 pos,
                                 csNativeIntArray visible_sides)
Fill the array (which should be three long at least) with all visible sides (CS_BOX_SIDE_x etc. defines) as seen from the given point. Returns the number of visible sides.

Parameters:
pos -
visible_sides -
Returns:

in

public final boolean in(csVector3 v)
Test if the given coordinate is in this box. Definition at line 652 of file box.h. References In(), csVector3::x, csVector3::y, and csVector3::z.

Parameters:
v -
Returns:

in

public final boolean in(float x,
                        float y,
                        float z)
Test if the given coordinate is in this box. Definition at line 643 of file box.h. References csVector3::x, csVector3::y, and csVector3::z. Referenced by In().

Parameters:
x -
y -
z -
Returns:

manhattanDistance

public final void manhattanDistance(csBox3 other,
                                    csVector3 dist)
Calculate the minimum manhattan distance between this box and another one.

Parameters:
other -
dist -

max

public final csVector3 max()
Get the 3d vector of maximum (x, y, z) values. Definition at line 548 of file box.h.

Returns:

max

public final float max(int idx)
Get Max component for 0 (x), 1 (y), or 2 (z). Definition at line 543 of file box.h. References csVector3::x, csVector3::y, and csVector3::z.

Parameters:
idx -
Returns:

maxX

public final float maxX()
Get the maximum X value of the box. Definition at line 534 of file box.h.

Returns:

maxY

public final float maxY()
Get the maximum Y value of the box. Definition at line 536 of file box.h.

Returns:

maxZ

public final float maxZ()
Get the maximum Z value of the box. Definition at line 538 of file box.h.

Returns:

min

public final csVector3 min()
Get the 3d vector of minimum (x, y, z) values. Definition at line 546 of file box.h.

Returns:

min

public final float min(int idx)
Get Min component for 0 (x), 1 (y), or 2 (z). Definition at line 540 of file box.h. References csVector3::x, csVector3::y, and csVector3::z.

Parameters:
idx -
Returns:

minX

public final float minX()
Get the minimum X value of the box. Definition at line 528 of file box.h.

Returns:

minY

public final float minY()
Get the minimum Y value of the box. Definition at line 530 of file box.h.

Returns:

minZ

public final float minZ()
Get the minimum Z value of the box. Definition at line 532 of file box.h.

Returns:

mul

public final csBox3 mul(csBox3 box)
Compute the intersection of two bounding boxes.

Parameters:
box -
Returns:

add

public final csBox3 add(csVector3 point)
Compute the union of a point with this bounding box.

Parameters:
point -
Returns:

add

public final csBox3 add(csBox3 box)
Compute the union of two bounding boxes.

Parameters:
box -
Returns:

otherSide

public static final int otherSide(int side)
Static function to get the 'other' side (i.e. CS_BOX_SIDE_X to CS_BOX_SIDE_x, ...). Definition at line 616 of file box.h.

Parameters:
side -
Returns:

overlap

public final boolean overlap(csBox3 box)
Test if this box overlaps with the given box. Definition at line 658 of file box.h. References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

Parameters:
box -
Returns:

projectBox

public final boolean projectBox(csTransform trans,
                                float fov,
                                float sx,
                                float sy,
                                csBox2 sbox,
                                float min_z,
                                float max_z)
Project this box to a 2D bounding box given the view point transformation and also the field-of-view and shift values (for perspective projection). The transform should transform from world to camera space (using Other2This). The minimum and maximum z are also calculated. If the bounding box is behind the camera then the 'sbox' will not be calculated (min_z and max_z are still calculated) and the function will return false. If the camera is inside the transformed box then this function will return true and a conservative screen space bounding box is returned.

Parameters:
trans -
fov -
sx -
sy -
sbox -
min_z -
max_z -
Returns:

projectBoxAndOutline

public final boolean projectBoxAndOutline(csTransform trans,
                                          float fov,
                                          float sx,
                                          float sy,
                                          csBox2 sbox,
                                          csPoly2D poly,
                                          float min_z,
                                          float max_z)
Project this box to the 2D outline given the view point transformation and also the field-of-view and shift values (for perspective correction). The minimum and maximum z are also calculated. If the box is fully behind the camera then false is returned and this function will not do anything. If the box is partially behind the camera you will get an outline that is conservatively correct (i.e. it will overestimate the box). In addition to the outline this function also returns the projected screen-space box. So it is a combination of ProjectBox() and ProjectOutline().

Parameters:
trans -
fov -
sx -
sy -
sbox -
poly -
min_z -
max_z -
Returns:

projectOutline

public final boolean projectOutline(csTransform trans,
                                    float fov,
                                    float sx,
                                    float sy,
                                    csPoly2D poly,
                                    float min_z,
                                    float max_z)
Project this box to the 2D outline given the view point transformation and also the field-of-view and shift values (for perspective correction). The minimum and maximum z are also calculated. If the box is fully behind the camera then false is returned and this function will not do anything. If the box is partially behind the camera you will get an outline that is conservatively correct (i.e. it will overestimate the box).

Parameters:
trans -
fov -
sx -
sy -
poly -
min_z -
max_z -
Returns:

set

public final void set(float x1,
                      float y1,
                      float z1,
                      float x2,
                      float y2,
                      float z2)
Sets the bounds of the box with the given values. Definition at line 780 of file box.h. References StartBoundingBox(), csVector3::x, csVector3::y, and csVector3::z.

Parameters:
x1 -
y1 -
z1 -
x2 -
y2 -
z2 -

set

public final void set(csVector3 bmin,
                      csVector3 bmax)
Sets the bounds of the box with the given values. Definition at line 773 of file box.h.

Parameters:
bmin -
bmax -

setCenter

public final void setCenter(csVector3 c)
Set the center of this box. This will not change the size of the box but just relocate the center.

Parameters:
c -

setMax

public final void setMax(int idx,
                         float val)
Set Max component for 0 (x), 1 (y), or 2 (z). Definition at line 799 of file box.h. References csVector3::x, csVector3::y, and csVector3::z.

Parameters:
idx -
val -

setMin

public final void setMin(int idx,
                         float val)
Set Min component for 0 (x), 1 (y), or 2 (z). Definition at line 791 of file box.h. References csVector3::x, csVector3::y, and csVector3::z.

Parameters:
idx -
val -

setSize

public final void setSize(csVector3 s)
Set the size of the box but keep the center intact.

Parameters:
s -

squaredOriginDist

public final float squaredOriginDist()
Calculate the squared distance between (0,0,0) and the box This routine is extremely efficient.

Returns:

squaredOriginMaxDist

public final float squaredOriginMaxDist()
Calculate the squared distance between (0,0,0) and the point on the box which is furthest away from (0,0,0). This routine is extremely efficient.

Returns:

startBoundingBox

public final void startBoundingBox(csVector3 v)
Initialize this box to one vertex. Definition at line 695 of file box.h.

Parameters:
v -

startBoundingBox

public final void startBoundingBox()
Initialize this box to empty. Definition at line 684 of file box.h. References CS_BOUNDINGBOX_MAXVALUE, csVector3::x, csVector3::y, and csVector3::z. Referenced by csBox3(), and Set().


testIntersect

public final boolean testIntersect(csBox3 box)
Test if the two boxes have an intersection.

Parameters:
box -
Returns:

mul

public static final csBox3 mul(csBox3 box1,
                               csBox3 box2)
Compute the intersection of two bounding boxes.

Parameters:
box1 -
box2 -
Returns:

nEquals

public static final boolean nEquals(csBox3 box1,
                                    csBox3 box2)
Tests if two bounding boxes are unequal.

Parameters:
box1 -
box2 -
Returns:

add

public static final csBox3 add(csBox3 box,
                               csVector3 point)
Compute the union of a bounding box and a point.

Parameters:
box -
point -
Returns:

add

public static final csBox3 add(csBox3 box1,
                               csBox3 box2)
Compute the union of two bounding boxes.

Parameters:
box1 -
box2 -
Returns:

less

public static final boolean less(csVector3 point,
                                 csBox3 box)
Tests if a point is contained in a box.

Parameters:
point -
box -
Returns:

less

public static final boolean less(csBox3 box1,
                                 csBox3 box2)
Tests if box1 is a subset of box2.

Parameters:
box1 -
box2 -
Returns:

equals

public static final boolean equals(csBox3 box1,
                                   csBox3 box2)
Tests if two bounding boxes are equal.

Parameters:
box1 -
box2 -
Returns:

greater

public static final boolean greater(csBox3 box1,
                                    csBox3 box2)
Tests if box1 is a superset of box2.

Parameters:
box1 -
box2 -
Returns: