Beispiel #1
0
    private void FireBeam(bool isInstant)
    {
        Vector3Int binGridDimensions   = voxelGrid.GetBinGridDimensions();
        Vector3Int voxelGridDimensions = VoxelGrid.CalculateVoxelGridDimensions(binGridDimensions);

        Vector3    mouseWorldPos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int lineStartCoords = voxelGrid.GetVoxelCoordsFromWorldPos(mouseWorldPos);
        Vector3Int lineEndCoords   = voxelGrid.GetVoxelCoordsFromWorldPos(mouseWorldPos + Camera.main.transform.forward * 100);

        Vector3Int[] line = Bresenhams3D.GetLine(lineStartCoords, lineEndCoords);

        for (int i = 0; i < line.Length; i++)
        {
            Vector3Int lineVoxelCoords = line[i];

            if (!VoxelGrid.AreCoordsWithinDimensions(lineVoxelCoords, voxelGridDimensions))
            {
                continue;
            }

            voxelGrid.TrySetVoxelExists(lineVoxelCoords, exists: false);
            if (!isInstant)
            {
                break;
            }
        }
    }
    public void AreCoordsWithinDimensions()
    {
        for (int i = 0; i < 25; i++)
        {
            Vector3Int dimensions = new Vector3Int(Random.Range(1, 10), Random.Range(1, 10), Random.Range(1, 10));
            Vector3Int coords     = new Vector3Int(Random.Range(0, dimensions.x), Random.Range(0, dimensions.y), Random.Range(0, dimensions.z));

            Assert.IsTrue(VoxelGrid.AreCoordsWithinDimensions(coords, dimensions));
            Assert.IsFalse(VoxelGrid.AreCoordsWithinDimensions(dimensions, dimensions));
        }
    }