private void NEViewPort_SizeChanged(object sender, EventArgs e) { m_view.Width = (uint)this.ClientSize.Width; m_view.Height = (uint)this.ClientSize.Height; NEngineConfig eng = NEditorEngine.Instance().Config; m_view.X = (uint)(eng.ClientWidth - m_view.Width) / 2; m_view.Y = (uint)(eng.ClientHeight - m_view.Height) / 2; m_cameraSight = m_minCameraSight * (1 - m_Sight * m_Sight) + m_maxCameraSight * (m_Sight * m_Sight); m_view.Camera.SetPerspective(MathConst.PI / 4, ClientSize.Width, ClientSize.Height, 20, m_cameraSight); }
public void CreateViewport() { // initialize Viewport int w = NEditorEngine.Instance().Config.ClientWidth; int h = NEditorEngine.Instance().Config.ClientHeight; m_viewport = new NViewport(); m_viewport.Camera.SetPerspective(MathConst.PI / 4, w, h, 20, 500000); m_viewport.HandleWnd = this.Handle; m_viewport.RenderMode = ERenderMode.Unlit; this.NRenderContorl_SizeChanged(null, null); // create render element NWidgetsRender widgetsRender = new NWidgetsRender(); m_viewport.WidgetsRender = widgetsRender; widgetsRender.AddRenderControl(this); // 创建UI系统 new GUISystem(widgetsRender.UICanvas); // 签署事件 this.KeyDown += new System.Windows.Forms.KeyEventHandler(NRenderControl_KeyDown); this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(NRenderControl_KeyPress); this.KeyUp += new System.Windows.Forms.KeyEventHandler(NRenderControl_KeyUp); this.MouseClick += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseClick); this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseDoubleClick); this.MouseDown += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseUp); this.MouseWheel += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseWheel); this.MouseMove += new System.Windows.Forms.MouseEventHandler(NRenderControl_MouseMove); //加载程序集,注册内置窗口类型 Assembly executingAssembly = Assembly.GetExecutingAssembly(); WindowManager.Instance.LoadAssembly(Path.GetDirectoryName(executingAssembly.Location) + System.IO.Path.DirectorySeparatorChar + @"Nexus.GUI.dll"); // 加载当前执行文件中窗口类型 WindowManager.Instance.AttachAssembly(executingAssembly); // 创建一个缺省的唯一父窗口 GUISystem.Instance.RootWindow = WindowManager.Instance.CreateWindow("Nexus.GUI.Widgets.GUISheet", "root", null); PostInitialize(); // create game timer m_gameTimer = new NGameTimer(); m_gameTimer.Reset(); }
public NEViewport() { m_view = new NViewport(); int w = NEditorEngine.Instance().Config.ClientWidth; int h = NEditorEngine.Instance().Config.ClientHeight; m_minCameraSight = 500; m_maxCameraSight = 300000; m_Sight = 0.25f; m_cameraSight = m_minCameraSight * (1 - m_Sight * m_Sight) + m_maxCameraSight * (m_Sight * m_Sight); m_view.Camera.SetPerspective(MathConst.PI / 4, w, h, 1.0f, m_cameraSight); m_cameraCtrl = new NPerspectiveCameraController(); InitializeComponent(); this.Dock = DockStyle.Fill; this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); m_view.HandleWnd = this.Handle; m_view.RenderMode = ERenderMode.Unlit; this.NEViewPort_SizeChanged(this, null); // set view pos/size NEWidgetsRender widgets = CreateWidgetsRender(); m_view.WidgetsRender = widgets; widgets.AddViewport(this); //-- context menu m_menu = new ContextMenuStrip(); ToolStripMenuItem viewMenu = new ToolStripMenuItem("Render mode"); foreach (ERenderMode rm in Enum.GetValues(typeof(ERenderMode))) { ToolStripItem item = viewMenu.DropDownItems.Add(rm.ToString()); item.Click += new EventHandler(this.OnMenuClickRenderMode); } m_menu.Items.Add(viewMenu); ToolStripItem cameraItem = m_menu.Items.Add("Reset camera"); //-- m_mainTimer = new NGameTimer(); m_mainTimer.Reset(); }