|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.bounding.CollisionTree
public class CollisionTree
CollisionTree defines a well balanced red black tree used for triangle
accurate collision detection. The CollisionTree supports three types:
Oriented Bounding Box, Axis-Aligned Bounding Box and Sphere. The tree is
composed of a heirarchy of nodes, all but leaf nodes have two children, a
left and a right, where the children contain half of the triangles of the
parent. This "half split" is executed down the tree until the node is
maintaining a set maximum of triangles. This node is called the leaf node.
Intersection checks are handled as follows:
1. The bounds of the node is checked for intersection. If no intersection
occurs here, no further processing is needed, the children (nodes or
triangles) do not intersect.
2a. If an intersection occurs and we have children left/right nodes, pass the
intersection information to the children.
2b. If an intersection occurs and we are a leaf node, pass each triangle
individually for intersection checking.
Optionally, during creation of the collision tree, sorting can be applied.
Sorting will attempt to optimize the order of the triangles in such a way as
to best split for left and right sub-trees. This function can lead to faster
intersection tests, but increases the creation time for the tree. The number
of triangles a leaf node is responsible for is defined in
CollisionTreeManager. It is actually recommended to allow
CollisionTreeManager to maintain the collision trees for a scene.
CollisionTreeManager
,
Serialized FormNested Class Summary | |
---|---|
static class |
CollisionTree.Type
|
Field Summary | |
---|---|
protected static TreeComparator |
comparator
|
protected TriMesh |
mesh
|
Constructor Summary | |
---|---|
CollisionTree(CollisionTree.Type type)
Constructor creates a new instance of CollisionTree. |
Method Summary | |
---|---|
void |
construct(int childIndex,
Node parent,
boolean doSort)
Recreate this Collision Tree for the given Node and child index. |
void |
construct(TriMesh mesh,
boolean doSort)
Recreate this Collision Tree for the given mesh. |
boolean |
containsAnyLeaf(java.util.ArrayList<java.lang.Integer> triangleIndices)
Checks if this branch or one of its subbranches/leaves contains any of the given triangleIndices |
void |
createTree(int start,
int end,
boolean doSort)
Creates a Collision Tree by recursively creating children nodes, splitting the triangles this node is responsible for in half until the desired triangle count is reached. |
BoundingVolume |
getBounds()
Returns the bounding volume for this tree node in local space. |
BoundingVolume |
getWorldBounds()
Returns the bounding volume for this tree node in world space. |
boolean |
intersect(CollisionTree collisionTree)
Determines if this Collision Tree intersects the given CollisionTree. |
boolean |
intersect(CollisionTree collisionTree,
java.util.ArrayList<java.lang.Integer> aList,
java.util.ArrayList<java.lang.Integer> bList)
Determines if this Collision Tree intersects the given CollisionTree. |
void |
intersect(Ray ray,
java.util.ArrayList<java.lang.Integer> triList)
intersect checks for collisions between this collision tree and a provided Ray. |
boolean |
intersectsBounding(BoundingVolume volume)
Tests if the world bounds of the node at this level intersects a provided bounding volume. |
void |
rebuildLeaves(java.util.ArrayList<java.lang.Integer> triangleIndices,
int startLevel)
Rebuild all the leaves listed in triangleIndices, and any branches leading up to them. |
void |
sortTris()
sortTris attempts to optimize the ordering of the subsection of the array of triangles this node is responsible for. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected TriMesh mesh
protected static final TreeComparator comparator
Constructor Detail |
---|
public CollisionTree(CollisionTree.Type type)
type
- the type of collision tree to makeCollisionTree.Type
Method Detail |
---|
public void construct(int childIndex, Node parent, boolean doSort)
childIndex
- the index of the child to generate the tree for.parent
- The Node that this OBBTree should represent.doSort
- true to sort triangles during creation, false otherwisepublic void construct(TriMesh mesh, boolean doSort)
mesh
- The trimesh that this OBBTree should represent.doSort
- true to sort triangles during creation, false otherwisepublic void createTree(int start, int end, boolean doSort)
start
- The start index of the tris array, inclusive.end
- The end index of the tris array, exclusive.doSort
- True if the triangles should be sorted at each level, false
otherwise.public boolean intersectsBounding(BoundingVolume volume)
volume
- the volume to intersect with.
public boolean intersect(CollisionTree collisionTree)
collisionTree
- The Tree to test.
public boolean intersect(CollisionTree collisionTree, java.util.ArrayList<java.lang.Integer> aList, java.util.ArrayList<java.lang.Integer> bList)
collisionTree
- The Tree to test.aList
- a list to contain the colliding triangles of this mesh.bList
- a list to contain the colliding triangles of the testing mesh.
public void intersect(Ray ray, java.util.ArrayList<java.lang.Integer> triList)
ray
- the ray to test for intersections.triList
- the list to store instersections with.public BoundingVolume getBounds()
public BoundingVolume getWorldBounds()
public void sortTris()
public void rebuildLeaves(java.util.ArrayList<java.lang.Integer> triangleIndices, int startLevel)
triangleIndices
- a list of all the leaves to rebuildstartLevel
- how many trunk levels to ignore, for none put zero (ignoring
the first 2-3 levels increases speed greatly)public boolean containsAnyLeaf(java.util.ArrayList<java.lang.Integer> triangleIndices)
triangleIndices
- the indices to look for
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |