public static MeshData GenerateTerrainMesh(Vector3[,] points)
    {
        int width  = points.GetLength(0);
        int height = points.GetLength(1);

        int vertexIndex = 0;

        MeshData meshData = new MeshData(width, height);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                meshData.vertices[vertexIndex] = points[x, y];
                meshData.uvs[vertexIndex]      = new Vector2(x / (float)width, 1f - y / (float)height);

                if (x < width - 1 && y < height - 1)
                {
                    meshData.AddTriangle(vertexIndex, vertexIndex + width, vertexIndex + width + 1);
                    meshData.AddTriangle(vertexIndex + width + 1, vertexIndex + 1, vertexIndex);
                }

                vertexIndex++;
            }
        }

        return(meshData);
    }
    public void generateCaves(Vector3[,] caveVoidPoints, int radius)
    {
        int numberOfCaves      = caveVoidPoints.GetLength(0);
        int numberOfVoidPoints = caveVoidPoints.GetLength(1);

        for (int i = 0; i < numberOfCaves; i++)
        {
            for (int j = 0; j < numberOfVoidPoints; j++)
            {
                Vector3 voidPoint = caveVoidPoints [i, j];
                for (int x = -1 * radius; x <= radius; x++)
                {
                    for (int y = -1 * radius; y <= radius; y++)
                    {
                        for (int z = -1 * radius; z <= radius; z++)
                        {
                            Vector3 temp = new Vector3(voidPoint.x + x, voidPoint.y + y, voidPoint.z + z);
                            Instantiate(undergroundBlock, temp, Quaternion.identity);
                            Debug.Log(temp.x + " " + temp.y + " " + temp.z + " ");
                            worldBlocks [(int)voidPoint.x + x, (int)voidPoint.y + y, (int)voidPoint.z + z] = null;
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
0
    public void updateMesh()
    {
        Vector3[] vs = new Vector3[vertices.Length];
        Vector3[,] mat = getMatrix(vertices, MAX_COUNT);
        int i = 0;

        for (int j = 0; j < mat.GetLength(0); j++)
        {
            for (int k = 0; k < mat.GetLength(1); k++, i++)
            {
                float perlin = 0;

                perlin  = perlinOffset + perlinAmp1 * Mathf.PerlinNoise(getFloat(j + pos[0] + 5) * perlinDensity1 / 100f, getFloat(k + pos[1]) * perlinDensity1 / 100f) / 100f;
                perlin += perlinAmp2 * Mathf.PerlinNoise(getFloat(j + pos[0] + 5) * perlinDensity2 / 10f, getFloat(k + pos[1]) * perlinDensity2 / 10f) / 100f;
                perlin += perlinAmp3 * Mathf.PerlinNoise(getFloat(j + pos[0] + 5) * perlinDensity3 / 10f, getFloat(k + pos[1]) * perlinDensity3 / 10f) / 100f;

                vs[i] = vertices[i];

                vs[i].y = hMultiplier * perlin;
            }
        }

        mesh.vertices = vs;
        mf.mesh       = mesh;

        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
    }
Esempio n. 4
0
 public Vector3 GetWorldPositionOfCenterOfTile(Vector2Int tile)
 {
     /*
      * for(int i = 0; i < walkableTiles.Count; i++)
      * {
      *  if(walkableTiles[i].x == tile.x)
      *  {
      *      if(walkableTiles[i].y == tile.y)
      *      {
      *          float halfTilesize = tileSize / 2;
      *          return new Vector3(worldWalkableTiles[i].x + halfTilesize, worldWalkableTiles[i].y + halfTilesize);
      *      }
      *  }
      * }
      *
      * return Vector3.zero;
      */
     if ((tile.x < worldWalkableTilesArray.GetLength(0)) &&
         (tile.x >= 0) &&
         (tile.y < worldWalkableTilesArray.GetLength(1)) &&
         (tile.y >= 0))
     {
         float   halfTilesize = tileSize / 2;
         Vector3 bottomLeft   = worldWalkableTilesArray[tile.x, tile.y];
         return(new Vector3(bottomLeft.x + halfTilesize, bottomLeft.y + halfTilesize));
     }
     else
     {
         return(Vector3.zero);
     }
 }
        /// <summary>
        /// Converts vertex graph to on dimensional vertex array
        /// </summary>
        /// <param name="gridVertexGraph"></param>
        /// <returns></returns>
        private Vector3[] CreateGridVertexGraphArray(Vector3[,] gridVertexGraph)
        {
            int columnCount = gridVertexGraph.GetLength(0);
            int rowCount    = gridVertexGraph.GetLength(1);

            List <Vector3> vertices = new List <Vector3>();

            for (int i = 0; i < columnCount - 1; i++)
            {
                for (int j = 0; j < rowCount - 1; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        vertices.Add(gridVertexGraph[i + k, j]);
                        vertices.Add(gridVertexGraph[i + k, j + 1]);
                    }
                }
            }
            Vector3[] gridVertexArray = new Vector3[vertices.Count];

            for (int i = 3; i < vertices.Count; i += 4)
            {
                gridVertexArray[i - 3] = vertices[i - 3];
                gridVertexArray[i - 2] = vertices[i - 1];
                gridVertexArray[i - 1] = vertices[i - 2];
                gridVertexArray[i]     = vertices[i];
            }

            return(gridVertexArray);
        }
//Subdivide the landmass into a grid of 3D positions for agents to move to
//Check using a raycast if there is ground underneath, if not specify that area as a place for water
    void createGrid()
    {
        grid = new Vector3[h, w];
        for (int j = 0; j < grid.GetLength(0); j++)
        {
            for (int i = 0; i < grid.GetLength(1); i++)
            {
                float x           = (i - landmass.transform.localScale.x / 2) + tile.transform.localScale.x / 2;
                float z           = (j - landmass.transform.localScale.z / 2) + tile.transform.localScale.y / 2;
                int   occupiedVal = occupied[j, i];
                grid[j, i] = new Vector3(x, 2.75f, z);
                r          = new Ray(new Vector3(x, 2.75f, z), Vector3.down);
                RaycastHit hit;
                if (Physics.Raycast(r.origin, Vector3.down, out hit, 2f))
                {
                    var currentTile = Instantiate(water, new Vector3(x, 2.75f, z), tile.transform.rotation);
                    currentTile.transform.parent = GameObject.FindGameObjectWithTag("Tiles").transform;
                    occupied[j, i] = -1;
                }
                if (showGrid)
                {
                    if (occupied[j, i] == 1)
                    {
                        var currentTile = Instantiate(visitedTile, new Vector3(x, 2.75f, z), tile.transform.rotation);
                        currentTile.transform.parent = GameObject.FindGameObjectWithTag("Tiles").transform;
                    }
                    else if (occupied[j, i] != -1)
                    {
                        var currentTile = Instantiate(tile, new Vector3(x, 2.75f, z), tile.transform.rotation);
                        currentTile.transform.parent = GameObject.FindGameObjectWithTag("Tiles").transform;
                    }
                }
            }
        }
    }
    private void PlaceItems(Vector3[,] positionMatrix, GameObject parent, GameObject itemPrefab, int itemCount)
    {
        if (itemCount > positionMatrix.Length)
        {
            throw new Exception("There are too few rows in comparison to the itemCount in car.");
        }

        int a = 0;
        int b = positionMatrix.GetLength(1) - 1;

        for (int i = 0; i < itemCount; i++)
        {
            GameObject obj = Instantiate(itemPrefab);
            obj.transform.position = positionMatrix[a, b];
            obj.transform.SetParent(parent.transform);

            a += 1;

            if (a >= positionMatrix.GetLength(0))
            {
                a  = 0;
                b -= 1;
            }
        }
    }
        public static Bitmap GetImage(this Vector3[,] array)
        {
            int    width  = array.GetLength(0);
            int    height = array.GetLength(1);
            Bitmap map    = new Bitmap(width, height);

            BitmapData data = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                byte *byte_data = (byte *)data.Scan0.ToPointer();
                int   pos;
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        pos            = (y * width + x) * 4;
                        byte_data[pos] = (byte)(array[x, y].z * 255);
                        pos++;
                        byte_data[pos] = (byte)(array[x, y].y * 255);
                        pos++;
                        byte_data[pos] = (byte)(array[x, y].x * 255);
                        pos++;
                        byte_data[pos] = 255;
                        pos++;
                    }
                }
            }

            map.UnlockBits(data);

            return(map);
        }
Esempio n. 9
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Vector3[,] val = Procedurs.Medium(openFileDialog1.FileName);
                Morf morf = Morf.GenerateKMean(val, 5);
                morf.RemoveEmptyRegions();
                List <Vector3> avrs = new List <Vector3>();
                for (int i = 0; i < morf.regions.Count; i++)
                {
                    avrs.Add(morf.regions[i].GetAverage(val));
                }
                float[,] temp  = new float[val.GetLength(0), val.GetLength(1)];
                float[,] temp2 = new float[val.GetLength(0), val.GetLength(1)];

                VideoProcessig videoProcessig = new VideoProcessig(openFileDialog1.FileName, (map) =>
                {
                    val.WriteRGB(map);
                    Procedurs.MorfSubtract(morf, avrs, val, temp);
                    temp2.ForEach(() => 0);
                    Procedurs.BlockSum(temp, temp2, 5);
                    temp2.RegMaximum();
                    return(temp2);
                });
                videoProcessig.Show();
            }
        }
