private void CreateGround(bool flatGround) { var heightmap = new Graphics.Software.Texel.R32F[50, 50]; Random r = new Random(42); int xSize = 4; int ySize = 4; int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 0f; if (r.NextDouble() > 0.96) { height = 16f * (float)r.NextDouble() - 8f; } else if (r.NextDouble() > 0.92) { height = 8f * (float)r.NextDouble() - 4f; } else { height = 1f * (float)r.NextDouble() - 1f; } for (int yp = 0; yp < ySize; yp++) { for (int xp = 0; xp < xSize; xp++) { //if (x > 0 && y > 0) if (flatGround) { heightmap[x * xSize + xp, y *ySize + yp].R = 0; } else { heightmap[x * xSize + xp, y *ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)); } } } lastHeight = height; } } var ground = new TestGround { Simulation = motionSimulation, Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(12, 12), Height = 1, }; scene.Add(ground); ground.ConstructPieces(); }
private void CreateGround() { var heightmap = new Graphics.Software.Texel.R32F[100, 100]; Random r = new Random(); int xSize = 4; int ySize = 4; int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 2f * (float)r.NextDouble() - 1f; for (int yp = 0; yp < ySize; yp++) { for (int xp = 0; xp < xSize; xp++) { if (x > 0 && y > 0) { heightmap[x * xSize + xp, y *ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)); } } } lastHeight = height; } } var ground = new TestGround { Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(10, 10), Height = 1, }; scene.Add(ground); ground.ConstructPieces(); }
protected virtual void DeserializeHieghtmap(Map map, Stream stream) { // Heightmap serialization method 3 var d = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(stream); d.GetNextEntry(); var br = new BinaryReader(d); var height = br.ReadInt32(); var width = br.ReadInt32(); var hm = new Graphics.Software.Texel.R32F[height, width]; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { hm[y, x] = new Graphics.Software.Texel.R32F(br.ReadSingle()); } } map.Ground.Heightmap = hm; d.Close(); }
protected virtual void DeserializeHieghtmap(Map map, Stream stream) { // Heightmap serialization method 3 var d = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(stream); d.GetNextEntry(); var br = new BinaryReader(d); var height = br.ReadInt32(); var width = br.ReadInt32(); var hm = new Graphics.Software.Texel.R32F[height, width]; for (var y = 0; y < height; y++) for (var x = 0; x < width; x++) hm[y, x] = new Graphics.Software.Texel.R32F(br.ReadSingle()); map.Ground.Heightmap = hm; d.Close(); }
public override void Init() { Content.ContentPath = "Data"; scene = new Scene(); scene.View = this; scene.Camera = new LookatCartesianCamera() { Position = new Vector3(10, 10, 10), Lookat = Vector3.Zero, ZFar = 100, AspectRatio = AspectRatio }; InputHandler = new WalkaroundCameraInputHandler { Camera = (LookatCartesianCamera)scene.Camera }; //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100); Random r = new Random(); heightmap = new Graphics.Software.Texel.R32F[64, 64]; for (int y = 0; y < 64; y++) { for (int x = 0; x < 64; x++) { heightmap[y, x] = new Graphics.Software.Texel.R32F((float)r.NextDouble()); } } renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Device9StateManager(Device9) }; renderer.Initialize(this); sceneRendererConnector = new SortedTestSceneRendererConnector { Scene = scene, Renderer = renderer }; sceneRendererConnector.Initialize(); SizeF patches = new SizeF(20, 20); SizeF patchSize = new SizeF(1f / 20f, 1f / 20f); SizeF groundSize = new SizeF(100, 100); for (int y = 0; y < patches.Height; y++) { for (int x = 0; x < patches.Width; x++) { scene.Add(e = new Entity { MainGraphic = new MetaModel { XMesh = new MeshConcretize { MeshDescription = new Graphics.Software.Meshes.MeshFromHeightmap { Grid = new Graphics.Software.Meshes.Grid { Position = Vector3.Zero, MeshType = MeshType.Indexed, Size = new Vector2(patchSize.Width * groundSize.Width, patchSize.Height * groundSize.Height), NWidth = (int)((heightmap.GetLength(1) - 1) * patchSize.Width), NHeight = (int)((heightmap.GetLength(0) - 1) * patchSize.Height), UVMin = new Vector2(0, 0), UVMax = new Vector2(1, 1) }, Height = 5, Heightmap = heightmap, Rectangle = new RectangleF(x * patchSize.Width, y * patchSize.Height, patchSize.Width, patchSize.Height), PointSample = true }, Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance }, Texture = new TextureFromFile("Models/GroundTextures/Grass1.png") }, Translation = new Vector3(x * groundSize.Width / patches.Width, y * groundSize.Height / patches.Height, 0), VisibilityLocalBounding = Vector3.Zero }); } } }
private float[][] CreateGround() { var heightmap = new Graphics.Software.Texel.R32F[57, 121]; Random r = new Random(1024); int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 0f; if (r.NextDouble() > 0.92) { height = 16f * (float)r.NextDouble() - 8f; } else if (r.NextDouble() > 0.82) { height = 8f * (float)r.NextDouble() - 4f; } else { height = 1f * (float)r.NextDouble() - 1f; } for (int yp = 0; yp < ySize; yp++) { for (int xp = 0; xp < xSize; xp++) { if (x > 0 && y > 0) { heightmap[x * xSize + xp, y *ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)) + heightOffset; } } } lastHeight = height; } } var ground = new TestGround { Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(xSize, ySize), Height = 1, Simulation = motionSimulation }; scene.Add(ground); ground.ConstructPieces(); float[][] floatMap = new float[heightmap.GetLength(0)][]; for (int i = 0; i < heightmap.GetLength(0); i++) { floatMap[i] = new float[heightmap.GetLength(1)]; for (int j = 0; j < heightmap.GetLength(1); j++) { floatMap[i][j] = heightmap[i, j].R; } } return(floatMap); }
private void CreateGround() { var heightmap = new Graphics.Software.Texel.R32F[100, 100]; Random r = new Random(); int xSize = 4; int ySize = 4; int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 2f * (float)r.NextDouble() - 1f; for (int yp = 0; yp < ySize; yp++) for (int xp = 0; xp < xSize; xp++) { if (x > 0 && y > 0) heightmap[x*xSize + xp, y*ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)); } lastHeight = height; } } var ground = new TestGround { Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(10, 10), Height = 1, }; scene.Add(ground); ground.ConstructPieces(); }
private float[][] CreateGround() { var heightmap = new Graphics.Software.Texel.R32F[57, 121]; Random r = new Random(1024); int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 0f; if (r.NextDouble() > 0.92) height = 16f * (float)r.NextDouble() - 8f; else if (r.NextDouble() > 0.82) height = 8f * (float)r.NextDouble() - 4f; else height = 1f * (float)r.NextDouble() - 1f; for (int yp = 0; yp < ySize; yp++) for (int xp = 0; xp < xSize; xp++) { if (x > 0 && y > 0) { heightmap[x * xSize + xp, y * ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)) + heightOffset; } } lastHeight = height; } } var ground = new TestGround { Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(xSize, ySize), Height = 1, Simulation = motionSimulation }; scene.Add(ground); ground.ConstructPieces(); float[][] floatMap = new float[heightmap.GetLength(0)][]; for (int i=0; i<heightmap.GetLength(0); i++) { floatMap[i] = new float[heightmap.GetLength(1)]; for (int j=0; j<heightmap.GetLength(1); j++) { floatMap[i][j] = heightmap[i, j].R; } } return floatMap; }
private void CreateGround(bool flatGround) { var heightmap = new Graphics.Software.Texel.R32F[50, 50]; Random r = new Random(42); int xSize = 4; int ySize = 4; int xPieces = (int)(heightmap.GetLength(0) / (float)xSize); int yPieces = (int)(heightmap.GetLength(1) / (float)ySize); float lastHeight = 0f; for (int y = 0; y < yPieces; y++) { for (int x = 0; x < xPieces; x++) { float height = 0f; if (r.NextDouble() > 0.96) height = 16f * (float)r.NextDouble() - 8f; else if (r.NextDouble() > 0.92) height = 8f * (float)r.NextDouble() - 4f; else height = 1f * (float)r.NextDouble() - 1f; for (int yp = 0; yp < ySize; yp++) for (int xp = 0; xp < xSize; xp++) { //if (x > 0 && y > 0) if (flatGround) heightmap[x * xSize + xp, y * ySize + yp].R = 0; else heightmap[x * xSize + xp, y * ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)); } lastHeight = height; } } var ground = new TestGround { Simulation = motionSimulation, Size = new SizeF(size.Width, size.Height), Heightmap = heightmap, NPieces = new Size(12, 12), Height = 1, }; scene.Add(ground); ground.ConstructPieces(); }
public override void Init() { Content.ContentPath = "Data"; scene = new Scene(); scene.View = this; scene.Camera = new LookatCartesianCamera() { Position = new Vector3(10, 10, 10), Lookat = Vector3.Zero, ZFar = 100, AspectRatio = AspectRatio }; InputHandler = new WalkaroundCameraInputHandler { Camera = (LookatCartesianCamera)scene.Camera }; //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100); Random r = new Random(); heightmap = new Graphics.Software.Texel.R32F[64, 64]; for (int y = 0; y < 64; y++) for (int x = 0; x < 64; x++) heightmap[y, x] = new Graphics.Software.Texel.R32F((float)r.NextDouble()); renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Device9StateManager(Device9) }; renderer.Initialize(this); sceneRendererConnector = new SortedTestSceneRendererConnector { Scene = scene, Renderer = renderer }; sceneRendererConnector.Initialize(); SizeF patches = new SizeF(20, 20); SizeF patchSize = new SizeF(1f / 20f, 1f / 20f); SizeF groundSize = new SizeF(100, 100); for(int y=0; y < patches.Height; y++) for (int x = 0; x < patches.Width; x++) scene.Add(e = new Entity { MainGraphic = new MetaModel { XMesh = new MeshConcretize { MeshDescription = new Graphics.Software.Meshes.MeshFromHeightmap { Grid = new Graphics.Software.Meshes.Grid { Position = Vector3.Zero, MeshType = MeshType.Indexed, Size = new Vector2(patchSize.Width * groundSize.Width, patchSize.Height * groundSize.Height), NWidth = (int)((heightmap.GetLength(1) - 1) * patchSize.Width), NHeight = (int)((heightmap.GetLength(0) - 1) * patchSize.Height), UVMin = new Vector2(0, 0), UVMax = new Vector2(1, 1) }, Height = 5, Heightmap = heightmap, Rectangle = new RectangleF(x * patchSize.Width, y * patchSize.Height, patchSize.Width, patchSize.Height), PointSample = true }, Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance }, Texture = new TextureFromFile("Models/GroundTextures/Grass1.png") }, Translation = new Vector3(x * groundSize.Width/patches.Width, y*groundSize.Height/patches.Height, 0), VisibilityLocalBounding = Vector3.Zero }); }