com.threed.jpct
Class OcTree

java.lang.Object
  extended by com.threed.jpct.OcTree
All Implemented Interfaces:
java.io.Serializable

public final class OcTree
extends java.lang.Object
implements java.io.Serializable

This is a basic octree implementation. An octree is a structure for spatial subdivision. In jPCT, an octree can be constructed from any Mesh/Object3D and assigned to any Object3D if no portal rendering is in use. It's not possible to combine portals and octrees in jPCT, so you have to decide which way to go. Octrees are more suitable for terrain rendering while portals are better for indoor scenes. An Object3D will use an octree for rendering if one has been assigned to it. There is no need to enable it explicitly.
The octree may be used for collision detection too. This HAS to be enabled explicitly, because it's disabled by default. An octree is NOT useful in every situation and may even hurt performance when used in the wrong places.

See Also:
Object3D.setOcTree(com.threed.jpct.OcTree), Serialized Form

Field Summary
static boolean COLLISION_DONT_USE
          Don't use this octree to speed up collision detection
static boolean COLLISION_USE
          Use this octree to speed up collision detection
static int MODE_NORMAL
          Builds the octree in the "normal" way
static int MODE_OPTIMIZED
          Tries to build a more optimized octree.
static boolean RENDERING_DONT_USE
          Don't use this octree to speed up rendering
static boolean RENDERING_USE
          Use this octree to speed up rendering
 
Constructor Summary
OcTree()
           
OcTree(Mesh mesh, int maxPoly, int mode)
          Builds a new octree from an Object3D.
OcTree(Mesh mesh, int maxPoly, int maxDepth, int mode)
          Builds a new octree from an Object3D.
OcTree(Object3D obj, int maxPoly, int mode)
          Builds a new octree from an Object3D.
OcTree(Object3D obj, int maxPoly, int maxDepth, int mode)
          Builds a new octree from an Object3D.
 
Method Summary
 boolean getCollisionUse()
          Gets the collision detection setting for this octree.
 java.util.ArrayList<com.threed.jpct.OcTreeNode> getFilledLeafs()
           
 float getRadiusMultiplier()
          Returns the current radius multiplier for this octree.
 boolean getRenderingUse()
          Gets the rendering usage setting for this octree.
 boolean isOfOrderZero()
          If the root-node is the only node in the tree, the tree is of order zero.
 void setCollisionUse(boolean useIt)
          Sets the octree to be used for collision detection.
 void setRadiusMultiplier(float mul)
          Sets the radius multiplier that will be used for the sphere-polygon collision detection.
 void setRenderingUse(boolean useIt)
          Sets the octree to be used for rendering.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_NORMAL

public static final int MODE_NORMAL
Builds the octree in the "normal" way

See Also:
Constant Field Values

MODE_OPTIMIZED

public static final int MODE_OPTIMIZED
Tries to build a more optimized octree. In the current implementation, this will reduce the size of the tree in memory but it may take a bit longer to build the tree.

See Also:
Constant Field Values

COLLISION_USE

public static final boolean COLLISION_USE
Use this octree to speed up collision detection

See Also:
Constant Field Values

COLLISION_DONT_USE

public static final boolean COLLISION_DONT_USE
Don't use this octree to speed up collision detection

See Also:
Constant Field Values

RENDERING_USE

public static final boolean RENDERING_USE
Use this octree to speed up rendering

See Also:
Constant Field Values

RENDERING_DONT_USE

public static final boolean RENDERING_DONT_USE
Don't use this octree to speed up rendering

See Also:
Constant Field Values
Constructor Detail

OcTree

public OcTree(Mesh mesh,
              int maxPoly,
              int mode)
Builds a new octree from an Object3D. The tree may then be assigned to the object (this is NOT done automatically).
This constructor doesn't set the maximum depth of the OcTree, so the tree may become very big and the recursion may fail on large objects.

Parameters:
mesh - the mesh from which the octree should be constructed
maxPoly - the maximum number of polygons a single node may contain. The smaller this number is, the more complex the octree gets. It depends on the object and its usage which number will be the best.
mode - the mode that should be used to construct the object
See Also:
MODE_NORMAL, MODE_OPTIMIZED, Object3D.setOcTree(com.threed.jpct.OcTree)