Esempio n. 10
0
        public Vector3[,] DistInAvr(Vector3[,] map, Vector3 color)
        {
            int width  = map.GetLength(0);
            int height = map.GetLength(1);

            Vector3[,] result = new Vector3[width, height];

            List <float> dist = new List <float>();

            for (int i = 0; i < regions.Count; i++)
            {
                Vector3 avr = regions[i].GetAverage(map);
                dist.Add((avr - color).Magnitude());
            }

            //int minIndex = 0;
            for (int i = 0; i < regions.Count; i++)
            {
                float val = 1 / (1 + dist[i]);
                val = val > 0.92f ? val : 0;
                regions[i].Fill(new Vector3(val, val, val), result);
            }

            //regions[minIndex].Fill(new Vector3(1, 1, 1), result);

            return(result);
        }
Esempio n. 11
0
    private Transform[] GenerateBones(Vector3[,] vertices)
    {
        Transform[] bones        = new Transform[vertices.GetLength(1)];
        Vector3     bonePosition = new Vector3();

        for (int j = 0; j < vertices.GetLength(1); j++)
        {
            bonePosition.Set(0, 0, 0);
            for (int i = 0; i < vertices.GetLength(0); i++)
            {
                bonePosition += vertices[i, j];
            }

            bonePosition /= vertices.GetLength(0);


            bones[j]        = new GameObject("Bone" + j).transform;
            bones[j].parent = transform;

            bones[j].localRotation = Quaternion.identity;
            bones[j].localPosition = bonePosition;

            bones[j].gameObject.layer = LayerMask.NameToLayer("MassSpring");
        }


        return(bones);
    }
