APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.math

public Class Octree<T>

extends Object
Class Inheritance
Imports
com.badlogic.gdx.math.collision.BoundingBox, .Ray, com.badlogic.gdx.utils.Array, .ObjectSet, .Pool

A static Octree implementation. Example of usage:
Vector3 min = new Vector3(-10, -10, -10);
Vector3 max = new Vector3(10, 10, 10);
octree = new Octree(min, max, MAX_DEPTH, MAX_ITEMS_PER_NODE, new Octree.Collider() {
	@Override
	public boolean intersects (BoundingBox nodeBounds, GameObject geometry) {
		return nodeBounds.intersects(geometry.box);
	}

	@Override
	public boolean intersects (Frustum frustum, GameObject geometry) {
		return frustum.boundsInFrustum(geometry.box);
	}

	@Override
	public float intersects (Ray ray, GameObject geometry) {
		if (Intersector.intersectRayBounds(ray, geometry.box, new Vector3())) {
			return tmp.dst2(ray.origin);
		}
		return Float.MAX_VALUE;
	}
});

// Adding game objects to the octree
octree.add(gameObject1);
octree.add(gameObject2);

// Querying the result
ObjectSet result = new ObjectSet<>();
octree.query(cam.frustum, result);

// Rendering the result
for (GameObject gameObject : result) {
	modelBatch.render(gameObject);
}

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Octree.Collider<T>

Interface used by octree to handle geometries' collisions against BoundingBox, Frustum and Ray.

protected class
public static class

Field Summary

Modifier and TypeField and Description
pack-priv final Octree.Collider<T>
pack-priv final int
pack-priv final Pool<Octree<T>.OctreeNode>
protected Octree<T>.OctreeNode
pack-priv static final Vector3

Constructor Summary

AccessConstructor and Description
public
Octree(Vector3 minimum, Vector3 maximum, int maxDepth, int maxItemsPerNode, Octree.Collider<T> collider)

Method Summary

Modifier and TypeMethod and Description
public void
add(T object)

pack-priv Octree<T>.OctreeNode
createNode(Vector3 min, Vector3 max, int level)

public ObjectSet<T>

Returns:

the result set
getAll
(ObjectSet<T> resultSet)

Method to retrieve all the geometries.

public ObjectSet<BoundingBox>
getNodesBoxes(ObjectSet<BoundingBox> boxes)

Method to get nodes as bounding boxes.

public ObjectSet<T>
query(BoundingBox
- The bounding box to query
aabb
,
ObjectSet<T>
- Set to be populated with objects inside the BoundingBoxes
result
)

Method to query geometries inside nodes that the aabb intersects.

public ObjectSet<T>
query(Frustum
- The frustum to query
frustum
,
ObjectSet<T>
set populated with objects near from the frustum
result
)

Method to query geometries inside nodes that the frustum intersects.

public T
rayCast(Ray ray, Octree.RayCastResult<T> result)

public void
remove(T object)

public void
update(T object)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

colliderback to summary
pack-priv final Octree.Collider<T> collider
maxItemsPerNodeback to summary
pack-priv final int maxItemsPerNode
nodePoolback to summary
pack-priv final Pool<Octree<T>.OctreeNode> nodePool
rootback to summary
protected Octree<T>.OctreeNode root
tmpback to summary
pack-priv static final Vector3 tmp

Constructor Detail

Octreeback to summary
public Octree(Vector3 minimum, Vector3 maximum, int maxDepth, int maxItemsPerNode, Octree.Collider<T> collider)

Method Detail

addback to summary
public void add(T object)
createNodeback to summary
pack-priv Octree<T>.OctreeNode createNode(Vector3 min, Vector3 max, int level)
getAllback to summary
public ObjectSet<T> getAll(ObjectSet<T> resultSet)

Method to retrieve all the geometries.

Returns:ObjectSet<T>

the result set

getNodesBoxesback to summary
public ObjectSet<BoundingBox> getNodesBoxes(ObjectSet<BoundingBox> boxes)

Method to get nodes as bounding boxes. Useful for debug purpose.

queryback to summary
public ObjectSet<T> query(BoundingBox aabb, ObjectSet<T> result)

