Exemple #1
0
    public static bool TryGetNextQuadrantInRadius(ref GuadrantIterator iterator)
    {
        if (iterator.currentIterateRadius * QuadrantSystem.quadrantSize > iterator.radius + 2 * QuadrantSystem.quadrantSize)
        {
            return(false);
        }

        iterator.indexHor++;

        if (iterator.indexVer > iterator.currentIterateRadius)
        {
            iterator.currentIterateRadius++;
            iterator.indexVer = -iterator.currentIterateRadius;
            iterator.indexHor = 0;
        }
        else if (iterator.indexHor > iterator.currentIterateRadius - math.abs(iterator.indexVer))
        {
            iterator.indexVer++;
            iterator.indexHor = -(iterator.currentIterateRadius - math.abs(iterator.indexVer));
        }

        iterator.quadrant = GetQuadrant(
            new float3()
        {
            x = iterator.position.x + iterator.indexHor * QuadrantSystem.quadrantSize,
            y = iterator.position.y + iterator.indexVer * QuadrantSystem.quadrantSize,
            z = iterator.position.z
        }
            );

        return(true);
    }
Exemple #2
0
    public static bool TryGetFirstQuadrantInRadius(float3 position, float radius, out GuadrantIterator iterator)
    {
        iterator = new GuadrantIterator()
        {
            position = position,
            radius   = radius,
            quadrant = GetQuadrant(position),

            currentIterateRadius = 0,
            indexHor             = 0,
            indexVer             = 0
        };
        return(true);
    }