示例#1
0
        public City(Device device, DeviceContext context)
        {
            this.deviceContext = context;

            var windowSize  = new Size2(8, 8);
            var textureSize = new Size2(512, 512);

            var buildingTexture = new BuildingTexture(device, context, textureSize, windowSize);

            var texture = Texture.FromTexture2D(buildingTexture.Texture, device);

            this.pixelShader  = new PixelTextureLightShader(device, texture);
            this.vertexShader = new VertexPosNormalTextureModShader(device);

            this.random = new Random();

            var cityPlanner = new CityPlanner();
            var boxes       = cityPlanner.BuildCity();

            var geometryBatcher = new GeometryBatcher(boxes, 3000);

            var vertexSize = (Utilities.SizeOf <Vector3>() * 3) + Utilities.SizeOf <Vector2>();

            this.batchedRenderer = new BatchedGeometryRenderer(geometryBatcher, device, vertexSize, this.vertexShader.Layout);
        }
示例#2
0
        public static CityPlanner SetColorRangeClass(this CityPlanner cityPlanner)
        {
            cityPlanner.trip.temp_high.avg.CSSName = Convert.ToInt32(cityPlanner.trip.temp_high.avg.C).GetTempCssName();
            //cityPlanner.trip.temp_high.max.CSSName = Convert.ToInt32(cityPlanner.trip.temp_high.max.C).GetTempCSSName();
            //cityPlanner.trip.temp_high.min.CSSName = Convert.ToInt32(cityPlanner.trip.temp_high.min.C).GetTempCSSName();

            cityPlanner.trip.temp_low.avg.CSSName = Convert.ToInt32(cityPlanner.trip.temp_low.avg.C).GetTempCssName();
            //cityPlanner.trip.temp_low.max.CSSName = Convert.ToInt32(cityPlanner.trip.temp_low.max.C).GetTempCSSName();
            //cityPlanner.trip.temp_low.min.CSSName = Convert.ToInt32(cityPlanner.trip.temp_low.min.C).GetTempCSSName();

            cityPlanner.trip.precip.avg.CSSName        = "t04";
            cityPlanner.trip.dewpoint_high.avg.CSSName = Convert.ToInt32(cityPlanner.trip.dewpoint_high.avg.C).GetTempCssName();
            cityPlanner.trip.dewpoint_low.avg.CSSName  = Convert.ToInt32(cityPlanner.trip.dewpoint_low.avg.C).GetTempCssName();
            return(cityPlanner);
        }
    public void Decorate()
    {
        Vector3        lhs                 = Vector3.zero;
        bool           notInit             = true;
        List <float>   houseBaseWidths     = new List <float>();
        List <Vector3> plantBaseDirections = new List <Vector3>();

        int nHouses = 0;
        int nPlants = 0;
        int i       = -1;

        foreach (Vector3 rhs in _stitcher.groundSurface())
        {
            i++;
            if (notInit || _stitcher.groundInvalidSegment || lhs.x >= rhs.x)
            {
                lhs = rhs;
                if (notInit)
                {
                    notInit = false;
                }
                continue;
            }

            if (_stitcher.groundSurfaceType == GroundMaker.TerrainType.Ordered &&
                (rhs.x - lhs.x) > CityPlanner.instance.houseWidthMin &&
                Random.value < houseProbability)
            {
                //Produce a house
                if (nHouses < houses.Count)
                {
                    CityPlanner.PrepareFoundation(houses[nHouses], lhs, _stitcher.groundSurfaceTransform);
                }
                else
                {
                    houses.Add(CityPlanner.PrepareFoundation(lhs, _stitcher.groundSurfaceTransform));
                }
                nHouses++;
                houseBaseWidths.Add(rhs.x - lhs.x);
            }
            else if (_stitcher.groundSurfaceType != GroundMaker.TerrainType.Ordered &&
                     Mathf.Abs(Vector3.Dot((rhs - lhs).normalized, Vector3.up)) < plantBaseMaxSlope &&
                     Random.value < plantProbability)
            {
                //Produce a plant/shrub/tree
                if (nPlants < plants.Count)
                {
                    Gardener.Seed(plants[nPlants], lhs, _stitcher.groundSurfaceTransform);
                }
                else
                {
                    plants.Add(Gardener.Seed(lhs, _stitcher.groundSurfaceTransform));
                }
                nPlants++;
                plantBaseDirections.Add(rhs - lhs);
            }
            lhs = rhs;
        }

        while (houses.Count > nHouses)
        {
            House h = houses[houses.Count - 1];
            houses.Remove(h);
            Destroy(h.gameObject);
        }

        while (plants.Count > nPlants)
        {
            Plant p = plants[plants.Count - 1];
            plants.RemoveAt(plants.Count - 1);
            Destroy(p.gameObject);
        }

        CityPlanner.Architect(houses, houseBaseWidths);
        Gardener.Germinate(plants, plantBaseDirections);
    }