Esempio n. 12
0
    public Mesh MakeMesh()
    {
        var m         = new Mesh();
        var verts     = new List <Vector3>();
        var triangles = new List <int>();

        for (int y = 0; y < pointsReal.GetLength(1) - 1; y++)
        {
            for (int x = 0; x < pointsReal.GetLength(0) - 1; x++)
            {
                verts.Add(pointsReal[x, y]);
                verts.Add(pointsReal[x, y + 1]);
                verts.Add(pointsReal[x + 1, y + 1]);
                verts.Add(pointsReal[x + 1, y]);

                triangles.Add(x * 4);
                triangles.Add(x * 4 + 1);
                triangles.Add(x * 4 + 2);

                triangles.Add(x * 4 + 0);
                triangles.Add(x * 4 + 2);
                triangles.Add(x * 4 + 3);
            }
        }


        m.SetVertices(verts);
        m.SetTriangles(triangles.ToArray(), 0);

        m.RecalculateTangents();
        m.RecalculateNormals();


        return(m);
    }
Esempio n. 13
0
    public Vector3[] CameraPointsToAudioLocations(Vector3[,] depthMap, int resolution)
    {
        int yOSize = depthMap.GetLength(0);
        int xOSize = depthMap.GetLength(1);

        int ySize = (int)Math.Ceiling((double)yOSize / resolution);
        int xSize = (int)Math.Ceiling((double)xOSize / resolution);

        int[]     maxes       = new int[resolution * resolution];
        Vector3[] maxIndicies = new Vector3[maxes.Length];
        for (int i = 0; i < maxes.Length; i++)
        {
            maxes[i] = 100000;
        }
        for (int i = 0; i < yOSize; i++)
        {
            for (int j = 0; j < xOSize; j++)
            {
                int     tempCell = i / ySize * resolution + j / xSize;
                Vector3 pt       = depthMap[i, j];
                int     dist     = (int)Math.Sqrt(pt.x * pt.x + pt.y * pt.y + pt.z * pt.z);
                // Debug.Log(pt);
                if (dist >= 0 && dist < maxes[tempCell])
                {
                    maxes[tempCell]       = dist;
                    maxIndicies[tempCell] = new Vector3(pt.x, pt.y, pt.z);
                }
            }
        }

        return(maxIndicies);
    }