Method to query geometries inside nodes that the aabb intersects. Can be used as broad phase.

Parameters
aabb:BoundingBox

- The bounding box to query

result:ObjectSet<T>

- Set to be populated with objects inside the BoundingBoxes

queryback to summary
public ObjectSet<T> query(Frustum frustum, ObjectSet<T> result)

Method to query geometries inside nodes that the frustum intersects. Can be used as broad phase.

Parameters
frustum:Frustum

- The frustum to query

result:ObjectSet<T>

set populated with objects near from the frustum

rayCastback to summary
public T rayCast(Ray ray, Octree.RayCastResult<T> result)
removeback to summary
public void remove(T object)
updateback to summary
public void update(T object)
com.badlogic.gdx.math back to summary

public Interface Octree.Collider<T>


Interface used by octree to handle geometries' collisions against BoundingBox, Frustum and Ray.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

if they are intersecting
intersects
(BoundingBox nodeBounds, T geometry)

Method to calculate intersection between aabb and the geometry.

public boolean

Returns:

if they are intersecting
intersects
(Frustum frustum, T geometry)

Method to calculate intersection between frustum and the geometry.

public float

Returns:

distance between ray and geometry
intersects
(Ray ray, T geometry)

Method to calculate intersection between ray and the geometry.

Method Detail

intersectsback to summary
public boolean intersects(BoundingBox nodeBounds, T geometry)

Method to calculate intersection between aabb and the geometry.

Returns:boolean

if they are intersecting

intersectsback to summary
public boolean intersects(Frustum frustum, T geometry)

Method to calculate intersection between frustum and the geometry.

Returns:boolean

if they are intersecting

intersectsback to summary
public float intersects(Ray ray, T geometry)

Method to calculate intersection between ray and the geometry.

Returns:float

distance between ray and geometry

com.badlogic.gdx.math back to summary

protected Class Octree.OctreeNode

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final BoundingBox
private Octree.OctreeNode[]
private final Array<T>
pack-priv boolean
pack-priv int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
add(T geometry)

private void
private void
free()

protected void
getAll(ObjectSet<T> resultSet)

Get all geometries using Depth-First Search recursion.

protected void
getBoundingBox(ObjectSet<BoundingBox> bounds)

Get bounding boxes using Depth-First Search recursion.

protected boolean
private void
protected void
query(BoundingBox aabb, ObjectSet<T> result)

protected void
query(Frustum frustum, ObjectSet<T> result)

protected void
rayCast(Ray ray, Octree.RayCastResult<T> result)

protected boolean
remove(T object)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundsback to summary
pack-priv final BoundingBox bounds
childrenback to summary
private Octree.OctreeNode[] children
geometriesback to summary
private final Array<T> geometries
leafback to summary
pack-priv boolean leaf
levelback to summary
pack-priv int level

Constructor Detail

OctreeNodeback to summary
protected OctreeNode()

Method Detail

addback to summary
protected void add(T geometry)
clearChildrenback to summary
private void clearChildren()
freeback to summary
private void free()
getAllback to summary
protected void getAll(ObjectSet<T> resultSet)

Get all geometries using Depth-First Search recursion.

getBoundingBoxback to summary
protected void getBoundingBox(ObjectSet<BoundingBox> bounds)

Get bounding boxes using Depth-First Search recursion.

isLeafback to summary
protected boolean isLeaf()
mergeback to summary
private void merge()
queryback to summary
protected void query(BoundingBox aabb, ObjectSet<T> result)
queryback to summary
protected void query(Frustum frustum, ObjectSet<T> result)
rayCastback to summary
protected void rayCast(Ray ray, Octree.RayCastResult<T> result)
removeback to summary
protected boolean remove(T object)
splitback to summary
private void split()
com.badlogic.gdx.math back to summary

public Class Octree.RayCastResult<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv float
pack-priv T
pack-priv float

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

distanceback to summary
pack-priv float distance
geometryback to summary
pack-priv T geometry
maxDistanceSqback to summary
pack-priv float maxDistanceSq

Constructor Detail

RayCastResultback to summary
public RayCastResult()