// Returns the number of instances _actually_ created
        public int AddPlantInstances(Boundary boundary, Vector2 tileLocation, int pageSize, Random rand)
        {
            float scaleWidthRange  = scaleWidthHi - scaleWidthLow;
            float scaleHeightRange = scaleHeightHi - scaleHeightLow;
            float colorRange       = colorMultHi - colorMultLow;

            instances = new List <PlantInstance>();
            for (int i = 0; i < numInstances; i++)
            {
                // Generate random locations within the block. =
                Vector2 coordsInTile = new Vector2((float)rand.NextDouble(), (float)rand.NextDouble()) *
                                       pageSize * TerrainManager.oneMeter;;
                Vector2 worldCoords = coordsInTile + tileLocation;
                if (boundary.PointIn(new Vector3(worldCoords.x, 0, worldCoords.y)))
                {
                    float   colorScale = (((float)rand.NextDouble() * colorRange) + colorMultLow);
                    ColorEx tmpColor   = new ColorEx(color.r * colorScale, color.g * colorScale, color.b * colorScale);
                    instances.Add(new PlantInstance(coordsInTile,
                                                    (float)rand.NextDouble() * scaleWidthRange + scaleWidthLow,
                                                    (float)rand.NextDouble() * scaleHeightRange + scaleHeightLow,
                                                    tmpColor, windMagnitude));
                }
            }
            return(instances.Count);
        }
Example #2
0
        /// <summary>
        /// Select a random location within the boundary area for a tree.  First we pick a random spot
        /// within the 2D rectangular bounds of the boundary, and then perform an intersection test of
        /// the point against the actual boundary shape.  If the selected point is not in the boundary
        /// area, then we pick another random number and try again.
        /// </summary>
        /// <returns></returns>
        private Vector3 RandomLocation()
        {
            float   x;
            float   z;
            Vector3 v;

            do
            {
                x = ((float)rand.NextDouble()) * sizeX + offX;
                z = ((float)rand.NextDouble()) * sizeZ + offZ;

                v = new Vector3(x, 0, z);
            } while (!boundary.PointIn(v));

            return(new Vector3(x, TerrainManager.Instance.GetTerrainHeight(v, GetHeightMode.Interpolate, GetHeightLOD.MaxLOD), z));
        }