Esempio n. 14
0
    public static MeshData generateMesh(Vector3[,] heightMap)
    {
        int   width    = heightMap.GetLength(0);
        int   height   = heightMap.GetLength(1);
        float topLeftX = (width - 1) / -2f;
        float topLeftZ = (height - 1) / 2f;

        MeshData meshData    = new MeshData(width, height);
        int      vertexIndex = 0;

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                meshData.vertices [vertexIndex] = new Vector3(topLeftX + heightMap[x, y].x, heightMap[x, y].y, topLeftZ - heightMap[x, y].z);
                meshData.uvs [vertexIndex]      = new Vector2(x / (float)width, y / (float)height);

                if (x < width - 1 && y < height - 1)
                {
                    meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
                    meshData.AddTriangle(vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
                }

                vertexIndex++;
            }
        }

        return(meshData);
    }
Esempio n. 15
0
    public static MeshData GenerateMeshData(Vector3[,] verticesMatrix, Vector2[,] uvs, Color color, NeighBoursDirection direction)
    {
        int      width    = verticesMatrix.GetLength(0);
        int      height   = verticesMatrix.GetLength(1);
        MeshData meshData = new MeshData(width, height);

        int vertexIndex = 0;

        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                meshData.Vertices[vertexIndex] = verticesMatrix[x, y];
                meshData.UVS[vertexIndex]      = uvs[x, y];
                meshData.Colors[vertexIndex]   = color;

                if (x < width - 1 && y < height - 1)
                {
                    if (direction == NeighBoursDirection.BOTTOM || direction == NeighBoursDirection.LEFT)
                    {
                        meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
                        meshData.AddTriangle(vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
                    }
                    else
                    {
                        meshData.AddTriangle(vertexIndex, vertexIndex + width, vertexIndex + width + 1);
                        meshData.AddTriangle(vertexIndex + width + 1, vertexIndex + 1, vertexIndex);
                    }
                }
                vertexIndex++;
            }
        }
        return(meshData);
    }
