Ejemplo n.º 1
0
 public ReimersBillboards(
     VisionContent vContent,
     Matrix world,
     GroundMap groundMap,
     ColorSurface normals,
     Texture2D texture)
     : base(vContent, world, texture, generateTreePositions(vContent.Load<Texture2D>("treeMap"), groundMap, normals), 6, 7)
 {
 }
Ejemplo n.º 2
0
 private static void PopulateSurface(ColorSurface surface, WriteableBitmapWrapper writeableBitmap)
 {
     for (int y = 0; y < surface.Height; ++y)
         for (int x = 0; x < surface.Width; ++x)
         {
             var c = writeableBitmap.GetPixel(x, y);
             surface[x, y, 0] = (ColorF) c;
         }
 }
Ejemplo n.º 3
0
        public static ColorSurface LoadFromFile(string uri)
        {
            BitmapImage bitmapImage = new BitmapImage(new Uri(uri));
            WriteableBitmapWrapper writeableBitmap = new WriteableBitmapWrapper(new WriteableBitmap(bitmapImage));

            ColorSurface surface = new ColorSurface(writeableBitmap.Width, writeableBitmap.Height, 1);
            PopulateSurface(surface, writeableBitmap);
            return surface;
        }
Ejemplo n.º 4
0
 public void GenerateTreePositions(GroundMap groundMap, ColorSurface normals)
 {
     var treeList = generateTreePositions(groundMap, normals);
     CreateBillboardVerticesFromList(treeList);
 }
Ejemplo n.º 5
0
        private List<Tuple<Vector3, Vector3>> generateTreePositions(GroundMap groundMap, ColorSurface normals)
        {
            var treeList = new List<Tuple<Vector3,Vector3>>();
            var random = new Random();

            for (var y = normals.Height - 2; y > 0; y--)
                for (var x = normals.Width - 2; x > 0; x--)
                {
                    var height = groundMap[x, y];
                    if ( height <3 || height > 5)
                        continue;
                    for (var currDetail = 0; currDetail < 5; currDetail++)
                    {
                        var rand1 = (float) random.NextDouble();
                        var rand2 = (float) random.NextDouble();
                        treeList.Add(new Tuple<Vector3, Vector3>(
                                         new Vector3(
                                             x + rand1,
                                             groundMap.GetExactHeight(x, y, rand1, rand2),
                                             y + rand2),
                                         normals.AsVector3(x, y)));
                    }
                }

            return treeList;
        }
Ejemplo n.º 6
0
 public void GenerateTreePositions(GroundMap groundMap, ColorSurface normals)
 {
     generateTreePositions(groundMap, normals);
     CreateVertices();
 }
Ejemplo n.º 7
0
        protected void initialize(GroundMap groundMap, WeightsMap weights, ColorSurface normals)
        {
            GroundMap = groundMap;

            Debug.Assert((groundMap.Width%TerrainPlane.SquareSize) == 0 && (groundMap.Height%TerrainPlane.SquareSize) == 0);

            _position = World.TranslationVector;

            Textures[0] = Textures[0] ?? VContent.Load<Texture2D>("terraintextures/sand");
            Textures[1] = Textures[1] ?? VContent.Load<Texture2D>("terraintextures/sahara");
            Textures[2] = Textures[2] ?? VContent.Load<Texture2D>("terraintextures/grass");
            Textures[3] = Textures[3] ?? VContent.Load<Texture2D>("terraintextures/rock");
            Textures[4] = Textures[4] ?? VContent.Load<Texture2D>("terraintextures/snow");
            Textures[5] = Textures[5] ?? VContent.Load<Texture2D>("terraintextures/stones");
            Textures[6] = Textures[6] ?? VContent.Load<Texture2D>("terraintextures/dirtground");
            Textures[7] = Textures[7] ?? VContent.Load<Texture2D>("terraintextures/path");
            Textures[8] = Textures[8] ?? VContent.Load<Texture2D>("terraintextures/wheatfield");

            HeightsMap = groundMap.CreateHeightsTexture(Effect.GraphicsDevice);
            WeightsMap = weights.CreateTexture2D(Effect.GraphicsDevice);
            NormalsMap = normals.CreateTexture2D(Effect.GraphicsDevice);

            var slicesW = groundMap.Width/Side;
            var slicesH = groundMap.Height/Side;
            //TODO - this is wrong - I guess...
            var sliceFracX = 1f/slicesW;
            var sliceFracY = 1f/slicesH;
            _slices = new TerrainSlice[slicesW*slicesH];

            var gurka = Vector3.TransformNormal(new Vector3(HalfSide, 0, HalfSide), World);
            var radius = Math.Max(gurka.X, gurka.Z) * (float)Math.Sqrt(2);

            var i = 0;
            for (var y = 0; y < slicesH; y++)
                for (var x = 0; x < slicesW; x++)
                {
                    var world = Matrix.Translation(Side*x, 0, Side*y)*World;
                    _slices[i++] = new TerrainSlice
                    {
                        TexOffsetAndScale = new Vector4(x*sliceFracX, y*sliceFracY, sliceFracX, sliceFracY),
                        World = world,
                        BoundingSphere = new BoundingSphere(world.TranslationVector + gurka, radius)
                    };
                }
            BoundingSphere = new BoundingSphere(
                _position + new Vector3(groundMap.Width, 0, groundMap.Height)/2,
                (float) Math.Sqrt(groundMap.Width*groundMap.Width + groundMap.Height*groundMap.Height)/2);

            GroundExtentX = slicesW;
            GroundExtentZ = slicesH;
        }