OcTree

public OcTree(Mesh mesh,
              int maxPoly,
              int maxDepth,
              int mode)
Builds a new octree from an Object3D. The tree may then be assigned to the object (this is NOT done automatically).

Parameters:
mesh - the mesh from which the octree should be constructed
maxPoly - the maximum number of polygons a single node may contain. The smaller this number is, the more complex the octree gets. It depends on the object and its usage which number will be the best.
maxDepth - the maximum depth of the tree. The recursion will end at this depth regardless of the number of polygons in the node.
mode - the mode that should be used to construct the object
See Also:
MODE_NORMAL, MODE_OPTIMIZED, Object3D.setOcTree(com.threed.jpct.OcTree)

OcTree

public OcTree(Object3D obj,
              int maxPoly,
              int mode)
Builds a new octree from an Object3D. The tree may then be assigned to the object (this is NOT done automatically).
This constructor doesn't set the maximum depth of the OcTree, so the tree may become very big and the recursion may fail on large objects.

Parameters:
obj - the object from which's mesh the octree should be constructed
maxPoly - the maximum number of polygons a single node may contain. The smaller this number is, the more complex the octree gets. It depends on the object and its usage which number will be the best.
mode - the mode that should be used to construct the object
See Also:
MODE_NORMAL, MODE_OPTIMIZED, Object3D.setOcTree(com.threed.jpct.OcTree)

OcTree

public OcTree(Object3D obj,
              int maxPoly,
              int maxDepth,
              int mode)
Builds a new octree from an Object3D. The tree may then be assigned to the object (this is NOT done automatically).

Parameters:
obj - the object from which's mesh the octree should be constructed
maxPoly - the maximum number of polygons a single node may contain. The smaller this number is, the more complex the octree gets. It depends on the object and its usage which number will be the best.
maxDepth - the maximum depth of the tree. The recursion will end at this depth regardless of the number of polygons in the node.
mode - the mode that should be used to construct the object
See Also:
MODE_NORMAL, MODE_OPTIMIZED, Object3D.setOcTree(com.threed.jpct.OcTree)

OcTree

public OcTree()
Method Detail

getFilledLeafs

public java.util.ArrayList<com.threed.jpct.OcTreeNode> getFilledLeafs()

setCollisionUse

public void setCollisionUse(boolean useIt)
Sets the octree to be used for collision detection. This may increase collision detection performance. It's enabled by default.

Parameters:
useIt - use it for collision detection...or not...
See Also:
COLLISION_USE, COLLISION_DONT_USE

setRenderingUse

public void setRenderingUse(boolean useIt)
Sets the octree to be used for rendering. This may increase collision detection performance. After creating the octree, this option is enabled. It can be useful to disable it when using compiled objects.

Parameters:
useIt - use it for rendering...or not...
See Also:
RENDERING_USE, RENDERING_DONT_USE

getCollisionUse

public boolean getCollisionUse()
Gets the collision detection setting for this octree.

Returns:
the setting
See Also:
COLLISION_USE, COLLISION_DONT_USE

getRenderingUse

public boolean getRenderingUse()
Gets the rendering usage setting for this octree.

Returns:
the setting
See Also:
RENDERING_USE, RENDERING_DONT_USE

setRadiusMultiplier

public void setRadiusMultiplier(float mul)
Sets the radius multiplier that will be used for the sphere-polygon collision detection. An object that collides with something inside a node may slide into an octree-node that wasn't marked as a possible collider earlier in the process. jPCT doesn't check this for performance reasons. By increasing the radius, more nodes are taken into account to avoid this problem. This comes at the cost of additional processing time. Default is 1.5f.

Parameters:
mul - the multiplier

getRadiusMultiplier

public float getRadiusMultiplier()
Returns the current radius multiplier for this octree.

Returns:
the multiplier

isOfOrderZero

public boolean isOfOrderZero()
If the root-node is the only node in the tree, the tree is of order zero. In that case, using the generated octree is at least questionable. This can be used to assign (to an Object3D) trees of a higher order only.

Returns:
true...or false