// // Constructors // public CollisionPairEvaluator() : base() { this.subscription = new CollisionSubscription(); this.name = Name.UNINITIALIZED; this.collisionTreeRootFirst = null; this.collisionTreeRootSecond = null; this.firstTvr = new PCSTraverser(null); this.secondTvr = new PCSTraverser(null); this.iterator = new PCSIterator(null); this.collisionChecks = 1; this.scanEntireFirstTree = false; }
/// <summary> /// Checks collisons with every object in the tree /// against only the root of the other tree /// </summary> /// <param name="treeTvr"> /// The tree to narrow down (as a PCS traverser) /// </param> /// <param name="otherRoot"> /// The other tree to check against /// </param> /// <returns>A GameObject that collides with other tree, otherwise null</returns> private GameObject NarrowDownCollisonTree(PCSTraverser treeTvr, GameObject otherRoot) { // Make sure the traverser starts at the root treeTvr.StartOver(); // Loop through (almost) every object in this tree (pointed by the traverser) while (treeTvr.IsValid()) { GameObject current = treeTvr.GetCurrent() as GameObject; // Check if the current object collides with the other root if (Collider.Intersect(current.Collider, otherRoot.Collider)) { // If the current object has children if (treeTvr.IsThereChild()) { // Check collisons with the children treeTvr.NextChild(); } // The current object is at the bottom of the // collison hierarchy (it is a last-child node) else { // A collison was found! break; } } // No collision else { // Go to the next sibling // If there are no more siblings, this loop breaks treeTvr.NextSibling(); } } // Return the current object. This can be null. return(treeTvr.GetCurrent() as GameObject); }