///
/// This abstract class is extended by any type of primitive geometry that can be tested for
/// collisions with moving points or boxes. In this sample it is only extended by the
/// CollisionTriangle class.
///
public abstract class CollideableElement : Node
{
/*
* CLASS PROPERTIES
*/
///
/// flag to indicate if the collideable
/// element needs it's definition updated
///
public bool NeedsUpdate;
///
/// bounding box of collideable element
///
public Bounds box;
///
/// all tree nodes in which this
/// dynamic collidable element is in
///
private List treeNodes;
///
/// recurse id used to compute selections
/// without getting redundant elements
///
private uint mLastSearchId;
/*
* CONSTRUCTOR
*/
///
/// constructor for a collideable element
///
public CollideableElement(TwelveCylinderGame newGame)
: base(newGame)
{
treeNodes = new List();
mLastSearchId = 0;
}
/*
* ABSTRACT METHODS
*/
///
/// updates the bounding collision box definition
/// to ensure it exactley contains the element
///
public abstract void updateCollisionBox();
///
/// intersect a moving point with the element
///
public abstract void PointIntersect(ref MovingPointData pointData);
///
/// intersects a moving box with the element
///
public abstract bool BoxIntersect(MovingBoxData boxData, out float collisionDistance,
out Vector3 collisionPosition, out Vector3 collisionNormal);
/*
* TREE NODE LIST
*/
///
/// adds a tree node to this collidable element's containing list
///
public virtual void AddTreeNode(CollisionTreeNode treeNode)
{
treeNodes.Add(treeNode);
}
///
/// removes a single tree node from this collidable element's containing list
///
public virtual void RemoveTreeNode(CollisionTreeNode xTreeNode)
{
treeNodes.Remove(xTreeNode);
}
///
/// Removes this element from the tree
///
public void RemoveFromAllNodes()
{
// remove element from all nodes it is associated with
foreach (CollisionTreeNode n in treeNodes)
n.RemoveElement(this);
treeNodes.Clear();
}
}