Ejemplo n.º 1
0
 public void LoadContent(ContentManager cm, Ground land, Camera cam)
 {
     fx = cm.Load<Effect>("bbEffect");
     treeTexture = cm.Load<Texture2D>("tree");
     treeMap = cm.Load<Texture2D>("treeMap");
     Locations = new List<Vector3>();
     GenerateTreePositions(land);
     List2Buffer(cam.device);
 }
Ejemplo n.º 2
0
        private void GenerateTreePositions(Ground land)
        {
            Color[] treeMapColors = new Color[treeMap.Width * treeMap.Height];
            treeMap.GetData(treeMapColors);

            int[,] noiseData = new int[treeMap.Width, treeMap.Height];
            for (int x = 0; x < treeMap.Width; x++)
                for (int y = 0; y < treeMap.Height; y++)
                    noiseData[x, y] = treeMapColors[y + x * treeMap.Height].R;

            Random random = new Random();
            float steep = (float)Math.Cos(MathHelper.ToRadians(15));

            for (int x = 0; x < land.Width; x++)
            {
                for (int y = 0; y < land.Length; y++)
                {
                    float alt = land.Height(x, y);
                    if ((alt < 8) || (alt > 14)) continue;

                    float level = Vector3.Dot(land.Vertices[x + y * land.Width].Normal, Vector3.Up);
                    if (level < steep) continue;

                    float relx = (float)x / (float)land.Width;
                    float rely = (float)y / (float)land.Length;

                    float noise = noiseData[(int)(relx * treeMap.Width), (int)(rely * treeMap.Height)];
                    float treeDensity;
                    if (noise > 200)
                        treeDensity = 5;
                    else if (noise > 150)
                        treeDensity = 4;
                    else if (noise > 100)
                        treeDensity = 3;
                    else
                        treeDensity = 0;

                    for (int currDetail = 0; currDetail < treeDensity; currDetail++)
                    {
                        float rand1 = (float)random.Next(1000) / 1000.0f;
                        float rand2 = (float)random.Next(1000) / 1000.0f;
                        Vector3 treePos = new Vector3((float)x - rand1, alt, -(float)y - rand2);
                        Locations.Add(treePos);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 protected override void Initialize()
 {
     Window.Title = "3D Project";
     //IsMouseVisible = true;
     graphics.PreferredBackBufferWidth = 1280;
     graphics.PreferredBackBufferHeight = 1024;
     graphics.ApplyChanges();
     land = new Ground("x6");
     camera = new Camera();
     dome = new Sky();
     trees = new Forest();
     this.Components.Add(new FrameRateCounter(this));
     this.Components.Add(new ShowFPS(this));
     base.Initialize();
 }