Exemplo n.º 1
0
        public List <JCollider> FindOverlaps(JCollider colliderA)
        {
            var output  = new List <JCollider>(10);
            var boundsA = colliderA.meshFrame.AABB;
            var meshA   = colliderA.meshFrame;

            collisionMapQueue.ResetQueueIteration();
            while (collisionMapQueue.HasNext())
            {
                var map = collisionMapQueue.Next();
                if (map.bodies != null && JMeshOverlap.AABBOverlap(boundsA, map.bounds))
                {
                    for (var i = 0; i < map.bodies.Count; i++)
                    {
                        var colliderB = map.bodies[i];
                        if (output.Contains(colliderB))
                        {
                            continue;
                        }

                        if (JLayerMaskUtil.MaskCheck(JLayerMaskUtil.GetLayerMask(colliderA.jLayer), colliderB.jLayer) &&
                            JMeshOverlap.AABBOverlap(boundsA, colliderB.meshFrame.AABB) &&
                            JMeshOverlap.MeshesOverlap(meshA, colliderB.meshFrame))
                        {
                            output.Add(colliderB);
                        }
                    }
                }
            }

            return(output);
        }
Exemplo n.º 2
0
        // Modifies completedCollisions by always trying to add the new collision pair to the list
        private bool ShouldSkipCollisionCheck(JCollider colliderA, JCollider colliderB, HashSet <JCollisionPair> completedCollisions)
        {
            if (!JLayerMaskUtil.MaskCheck(JLayerMaskUtil.GetLayerMask(colliderA.jLayer), colliderB.jLayer))
            {
                return(true);
            }

            var collisionPair = new JCollisionPair(colliderA, colliderB);

            if (!completedCollisions.Add(collisionPair))    // This is where the methods mutates completedCollisions
            {
                return(true);
            }

            var boundsA = colliderA.meshFrame.AABB;
            var boundsB = colliderB.meshFrame.AABB;

            if (!JMeshOverlap.AABBOverlap(boundsA, boundsB))
            {
                return(true);
            }

            var meshA = colliderA.meshFrame;
            var meshB = colliderB.meshFrame;

            if (!JMeshOverlap.MeshesOverlap(meshA, meshB))
            {
                return(true);
            }
            return(false);
        }