Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static CollisionMap GenerateMapFor(List <JCollider> bodies, int maxNumberOfElements, Bounds bounds)
        {
            var rootCollisionMap = new CollisionMap();

            if (bodies.Count <= maxNumberOfElements || bounds.size.x <= MinBoundsWidth)
            {
                rootCollisionMap.bodies = new List <JCollider>(bodies);
                rootCollisionMap.bounds = bounds;
            }
            else
            {
                var newXSize = bounds.size.x / 2;

                var boundsChildA = new Bounds(
                    new Vector3(newXSize / 2 + bounds.min.x, 0, bounds.center.z),
                    new Vector3(newXSize, 0, bounds.size.z));

                var boundsChildB = new Bounds(
                    new Vector3(newXSize / 2 + bounds.center.x, 0, bounds.center.z),
                    new Vector3(newXSize, 0, bounds.size.z));

                List <JCollider> childABodies = new List <JCollider>();
                List <JCollider> childBBodies = new List <JCollider>();

                for (var i = 0; i < bodies.Count; i++)
                {
                    var body = bodies[i];
                    if (JMeshOverlap.AABBOverlap(boundsChildA, body.meshFrame.AABB))
                    {
                        childABodies.Add(body);
                    }
                    if (JMeshOverlap.AABBOverlap(boundsChildB, body.meshFrame.AABB))
                    {
                        childBBodies.Add(body);
                    }
                }

                rootCollisionMap.subMaps = new List <CollisionMap>();
                rootCollisionMap.subMaps.Add(GenerateMapFor(childABodies, maxNumberOfElements, boundsChildA));
                rootCollisionMap.subMaps.Add(GenerateMapFor(childBBodies, maxNumberOfElements, boundsChildB));
            }

            return(rootCollisionMap);
        }