//////////////////////////////////////////////////////////////////////////////////// //重建除device之外的一切D3D资源 public void SetupDevice() { //重建所有的Mesh if (ms.mesh == null) { ms.CreateExtrusionMesh(device); } if (ws.mesh == null) { ws.CreateWallMesh(device); } //重建所有的VertexBuffer if (pl.vertexbuf == null) { pl.CreatePartitionLinesVertexBuffer(device); } if (wpl.vertexbuf == null) { wpl.CreateWallPartitionLinesVertexBuffer(device); } //一体创建sl及其VertexBuffer if (sl == null) { sl = new SelectionLines(ms.polys[curr_district]); sl.CreateSelectionLines(device); } ////创建显示所需的字体 if (d3dfont_selected == null) { d3dfont_selected = new Microsoft.DirectX.Direct3D.Font(device, font_selected); } if (d3dfont_hud == null) { d3dfont_hud = new Microsoft.DirectX.Direct3D.Font(device, font_hud); } //设置信息框背景贴图 if (bkground_hud == null) { bkground_hud = new Texture(device, bmp_hud, Usage.Dynamic, Pool.Default); } //创建显示信息框的精灵 if (sprite == null) { sprite = new Sprite(device); } }
//////////////////////////////////////////////////////////////////////////////////// void Game_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.C: EnableColoring = !EnableColoring; EnableLights = false; ms.mesh.Dispose(); ms = new ExtrusionMesh(sec, Color.White, EnableColoring); ms.CreateExtrusionMesh(device); break; case Keys.Escape: case Keys.Q: Close(); break; case Keys.K: //距离 //地图越大,将距离调最远时,越容易出现被culling的现象,估计跟projection有关 camera.IncreaseRadius(100F); //if (scaling + 0.1F <= 5) scaling += 0.1f; break; case Keys.J: //距离 camera.DecreaseRadius(100F); //if (scaling - 0.1F >= 0.1) scaling -= 0.1f; break; case Keys.Left: //视角 camera.DecreaseLongitude((float)(0.02 * Math.PI)); break; case Keys.Right: //视角 camera.IncreaseLongitude((float)(0.02 * Math.PI)); break; case Keys.Up: //视角 camera.IncreaseLatitude((float)(0.02F * Math.PI)); break; case Keys.Down: //视角 camera.DecreaseLatitude((float)(0.02F * Math.PI)); break; case Keys.Z: //光线方向 dir_light.AdjustLongitude((float)(-0.02 * Math.PI)); break; case Keys.X: //光线方向 dir_light.AdjustLongitude((float)(0.02 * Math.PI)); break; case Keys.A: //光线方向 dir_light.AdjustLatitude((float)(0.02 * Math.PI)); break; case Keys.S: //光线方向 dir_light.AdjustLatitude((float)(-0.02 * Math.PI)); break; case Keys.F: //区域线框 DisplayWireFrame = !DisplayWireFrame; break; case Keys.L: //光照开关 EnableLights = !EnableLights; break; case Keys.H: //水平面开关 DisplayHorizonalMesh = !DisplayHorizonalMesh; break; case Keys.V: //垂直面开关 DisplayVerticalMesh = !DisplayVerticalMesh; break; case Keys.I: DisplayInfoHUD = !DisplayInfoHUD; break; case Keys.R: //复位world平移矢量和camera半径 world_translation = center; camera.ResetRadius(); break; #if (!FULL_SCREEN) case Keys.O: string fn = Program.SelectSecFile(); if (fn != null) { //从头创建所有的一切! CleanupGraphics(); GC.Collect(); ResetAll(fn); InitializeGraphics(); } break; #endif case Keys.OemPeriod: curr_district = (curr_district + 1) % ms.polys.Length; sl.Dispose(); sl = new SelectionLines(ms.polys[curr_district]); sl.CreateSelectionLines(device); curr_centroid = ms.polys[curr_district].GetCentroid(); GenerateMessageString(); break; case Keys.Oemcomma: curr_district = (curr_district + ms.polys.Length - 1) % ms.polys.Length; sl.Dispose(); sl = new SelectionLines(ms.polys[curr_district]); sl.CreateSelectionLines(device); curr_centroid = ms.polys[curr_district].GetCentroid(); GenerateMessageString(); break; default: Debug.WriteLine(e.KeyCode); break; } }