Esempio n. 16
0
    // ienumeradores privados
    private IEnumerator CalculateCellPositions()
    {
        // precorre a lista de celulas e atribui a posiçao para cada uma delas
        // segundo a coluna
        for (int x = 0; x < projecter_cell_position.GetLength(0); x++)
        {
            // segundo a linha
            for (int y = 0; y < projecter_cell_position.GetLength(1); y++)
            {
                // define a posiçao da celula
                // posiçao local
                projecter_cell_position[x, y] = new Vector3((-projecter_area_.x * 0.5f) + projecter_cell_size_ * 0.5f + projecter_cell_size_ * x,
                                                            (-projecter_area_.y * 0.5f) + projecter_cell_size_ * 0.5f + projecter_cell_size_ * y, -0.5f * projecter_area_.z);

                // calcula a posiçao no mundo relativa ao objecto
                projecter_cell_position[x, y] = this.transform.TransformPoint(projecter_cell_position[x, y]);
            }
            // aguarda o proximo frame
            yield return(null);
        }
        //degub
        Debug.Log($"{projecter_cell_position.Length} Calculated positions");

        // ao terminar de calcular as posiçoes para cada uma das celulas
        // activa os elementos projectores
        foreach (ProjectedSystem projected_system in project_to_)
        {
            // inicia estas areas
            projected_system.ActivateProjectedArea(this, projecter_cell_position.GetLength(0), projecter_cell_position.GetLength(1));
        }

        // inicia a projecçao
        StartCoroutine(ProjectionActivity());
    }
Esempio n. 17
0
 public void PokazPozycje()
 {
     for (int i = 0; i < positions.GetLength(0); i++)
     {
         for (int j = 0; j < positions.GetLength(1); j++)
         {
             bool ignore = false;
             for (int k = 0; k < toIgnore.GetLength(0); k++)
             {
                 if (i == toIgnore[k, 0] && j == toIgnore[k, 1])
                 {
                     ignore = true;
                     break;
                 }
             }
             if (!ignore)
             {
                 GameObject z = Instantiate(pointOnBoard, positions[i, j], Quaternion.FromToRotation(Vector3.forward, transform.up)) as GameObject;
                 z.transform.parent = this.transform;
                 z.GetComponent <PointOnBoardScript>().gridI = i;
                 z.GetComponent <PointOnBoardScript>().gridJ = j;
                 points[i, j] = z.GetComponent <PointOnBoardScript>();
             }
         }
     }
 }
Esempio n. 18
0
    //Awake()で走っていたスクリプト
    public void FirstMethod()
    {
        //スタート位置を生成
        railPos = cellPoint[UnityEngine.Random.Range(cellPoint.GetLength(0) - 1, 0), UnityEngine.Random.Range(0, cellPoint.GetLength(1) - 1)];
        mapData.Add(railPos);
        param = mapData[mapData.Count - 1];

        //cellPointのIndexを取得するためのリストに値を入れる
        for (int i = 0; i <= cellPoint.GetLength(0) - 1; i++)
        {
            for (int j = 0; j <= cellPoint.GetLength(1) - 1; j++)
            {
                xIndex.Add(i);
                zIndex.Add(j);
            }
        }

        //mapDataにデータを格納
        for (int i = 1; i <= maxRail - 1; i++)
        {
            railPos = RandomMaker(zIndex, xIndex);
            mapData.Add(railPos);
            param = mapData[mapData.Count - 2];
        }
    }
Esempio n. 19
0
    private void Start()
    {
        tiles = new Tile[xLength * space.GetLength(1)];
        float xOffset = xLength / 2f - 0.5f;
        float yOffset = space.GetLength(1) / 2f - 0.5f;

        levelIndex = Random.Range(0, Levels.templates.Length);

        for (int y = 0; y < space.GetLength(1); y++)
        {
            for (int x = 0; x < xLength; x++)
            {
                var index = x + (y * xLength);
                if (Levels.templates[levelIndex][index] == 1)
                {
                    var pos  = new Vector3(x - xOffset, y - yOffset, 0);
                    var temp = Instantiate(bg_prefab, pos, Quaternion.identity);
                    temp.transform.parent = transform;
                    var typeIndex = Random.Range(0, tile_prefabs.Length);
                    var tile      = Instantiate(tile_prefabs[typeIndex], pos, Quaternion.identity);
                    tile.transform.parent = transform;
                    var tileComponent = tile.AddComponent <Tile>();
                    tileComponent.indexX    = x;
                    tileComponent.indexY    = y;
                    tileComponent.typeIndex = typeIndex;
                    tiles[index]            = tileComponent;
                }
            }
        }
    }
