static Map.Map Random(SlimDX.Direct3D9.Device device, System.Drawing.SizeF size, int nHeightIncs, int nSplatDraws, int nProps) { var m = Map.Map.New(new Client.Game.Map.MapSettings { Size = size }, device); m.MainCharacter.Position = new SlimDX.Vector3(m.Settings.Size.Width/2f, m.Settings.Size.Height/2f, 0); Random r = new Random(); // Heightmap Graphics.Editors.GroundTextureEditor e = new Graphics.Editors.GroundTextureEditor { Size = m.Settings.Size, SoftwareTexture = new Graphics.Software.Texture<Graphics.Software.Texel.R32F>[] { new Graphics.Software.Texture<Graphics.Software.Texel.R32F>(m.Ground.Heightmap) }, Pencil = new Graphics.Editors.GroundTexturePencil { Color = new SlimDX.Vector4(1, 0, 0, 0), Radius = 5, Type = Graphics.Editors.GroundTexturePencilType.Add } }; e.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler( (o, args) => m.Ground.UpdatePieceMeshes(args.ChangedRegion)); for (int i = 0; i < nHeightIncs; i++) { var p = new Graphics.Editors.GroundTexturePencil { Radius = 1 + (float)(r.NextDouble()*10), Color = new SlimDX.Vector4((float)(r.NextDouble() * 2 - 1), 0, 0, 0), Type = Graphics.Editors.GroundTexturePencilType.Add }; e.Draw( new SlimDX.Vector2((float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height)), p); } // Splatmap e = new Graphics.Editors.GroundTextureEditor { Size = m.Settings.Size, SoftwareTexture = new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>[] { new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>( Graphics.TextureUtil.ReadTexture<Graphics.Software.Texel.A8R8G8B8>(m.Ground.SplatMap1.Resource9, 0)) }, Texture9 = new SlimDX.Direct3D9.Texture[] { m.Ground.SplatMap1.Resource9 }, Pencil = new Graphics.Editors.GroundTexturePencil { Color = new SlimDX.Vector4(1, 0, 0, 0), Radius = 5, Type = Graphics.Editors.GroundTexturePencilType.Add } }; for (int i = 0; i < nSplatDraws; i++) { SlimDX.Vector4 v = Vector4.Zero; float d = (float)r.NextDouble(); switch (r.Next(5)) { case 0: v = new Vector4(d, -d, -d, -d); break; case 1: v = new Vector4(-d, d, -d, -d); break; case 2: v = new Vector4(-d, -d, d, -d); break; case 3: v = new Vector4(-d, -d, -d, d); break; case 4: v = new Vector4(-d, -d, -d, -d); break; } var p = new Graphics.Editors.GroundTexturePencil { Radius = 1 + (float)(r.NextDouble() * 10), Color = v, Type = Graphics.Editors.GroundTexturePencilType.AddSaturate }; e.Draw( new SlimDX.Vector2((float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height)), p); } // Props List<Type> propTypes = new List<Type>(); foreach (var v in typeof(Map.Props.Prop).Assembly.GetTypes()) if (typeof(Map.Props.Prop).IsAssignableFrom(v)) propTypes.Add(v); propTypes.Remove(typeof(Map.Props.Prop)); for (int i = 0; i < nProps; i++) { var p = (Map.Props.Prop)Activator.CreateInstance(propTypes[r.Next(propTypes.Count)]); p.Position = new SlimDX.Vector3( (float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height), 0); float rotation = (float)(2 * Math.PI * r.NextDouble()); p.Rotation = Quaternion.RotationAxis(Vector3.UnitZ, rotation); p.Position = m.Ground.GetHeight(p.Position); m.DynamicsRoot.AddChild(p); } m.MainCharacter.Position = m.Ground.GetHeight(m.MainCharacter.Position); return m; }
static Map.Map Random(SlimDX.Direct3D9.Device device, System.Drawing.SizeF size, int nHeightIncs, int nSplatDraws, int nProps) { var m = Map.Map.New(new Client.Game.Map.MapSettings { Size = size }, device); m.MainCharacter.Position = new SlimDX.Vector3(m.Settings.Size.Width / 2f, m.Settings.Size.Height / 2f, 0); Random r = new Random(); // Heightmap Graphics.Editors.GroundTextureEditor e = new Graphics.Editors.GroundTextureEditor { Size = m.Settings.Size, SoftwareTexture = new Graphics.Software.Texture <Graphics.Software.Texel.R32F>[] { new Graphics.Software.Texture <Graphics.Software.Texel.R32F>(m.Ground.Heightmap) }, Pencil = new Graphics.Editors.GroundTexturePencil { Color = new SlimDX.Vector4(1, 0, 0, 0), Radius = 5, Type = Graphics.Editors.GroundTexturePencilType.Add } }; e.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler( (o, args) => m.Ground.UpdatePieceMeshes(args.ChangedRegion)); for (int i = 0; i < nHeightIncs; i++) { var p = new Graphics.Editors.GroundTexturePencil { Radius = 1 + (float)(r.NextDouble() * 10), Color = new SlimDX.Vector4((float)(r.NextDouble() * 2 - 1), 0, 0, 0), Type = Graphics.Editors.GroundTexturePencilType.Add }; e.Draw( new SlimDX.Vector2((float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height)), p); } // Splatmap e = new Graphics.Editors.GroundTextureEditor { Size = m.Settings.Size, SoftwareTexture = new Graphics.Software.Texture <Graphics.Software.Texel.A8R8G8B8>[] { new Graphics.Software.Texture <Graphics.Software.Texel.A8R8G8B8>( Graphics.TextureUtil.ReadTexture <Graphics.Software.Texel.A8R8G8B8>(m.Ground.SplatMap1.Resource9, 0)) }, Texture9 = new SlimDX.Direct3D9.Texture[] { m.Ground.SplatMap1.Resource9 }, Pencil = new Graphics.Editors.GroundTexturePencil { Color = new SlimDX.Vector4(1, 0, 0, 0), Radius = 5, Type = Graphics.Editors.GroundTexturePencilType.Add } }; for (int i = 0; i < nSplatDraws; i++) { SlimDX.Vector4 v = Vector4.Zero; float d = (float)r.NextDouble(); switch (r.Next(5)) { case 0: v = new Vector4(d, -d, -d, -d); break; case 1: v = new Vector4(-d, d, -d, -d); break; case 2: v = new Vector4(-d, -d, d, -d); break; case 3: v = new Vector4(-d, -d, -d, d); break; case 4: v = new Vector4(-d, -d, -d, -d); break; } var p = new Graphics.Editors.GroundTexturePencil { Radius = 1 + (float)(r.NextDouble() * 10), Color = v, Type = Graphics.Editors.GroundTexturePencilType.AddSaturate }; e.Draw( new SlimDX.Vector2((float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height)), p); } // Props List <Type> propTypes = new List <Type>(); foreach (var v in typeof(Map.Props.Prop).Assembly.GetTypes()) { if (typeof(Map.Props.Prop).IsAssignableFrom(v)) { propTypes.Add(v); } } propTypes.Remove(typeof(Map.Props.Prop)); for (int i = 0; i < nProps; i++) { var p = (Map.Props.Prop)Activator.CreateInstance(propTypes[r.Next(propTypes.Count)]); p.Position = new SlimDX.Vector3( (float)(r.NextDouble() * m.Settings.Size.Width), (float)(r.NextDouble() * m.Settings.Size.Height), 0); float rotation = (float)(2 * Math.PI * r.NextDouble()); p.Rotation = Quaternion.RotationAxis(Vector3.UnitZ, rotation); p.Position = m.Ground.GetHeight(p.Position); m.DynamicsRoot.AddChild(p); } m.MainCharacter.Position = m.Ground.GetHeight(m.MainCharacter.Position); return(m); }