Ejemplo n.º 8
0
 public static void PopulateFromStream(ColorSurface surface, Stream stream)
 {
     BitmapFrame bitmapImage = BitmapFrame.Create(stream);
     PopulateSurface(surface, new WriteableBitmapWrapper(new WriteableBitmap(bitmapImage)));
 }
Ejemplo n.º 9
0
        private Material CreateMaterial(ModelMaterial modelmtrl)
        {
            var shininess   = modelmtrl.Params.OfType<ParamF>  ().FirstOrDefault(i => i.Name == "_Shininess");
            var maintex     = modelmtrl.Params.OfType<ParamTex>().FirstOrDefault(i => i.Name == "_MainTex");
            var color       = modelmtrl.Params.OfType<ParamCol>().FirstOrDefault(i => i.Name == "_Color");
            var mtrl        = new Material();
            var id          = modelmtrl.Descriptions[0];
            var name        = modelmtrl.Descriptions[0];
            mtrl.ID         = "Material-"+id;
            mtrl.Name       = "Material-"+name;
            mtrl.Shader     = ShaderType.Phong;
            mtrl.Shininess   = null == shininess ? 1 : shininess.Value;
            mtrl.Transparency= 1;

            if(null != maintex)
            {
                var surf    = new TextureSurface("Surface-"+id+"-Diff", name+"-Diff");
                surf.Texture= CreateBitmapTexture(maintex);
                surf.TexCoord   = 1;

                mtrl.AddSurface(SurfaceSlot.Diffuse, surf);
            } else
            if(null != color)
            {
                var surf    = new ColorSurface("Surface-"+id+"-Diff", name+"-Diff");
                surf.Color3 = new SlimDX.Color3(color.R, color.G, color.B);

                mtrl.AddSurface(SurfaceSlot.Diffuse, surf);
            } else
            {
                var surf    = new ColorSurface("Surface-"+id+"-Diff", name+"-Diff");
                surf.Color3 = new SlimDX.Color3(1, 1, 1);

                mtrl.AddSurface(SurfaceSlot.Diffuse, surf);
            }

            mtrl.AddSurface(SurfaceSlot.Ambient,     new SlimDX.Color4(1.0f, 0.5f, 0.5f, 0.5f));
            mtrl.AddSurface(SurfaceSlot.Specular,    new SlimDX.Color4(1.0f, 0.0f, 0.0f, 0.0f));
            mtrl.AddSurface(SurfaceSlot.Reflective,  new SlimDX.Color4(1.0f, 0.0f, 0.0f, 0.0f));
            mtrl.AddSurface(SurfaceSlot.Transparent, new SlimDX.Color4(1.0f, 1.0f, 1.0f, 1.0f));

            Materials.Add(mtrl.ID, mtrl);
            Root.Instances.Add(mtrl);

            return mtrl;
        }
Ejemplo n.º 10
-1
        private static List<Vector3> generateTreePositions(Texture2D treeMap, GroundMap groundMap, ColorSurface normals)
        {
            var treeMapColors = new Color[treeMap.Description.Width*treeMap.Description.Height];
            treeMap. GetData(treeMapColors);

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

            var treeList = new List<Vector3>();
            var random = new Random();

            var minFlatness = (float) Math.Cos(MathUtil.DegreesToRadians(15));
            for (var y = normals.Height - 2; y > 0; y--)
                for (var x = normals.Width - 2; x > 0; x--)
                {
                    var terrainHeight = groundMap[x, y];
                    if ((terrainHeight <= 8) || (terrainHeight >= 14))
                        continue;
                    var flatness1 = Vector3.Dot(normals.AsVector3(x, y), Vector3.Up);
                    var flatness2 = Vector3.Dot(normals.AsVector3(x + 1, y + 1), Vector3.Up);
                    if (flatness1 <= minFlatness || flatness2 <= minFlatness)
                        continue;
                    var relx = (float) x/normals.Width;
                    var rely = (float) y/normals.Height;

                    float noiseValueAtCurrentPosition = noiseData[(int) (relx*sz.Width), (int) (rely*sz.Height)];
                    float treeDensity;
                    if (noiseValueAtCurrentPosition > 200)
                        treeDensity = 3;
                    else if (noiseValueAtCurrentPosition > 150)
                        treeDensity = 2;
                    else if (noiseValueAtCurrentPosition > 100)
                        treeDensity = 1;
                    else
                        treeDensity = 0;

                    for (var currDetail = 0; currDetail < treeDensity; currDetail++)
                    {
                        var rand1 = (float) random.NextDouble();
                        var rand2 = (float) random.NextDouble();
                        treeList.Add(new Vector3(
                                         x + rand1,
                                         groundMap.GetExactHeight(x, y, rand1, rand2),
                                         y + rand2));
                    }
                }

            return treeList;
        }