Ejemplo n.º 1
0
    protected void RayEntersCellFromCell(Ray ray, Vector3i cell, Vector3i outCell, out float outDistance)
    {
        float closestDistance = float.MaxValue;
        float distance;

        int highX = cell.x + 1;
        int highY = cell.y + 1;
        int highZ = cell.z + 1;

        if (CollisionUtil.IntersectsBounds(ray, cell.x, cell.y, cell.z, cell.x, highY, highZ, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x - 1, cell.y, cell.z);
                closestDistance = distance;
            }
        }
        if (CollisionUtil.IntersectsBounds(ray, cell.x, cell.y, cell.z, highX, cell.y, highZ, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x, cell.y - 1, cell.z);
                closestDistance = distance;
            }
        }
        if (CollisionUtil.IntersectsBounds(ray, cell.x, cell.y, cell.z, highX, highY, cell.z, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x, cell.y, cell.z - 1);
                closestDistance = distance;
            }
        }
        if (CollisionUtil.IntersectsBounds(ray, highX, cell.y, cell.z, highX, highY, highZ, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x + 1, cell.y, cell.z);
                closestDistance = distance;
            }
        }

        if (CollisionUtil.IntersectsBounds(ray, cell.x, highY, cell.z, highX, highY, highZ, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x, cell.y + 1, cell.z);
                closestDistance = distance;
            }
        }
        if (CollisionUtil.IntersectsBounds(ray, cell.x, cell.y, highZ, highX, highY, highZ, out distance))
        {
            if (distance < closestDistance)
            {
                outCell.Set(cell.x, cell.y, cell.z + 1);
                closestDistance = distance;
            }
        }

        outDistance = closestDistance;
    }