Esempio n. 1
0
    public static bool AABBSphereOverlap(bounds _a, sphereBounds _s)
    {
        float x = Mathf.Max(_a.minPoints.x, Mathf.Min(_s.center.x, _a.maxPoints.x));
        float y = Mathf.Max(_a.minPoints.y, Mathf.Min(_s.center.y, _a.maxPoints.y));
        float z = Mathf.Max(_a.minPoints.z, Mathf.Min(_s.center.z, _a.maxPoints.z));

        float distance = Mathf.Sqrt(
            (x - _s.center.x) * (x - _s.center.x) +
            (y - _s.center.y) * (y - _s.center.y) +
            (z - _s.center.z) * (z - _s.center.z));

        return(distance < _s.radius);
    }
Esempio n. 2
0
    public void SelectAllBuildingsInSphere(sphereBounds _s)
    {
        System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
        List <entity> entities          = new List <entity>();

        for (int i = 0; i < gameWorld.entityCount; ++i)
        {
            if (Collision.AABBSphereOverlap(gameWorld.entities[i].bounds, _s))
            {
                entities.Add(gameWorld.entities[i]);
                Debug.Log($"{gameWorld.entities[i].name} was in overlap sphere.");
            }
        }
        sw.Stop();
        Debug.Log($"Select All Buildings In Sphere Took {sw.ElapsedMilliseconds}ms");
    }