Esempio n. 20
0
        public Vector3[,] BestInAvr(Vector3[,] map, Vector3 color)
        {
            int width  = map.GetLength(0);
            int height = map.GetLength(1);

            Vector3[,] result = new Vector3[width, height];

            List <float> dist = new List <float>();

            for (int i = 0; i < regions.Count; i++)
            {
                Vector3 avr = regions[i].GetAverage(map);
                dist.Add((avr - color).Magnitude());
            }

            int minIndex = 0;

            for (int i = 0; i < regions.Count; i++)
            {
                regions[i].Fill(new Vector3(), result);
                if (dist[minIndex] > dist[i])
                {
                    minIndex = i;
                }
            }

            regions[minIndex].Fill(new Vector3(1, 1, 1), result);

            return(result);
        }
Esempio n. 21
0
 // Use this for initialization
 void Awake()
 {
     audioManager = FindObjectOfType <AudioManager>();
     enemyObjects = new GameObject[enemyPosArray.GetLength(1)];
     for (int i = 0; i < enemyPosArray.GetLength(1); i++)
     {
         enemyObjects[i] = Instantiate(enemyPrefab, Vector3.down * 2, Quaternion.identity);
     }
 }
Esempio n. 22
0
    public void SetIfUserCanInput(bool isUserCanInput, Vector3[,] cellsPositions)
    {
        _isInputUserActive = isUserCanInput;
        _cellsPosition     = cellsPositions;

        _currentPositionI = _cellsPosition.GetLength(0) / 2;
        _currentPositionJ = _cellsPosition.GetLength(1) / 2;
        RefreshPositionOfPlayer();
    }
Esempio n. 23
0
 public Vector3[] getPos(int body)
 {
     Vector3[] temp = new Vector3[positions.GetLength(1)];
     for (int i = 0; i < positions.GetLength(1); i++)
     {
         temp[i] = positions[body - 1, i];
     }
     return(temp);
 }
Esempio n. 24
0
    //----------------------


    //-----------------------
    Vector3[] GetLineToPass(Vector3[,] bMatrix, int reflIndex)
    {
        Vector3[] lineContainer = new Vector3[bMatrix.GetLength(1)];
        for (int points = 0; points < bMatrix.GetLength(1); points++)
        {
            lineContainer[points] = bMatrix[reflIndex, points];
        }
        return(lineContainer);
    }
