protected override void OnRenderFrame(FrameEventArgs e) { //RenderGui(); GL.MatrixMode(MatrixMode.Projection); // Select the Projection matrix for operation GL.LoadIdentity(); // Reset Projection matrix GL.Ortho(0, this.Width * Global.Scale, 0, this.Height * Global.Scale, -1.0, 1.0); // Set clipping area's left, right, bottom, top GL.MatrixMode(MatrixMode.Modelview); // Select the ModelView for operation GL.LoadIdentity(); // Reset the Model View Matrix GL.Clear(ClearBufferMask.ColorBufferBit); // | ClearBufferMask.DepthBufferBit); GL.Disable(EnableCap.DepthTest); GL.PushMatrix(); // Render World Map var avgHeight = 0; var count = 0; foreach (var poly in MapManager.GetWorldMapBlocks(Global.Direction)) { var scrPos = WorldToScreen(poly.Item1.X, poly.Item1.Y, poly.Item1.Z, largeBlock: true); RenderLargeBlock((float)e.Time, poly.Item2, scrPos.Item1, scrPos.Item2, scrPos.Item3, poly.Item1); if (Math.Abs(poly.Item1.Z - Global.LookingAt.Z) <= 100 && Math.Abs(poly.Item1.X - Global.LookingAt.X) <= 100) { avgHeight += poly.Item1.Y; count++; } //scrPos = WorldToScreen(poly[1].X, poly[1].Y, poly[1].Z); //RenderLargeBlock((float)e.Time,(Block.BlockType)TextureGrass,scrPos.Item1, scrPos.Item2, scrPos.Item3,poly[1]); //scrPos = WorldToScreen(poly[2].X, poly[2].Y, poly[2].Z); //RenderLargeBlock((float)e.Time,(Block.BlockType)TextureGrass,scrPos.Item1, scrPos.Item2, scrPos.Item3,poly[2]); //scrPos = WorldToScreen(poly[3].X, poly[3].Y, poly[3].Z); //RenderLargeBlock((float)e.Time,(Block.BlockType)TextureGrass,scrPos.Item1, scrPos.Item2, scrPos.Item3,poly[3]); } if (count > 0) { Global.LookingAt = new Position(Global.LookingAt.X, avgHeight / count, Global.LookingAt.Z); } GL.PopMatrix(); // Render Local Chunks int drawCount = 0; int cullCount = 0; foreach (var blockInfo in MapManager.GetBlocks(Global.Direction)) { var pos = blockInfo.Item1; var blockType = blockInfo.Item2; var scrPos = WorldToScreen(pos.X, pos.Y, pos.Z); if (scrPos.Item1 < 0 || scrPos.Item1 > (this.Width * Global.Scale) || scrPos.Item2 < 0 || scrPos.Item2 > (this.Height * Global.Scale)) { //Console.WriteLine($"{x1},{y1},{z1}=>{x2},{y2},{z2}"); cullCount++; } else { if (pos.Y < trimHeight) { drawCount++; RenderBlock((float)e.Time, blockType, scrPos.Item1, scrPos.Item2, scrPos.Item3, pos); } } } foreach (var character in CharacterManager.GetCharacters(Global.Direction)) { drawCount++; var scrPos = WorldToScreen(character.Item1.X, character.Item1.Y, character.Item1.Z); RenderBlock((float)e.Time, BlockType.Placeholder1, scrPos.Item1, scrPos.Item2, scrPos.Item3, character.Item1); // TODO - sprite block type scrPos = WorldToScreen(character.Item1.X, character.Item1.Y + 1, character.Item1.Z); RenderBlock((float)e.Time, BlockType.Placeholder1, scrPos.Item1, scrPos.Item2, scrPos.Item3, character.Item1); // TODO - sprite block type } //Console.WriteLine ($"DrawCount:{drawCount}, Culled:{cullCount}"); SwapBuffers(); }
public void GetWorldMap() { MapManager.SetWorldMapHeight(WorldInstance.GlobalMap); MapManager.SetWorldMapTerrain(WorldInstance.GlobalMapTerrain); }