Exemple #1
0
        public void CheckCollision(ColliderProxy obj, ref LRect checkBounds)
        {
            // Are the input bounds at least partially in this node?
            if (!bounds.Overlaps(checkBounds))
            {
                return;
            }

            // Check against any objects in this node
            for (int i = 0; i < objects.Count; i++)
            {
                var o = objects[i];
                if (!ReferenceEquals(o.Obj, obj) &&
                    BoundsQuadTree.FuncCanCollide(o.Obj, obj) &&
                    o.Bounds.Overlaps(checkBounds)
                    )
                {
                    BoundsQuadTree.funcOnCollide(obj, o.Obj);
                }
            }

            // Check children
            if (children != null)
            {
                for (int i = 0; i < NUM_CHILDREN; i++)
                {
                    children[i].CheckCollision(obj, ref checkBounds);
                }
            }
        }
Exemple #2
0
        public void DoStart(int[][] interestingMasks, int[] allTypes)
        {
            this.InterestingMasks = interestingMasks;
            this.AllTypes         = allTypes;
            //init _collisionMask//TODO read from file
            for (int i = 0; i < _collisionMask.Length; i++)
            {
                _collisionMask[i] = (uint)(~(1 << i));
            }

            // Initial size (metres), initial centre position, minimum node size (metres), looseness
            foreach (var type in allTypes)
            {
                var boundsTree = new BoundsQuadTree(worldSize, pos, minNodeSize, loosenessval);
                boundsTrees.Add(boundsTree);
            }

            BoundsQuadTree.FuncCanCollide = NeedCheck;
            BoundsQuadTree.funcOnCollide  = OnQuadTreeCollision;
        }