Esempio n. 25
0
 /// <summary>
 /// Removes No Data values by filling in from average of surrounding pixels
 /// </summary>
 /// <param name="ret"></param>
 void RemoveNaNs(Vector3[,] ret, List <XY> nanIndices)
 {
     int[] valid = new int[nanIndices.Count];
     for (int i = 0; i < nanIndices.Count; i++)
     {
         XY  xy = nanIndices[i];
         int s  = 0;
         if ((xy.x > 0) && (ret[xy.y, xy.x - 1].Z != NoData))
         {
             s++;
         }
         if ((xy.x < ret.GetLength(1) - 1) && (ret[xy.y, xy.x + 1].Z != NoData))
         {
             s++;
         }
         if ((xy.y > 0) && (ret[xy.y - 1, xy.x].Z != NoData))
         {
             s++;
         }
         if ((xy.y < ret.GetLength(0) - 1) && (ret[xy.y + 1, xy.x].Z != NoData))
         {
             s++;
         }
         valid[i] = s;
     }
     for (int i = 0; i < nanIndices.Count; i++)
     {
         if (valid[i] == 0)
         {
             continue;
         }
         XY     xy  = nanIndices[i];
         double sum = 0;
         int    s   = 0;
         if ((xy.x > 0) && ret[xy.y, xy.x - 1].Z != NoData)
         {
             sum += ret[xy.y, xy.x - 1].Z;
             s++;
         }
         if ((xy.x < ret.GetLength(1) - 1) && ret[xy.y, xy.x + 1].Z != NoData)
         {
             sum += ret[xy.y, xy.x + 1].Z;
             s++;
         }
         if ((xy.y > 0) && ret[xy.y - 1, xy.x].Z != NoData)
         {
             sum += ret[xy.y - 1, xy.x].Z;
             s++;
         }
         if ((xy.y < ret.GetLength(0) - 1) && ret[xy.y + 1, xy.x].Z != NoData)
         {
             sum += ret[xy.y + 1, xy.x].Z;
             s++;
         }
         ret[xy.y, xy.x].Z = (float)(sum / s);
     }
 }
Esempio n. 26
0
 ///<summary>
 /// Renvoie un iterateur sur l'array 2D qui va d'abord dans le sens oblique puis dans le sens tangent
 ///</summary>
 public IEnumerable <Vector3> Flatten(Vector3[,] arr2D)
 {
     for (int i = 0; i < arr2D.GetLength(0); i++)
     {
         for (int j = 0; j < arr2D.GetLength(1); j++)
         {
             yield return(arr2D[i, j]);
         }
     }
 }
Esempio n. 27
0
 void CalculatePoints()
 {
     for (int i = 0; i < points.GetLength(0); i++)
     {
         for (int j = 0; j < points.GetLength(1); j++)
         {
             pointsReal[i, j] = Vector3.Lerp(points[i, j], pointsSphere[i, j], Lerp);
         }
     }
 }
Esempio n. 28
0
 // Generate ofc
 public void Generate()
 {
     for (int i = 0; i < blocks.GetLength(0); i++)
     {
         for (int j = 0; j < blocks.GetLength(1); j++)
         {
             blocks[i, j] = GenerateBlock(i, j, seed);
         }
     }
 }
