////////////////////////////////////////////////////////////////////////////////////////////////////// public bool InitializeGraphics() { //初始化设备参数 CreatePresentParameters(FSAA); Device.IsUsingEventHandlers = false; //关闭MDX的自动事件布线机制! if (D3DConfiguration.SupportsHardwareVertexProcessing()) { device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, present_params); } else { device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, present_params); } device.DeviceReset += new EventHandler(this.OnDeviceReset); device.DeviceLost += new EventHandler(this.OnDeviceLost); axises = new CoordAxies(); //初始化坐标轴 SetupDevice(); //重建所有资源 camera = new FreeRotateCamera(mm.radius); return(true); }
////////////////////////////////////////////////////////////////////////////////////////////////////// private void Game_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.C: MeshCenter = !MeshCenter; //切换原点位置标志 axises.DisposeAllBuffer(); //删除原有的坐标轴 axises = new CoordAxies(); //彻底重建坐标轴 Vector3 center = MeshCenter ? mm.center : (new Vector3()); axises.CreateAllBuffer(device, center, mm.radius); break; case Keys.X: DrawCoordinateAxies = !DrawCoordinateAxies; break; case Keys.E: mbi.ExportToObjFile(null, null, null); Debug.WriteLine("[导出功能] OBJ/MTL文件和所有贴图导出完成."); Text += "[*]"; break; case Keys.A: //开启或者关闭FSAA FSAA = !FSAA; CreatePresentParameters(FSAA); device.Reset(present_params); break; case Keys.Escape: case Keys.Q: Close(); break; case Keys.K: //距离 camera.IncreaseRadius(20f); break; case Keys.J: //距离 camera.DecreaseRadius(20f); break; case Keys.R: //复位旋转阵 camera.Reset(); break; case Keys.F: //区域线框 DisplayWireFrame++; DisplayWireFrame %= 3; break; case Keys.O: string fn = Program.SelectSecFile(); if (fn != null) { //从头创建所有的一切! Cleanup(); GC.Collect(); ResetAll(fn); InitializeGraphics(); } break; case Keys.B: DrawBackground = !DrawBackground; if (DrawBackground) { BackColor = Color.FromArgb(0xff, 0x0, 0xff); } else { BackColor = Color.Black; } break; default: Debug.WriteLine(e.KeyCode); break; } }