/// <summary>Updates the openGL viewport</summary> /// <param name="Mode">The viewport change mode</param> internal static void UpdateViewport(ViewPortChangeMode Mode) { if (Mode == ViewPortChangeMode.ChangeToCab) { LibRender.Renderer.CurrentViewPortMode = ViewPortMode.Cab; } else { LibRender.Renderer.CurrentViewPortMode = ViewPortMode.Scenery; } GL.Viewport(0, 0, LibRender.Screen.Width, LibRender.Screen.Height); LibRender.Screen.AspectRatio = (double)LibRender.Screen.Width / (double)LibRender.Screen.Height; Camera.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * Camera.VerticalViewingAngle) * LibRender.Screen.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (LibRender.Renderer.CurrentViewPortMode == ViewPortMode.Cab) { Matrix4d perspective = Matrix4d.Perspective(Camera.VerticalViewingAngle, -LibRender.Screen.AspectRatio, 0.025, 50.0); GL.MultMatrix(ref perspective); } else { var b = CurrentRoute.CurrentBackground as BackgroundObject; var cd = b != null?Math.Max(Backgrounds.BackgroundImageDistance, b.ClipDistance) : Backgrounds.BackgroundImageDistance; Matrix4d perspective = Matrix4d.Perspective(Camera.VerticalViewingAngle, -LibRender.Screen.AspectRatio, 0.5, cd); GL.MultMatrix(ref perspective); } GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
internal static void UpdateViewport(ViewPortChangeMode Mode) { if (Mode == ViewPortChangeMode.ChangeToCab) { CurrentViewPortMode = ViewPortMode.Cab; } else { CurrentViewPortMode = ViewPortMode.Scenery; } GL.Viewport(0, 0, Screen.Width, Screen.Height); World.AspectRatio = (double)Screen.Width / (double)Screen.Height; World.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (CurrentViewPortMode == ViewPortMode.Cab) { Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.025, 50.0); GL.MultMatrix(ref perspective); } else { var b = BackgroundManager.CurrentBackground as BackgroundManager.BackgroundObject; var cd = b != null?Math.Max(World.BackgroundImageDistance, b.ClipDistance) : World.BackgroundImageDistance; Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.5, cd); GL.MultMatrix(ref perspective); } GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
internal static void UpdateViewport(ViewPortChangeMode Mode) { if (Mode == ViewPortChangeMode.ChangeToCab) { CurrentViewPortMode = ViewPortMode.Cab; } else { CurrentViewPortMode = ViewPortMode.Scenery; } GL.Viewport(0, 0, Screen.Width, Screen.Height); World.AspectRatio = (double)Screen.Width / (double)Screen.Height; World.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); //This value was used to convert radians to degrees //OpenTK works in radians, so removed..... //const double invdeg = 57.295779513082320877; if (CurrentViewPortMode == ViewPortMode.Cab) { //Glu.Perspective(World.VerticalViewingAngle * invdeg, -World.AspectRatio, 0.025, 50.0); Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.025, 50.0); GL.MultMatrix(ref perspective); } else { Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.5, World.BackgroundImageDistance); GL.MultMatrix(ref perspective); } GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
// XXX: Resize() and StartDraw() leave the matrix in a different mode than they got it in... public static void Resize() { double fov = Math.PI / 4; double aspectRatio = 4.0 / 3.0; Projection = Matrix4d.Perspective(fov, aspectRatio, ClipNear, ClipFar); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref Projection); }
private void myResize(object o, EventArgs e) { GL.Viewport(0, 0, ventana.Width, ventana.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); matriz = Matrix4d.Perspective (45.0f, ventana.Width / ventana.Height, 2.0f, 2000.0f); GL.LoadMatrix(ref matriz); GL.MatrixMode(MatrixMode.Modelview); }
// update viewport internal static void UpdateViewport() { GL.Viewport(0, 0, Renderer.ScreenWidth, Renderer.ScreenHeight); World.AspectRatio = (double)Renderer.ScreenWidth / (double)Renderer.ScreenHeight; World.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.2, 1000.0); GL.MultMatrix(ref perspective); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
// update viewport internal static void UpdateViewport() { GL.Viewport(0, 0, LibRender.Screen.Width, LibRender.Screen.Height); Screen.AspectRatio = (double)LibRender.Screen.Width / (double)LibRender.Screen.Height; Camera.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * Camera.VerticalViewingAngle) * Screen.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); Matrix4d perspective = Matrix4d.Perspective(Camera.VerticalViewingAngle, -Screen.AspectRatio, 0.2, 1000.0); GL.MultMatrix(ref perspective); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
/// <summary>Updates the openGL viewport for selection</summary> /// <param name="Point">Center of picking area at window coordinates</param> /// <param name="Delta">Width and height of picking area in window coordinates</param> private static void UpdateViewportSelection(Vector2 Point, Vector2 Delta) { CurrentViewPortMode = ViewPortMode.Cab; int[] Viewport = new int[] { 0, 0, Screen.Width, Screen.Height }; GL.Viewport(Viewport[0], Viewport[1], Viewport[2], Viewport[3]); World.AspectRatio = (double)Screen.Width / (double)Screen.Height; World.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); PickMatrix(new Vector2(Point.X, Viewport[3] - Point.Y), Delta, Viewport); Matrix4d perspective = Matrix4d.Perspective(World.VerticalViewingAngle, -World.AspectRatio, 0.025, 50.0); GL.MultMatrix(ref perspective); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); }
void keyDown(object o, KeyboardKeyEventArgs e) { if (e.Key == Key.D) { this.pos_x += 10.0; } if (e.Key == Key.A) { this.pos_x -= 10.0; } if (e.Key == Key.W) { this.pos_z += 10.0; } if (e.Key == Key.X) { this.pos_z -= 10.0; } if (e.Key == Key.S) { this.pos_y -= 10.0; } GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (e.Key == Key.O) { matriz = Matrix4d.CreateOrthographic(300.0, 300.0, 1.0, 300.0); } if (e.Key == Key.P) { // matriz = Matrix4d.Perspective(45.0f, ventana.Width / ventana.Height, 50.0f, 200.0f); matriz = Matrix4d.Perspective(45.0f, ventana.Width / ventana.Height, 2.0f, 2000.0f); // matriz = Matrix4d.CreatePerspectiveFieldOfView(20.0f, ventana.Width / ventana.Height, 50.0f, 200.0f); } GL.LoadMatrix(ref matriz); GL.MatrixMode(MatrixMode.Modelview); }