Esempio n. 29
0
    private IEnumerator SpawnTreesAsync(Vector3[,] globalVertexPositions)
    {
        var operations = 0;

        for (var zInd = 0; zInd < globalVertexPositions.GetLength(0) / tiling; zInd++)
        {
            for (var xInd = 0; xInd < globalVertexPositions.GetLength(1) / tiling; xInd++)
            {
                var heightSum = 0f;
                for (var zStart = zInd * tiling; zStart < (zInd + 1) * tiling; zStart++)
                {
                    for (var xStart = xInd * tiling; xStart < (xInd + 1) * tiling; xStart++)
                    {
                        heightSum += globalVertexPositions[zStart, xStart].y;
                    }
                }
                heightSum /= tiling * tiling;

                /*
                 * if(heightSum <= treeMaxBound && heightSum >= treeMinBound)
                 * {
                 *  Instantiate(treePrefab,
                 *      globalVertexPositions[zInd * tiling + tiling / 2, xInd * tiling + tiling / 2],
                 *      Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
                 * }
                 */
                for (var i = 0; i < spawnableObjects.Length; i++)
                {
                    var so = spawnableObjects[i];
                    if (so.maxBound > heightSum)
                    {
                        if (Random.Range(0f, 1f) <= so.probability &&
                            so.vars.Length > 0)
                        {
                            Instantiate(so.vars[Random.Range(0, so.vars.Length)],
                                        globalVertexPositions[zInd * tiling + tiling / 2, xInd * tiling + tiling / 2],
                                        Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
                        }
                        break;
                    }
                }
                if (operations >= asyncOperations)
                {
                    operations = 0;
                    yield return(null);
                }
            }
        }

        // //placing the stars
        //starsTf.position = transform.position + new Vector3(levelSize.x * mapWidth / 2, 0f, levelSize.y * mapDepth / 2);

        Debug.LogWarning("Trees gened async!");
        yield break;
    }
Esempio n. 30
0
 public Vector3 VectorFromPosition(int x, int y)
 {
     try
     {
         return(centers[y, x]);
     }
     catch (System.Exception error)
     {
         return(centers[centers.GetLength(0) - 1, centers.GetLength(1) - 1]);
     }
 }
	private void setParticleStartLocations(){
		endLocations = new Vector3[widthOfParticals, widthOfParticals];
		Vector3 particelStartLocation = gridBlockMovingTo.transform.position;
		//particelStartLocation = new Vector3(particelStartLocation.x, 0.01f, particelStartLocation.y);
		int x, y;
		for(x = 0; x < widthOfParticals; x++){
			for(y = 0; y < widthOfParticals; y++){
				endLocations[x, y] = particelStartLocation;
				float posX, posY;
				posX = x * offsetAmount;
				posX -= ((widthOfParticals - 1f) * offsetAmount) / 2f;
				posY = y * offsetAmount;
				posY -= ((widthOfParticals - 1f) * offsetAmount) / 2f;

				endLocations[x, y] += new Vector3(posX, 0, posY);
			}
		}

		#region semi randomize end locations 
		int n = endLocations.GetLength(0);
		Vector3[,] temp = new Vector3[n, n];
		Vector3 endTemp;
		x = 0;
		y = 0;
		int x1, y1;
	
		if(directionMoving == Direction.UP){
			for(int i = 0; i < endLocations.Length * 3; i++){
				x = Random.Range(0, widthOfParticals);
				y = Random.Range(0, widthOfParticals);
				x1 = Random.Range(0, widthOfParticals);

				endTemp = endLocations[x, y]; // swap 2 x values in a single y column
				endLocations[x, y] = endLocations[x1, y];
				endLocations[x1, y] = endTemp;
			}
		} else if(directionMoving == Direction.RIGHT){
			for(int i = 0; i < n; ++i){
				for(int j = 0; j < n; ++j){
					temp[i, j] = endLocations[j, i];
				}
			}
			endLocations = temp;
			for(int i = 0; i < endLocations.Length * 3; i++){
				x = Random.Range(0, widthOfParticals);
				y = Random.Range(0, widthOfParticals);
				x1 = Random.Range(0, widthOfParticals);

				endTemp = endLocations[x, y]; // swap 2 y values in a single x column
				endLocations[x, y] = endLocations[x1, y];
				endLocations[x1, y] = endTemp;
			}
		} else if(directionMoving == Direction.LEFT){
			for(int i = 0; i < n; ++i){
				for(int j = 0; j < n; ++j){
					temp[i, j] = endLocations[n - j - 1, i];
				}
			}
			endLocations = temp;
			for(int i = 0; i < endLocations.Length * 3; i++){
				x = Random.Range(0, widthOfParticals);
				y = Random.Range(0, widthOfParticals);
				x1 = Random.Range(0, widthOfParticals);

				endTemp = endLocations[x, y]; // swap 2 y values in a single x column
				endLocations[x, y] = endLocations[x1, y];
				endLocations[x1, y] = endTemp;
			}
		} else if(directionMoving == Direction.DOWN){
			for(int i = 0; i < n; ++i){
				for(int j = 0; j < n; ++j){
					temp[i, j] = endLocations[i, n - j - 1];
				}
			}
			endLocations = temp;
			for(int i = 0; i < endLocations.Length * 3; i++){
				x = Random.Range(0, widthOfParticals);
				y = Random.Range(0, widthOfParticals);
				x1 = Random.Range(0, widthOfParticals);

				endTemp = endLocations[x, y]; // swap 2 x values in a single y column
				endLocations[x, y] = endLocations[x1, y];
				endLocations[x1, y] = endTemp;
			}
		}
		#endregion
	}