/// <summary> Start the class. Pass the GL window control, and the initial lookat/cameradirection and zoom. /// Control if registration of mouse and keyboard UI is performed with GL window control /// </summary> public void Start(GLWindowControl win, Vector3 lookat, Vector3 cameradirdegrees, float zoomn, bool registermouseui = true, bool registerkeyui = true) { glwin = win; win.Resize += glControl_Resize; win.Paint += glControl_Paint; if (registermouseui) { win.MouseDown += MouseDown; win.MouseUp += MouseUp; win.MouseMove += MouseMove; win.MouseWheel += MouseWheel; } if (registerkeyui) { win.KeyDown += KeyDown; win.KeyUp += KeyUp; } MatrixCalc.ResizeViewPort(this, win.Size); // inform matrix calc of window size PosCamera.SetPositionZoom(lookat, new Vector2(cameradirdegrees.X, cameradirdegrees.Y), zoomn, cameradirdegrees.Z); MatrixCalc.CalculateModelMatrix(PosCamera.LookAt, PosCamera.EyePosition, PosCamera.CameraRotation); MatrixCalc.CalculateProjectionMatrix(); }
/// <summary> Set Perpective mode (true) or Othographic mode (false) </summary> public void ChangePerspectiveMode(bool on) { MatrixCalc.InPerspectiveMode = on; MatrixCalc.CalculateModelMatrix(PosCamera.LookAt, PosCamera.EyePosition, PosCamera.CameraRotation); MatrixCalc.CalculateProjectionMatrix(); glwin.Invalidate(); }
// from the window, a resize event. Must have the correct context, if multiple, set glwin.EnsureCurrentPaintResize private void glControl_Resize(object sender) { //System.Diagnostics.Debug.WriteLine("Controller3d Resize" + glwin.Size); MatrixCalc.ResizeViewPort(this, glwin.Size); MatrixCalc.CalculateModelMatrix(PosCamera.LookAt, PosCamera.EyePosition, PosCamera.CameraRotation); // non perspective viewport changes also can affect model matrix MatrixCalc.CalculateProjectionMatrix(); glwin.Invalidate(); }
/// <summary> Recalculate matrix - only use if changed a fundamental in matrixcalc </summary> public void RecalcMatrices() { MatrixCalc.CalculateModelMatrix(PosCamera.LookAt, PosCamera.EyePosition, PosCamera.CameraRotation); MatrixCalc.CalculateProjectionMatrix(); }