Class DynamicBVH<T>
A Dynamic Binary Volume Hierarchy implementation.
Inherited Members
Namespace: Evergine.Common.Helpers
Assembly: Evergine.Common.dll
Syntax
public class DynamicBVH<T>
Type Parameters
Name | Description |
---|---|
T | The object contained. |
Remarks
Inspired in Box2D b2DynamicTree https://github.com/erincatto/Box2D/blob/master/Box2D/Collision/b2DynamicTree.h.
Constructors
DynamicBVH(int)
Initializes a new instance of the DynamicBVH<T> class.
Declaration
public DynamicBVH(int defaultNodeCapacity = 16)
Parameters
Type | Name | Description |
---|---|---|
int | defaultNodeCapacity | The default node capacity. |
Fields
NodeCount
The node count.
Declaration
public int NodeCount
Field Value
Type | Description |
---|---|
int |
Nodes
The node array.
Declaration
public DynamicBVHNode<T>[] Nodes
Field Value
Type | Description |
---|---|
DynamicBVHNode<T>[] |
Properties
AreaRatio
Gets the ratio of the sum of the node areas to the root area.
Declaration
public float AreaRatio { get; }
Property Value
Type | Description |
---|---|
float |
Height
Gets the height of the binary tree in O(N) time. Should not be called often.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
int |
MaxBalance
Gets the maximum balance of an node in the tree. The balance is the difference in height of the two children of a node.
Declaration
public int MaxBalance { get; }
Property Value
Type | Description |
---|---|
int |
Methods
CreateProxy(ref BoundingBox, T)
Create a proxy. Provide a tight fitting AABB and a userData pointer.
Declaration
public int CreateProxy(ref BoundingBox aabb, T userData)
Parameters
Type | Name | Description |
---|---|---|
BoundingBox | aabb | The AABB. |
T | userData | The userData. |
Returns
Type | Description |
---|---|
int | The proxy Id. |
DestroyProxy(int)
Destroy a proxy. This asserts if the id is invalid.
Declaration
public void DestroyProxy(int proxyId)
Parameters
Type | Name | Description |
---|---|---|
int | proxyId | The proxy Id. |
GetFatAABB(int, out BoundingBox)
Get the fat AABB for a proxy.
Declaration
public void GetFatAABB(int proxyId, out BoundingBox fatAABB)
Parameters
Type | Name | Description |
---|---|---|
int | proxyId | The proxy Id. |
BoundingBox | fatAABB | Output value for fat AABB. |
GetUserData(int)
Get proxy user data.
Declaration
public T GetUserData(int proxyId)
Parameters
Type | Name | Description |
---|---|---|
int | proxyId | The proxy Id. |
Returns
Type | Description |
---|---|
T | the proxy user data or null if the id is invalid. |
MoveProxy(int, ref BoundingBox, ref Vector3)
Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.
Declaration
public bool MoveProxy(int proxyId, ref BoundingBox aabb, ref Vector3 displacement)
Parameters
Type | Name | Description |
---|---|---|
int | proxyId | The proxy Id. |
BoundingBox | aabb | The AABB. |
Vector3 | displacement | The displacement. |
Returns
Type | Description |
---|---|
bool | true if the proxy was re-inserted. |
Query<TResult>(QueryDelegate<TResult>, ref BoundingBox)
Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.
Declaration
public TResult Query<TResult>(DynamicBVH<T>.QueryDelegate<TResult> callback, ref BoundingBox aabb)
Parameters
Type | Name | Description |
---|---|---|
DynamicBVH<T>.QueryDelegate<TResult> | callback | A callback function called on every hit. |
BoundingBox | aabb | The AABB to test. |
Returns
Type | Description |
---|---|
TResult | The query result. |
Type Parameters
Name | Description |
---|---|
TResult | The result type. |
RayCast(QueryDelegate, ref Ray)
Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree.
Declaration
public void RayCast(DynamicBVH<T>.QueryDelegate callback, ref Ray input)
Parameters
Type | Name | Description |
---|---|---|
DynamicBVH<T>.QueryDelegate | callback | A callback class that is called for each proxy that is hit by the ray. |
Ray | input | The ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). |
RebuildBottomUp()
Build an optimal tree. Very expensive. For testing.
Declaration
public void RebuildBottomUp()
ShiftOrigin(ref Vector3)
Shift the world origin. Useful for large worlds. The shift formula is: position -= newOrigin.
Declaration
public void ShiftOrigin(ref Vector3 newOrigin)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | newOrigin | The new origin with respect to the old origin. |
Validate()
Validate this tree. For testing.
Declaration
public void Validate()