static private UpdateTrackFollower ( TrackFollower &Follower, double NewTrackPosition, bool UpdateWorldCoordinates, bool AddTrackInaccurary ) : void | ||
Follower | TrackFollower | The follower to update |
NewTrackPosition | double | The new track position of the follower |
UpdateWorldCoordinates | bool | Whether to update the world co-ordinates |
AddTrackInaccurary | bool | Whether to add track innacuracy |
Результат | void |
// update absolute camera internal static void UpdateAbsoluteCamera(double TimeElapsed) { // zoom double zm = World.CameraCurrentAlignment.Zoom; AdjustAlignment(ref World.CameraCurrentAlignment.Zoom, World.CameraAlignmentDirection.Zoom, ref World.CameraAlignmentSpeed.Zoom, TimeElapsed, World.CameraAlignmentSpeed.Zoom != 0.0); if (zm != World.CameraCurrentAlignment.Zoom) { ApplyZoom(); } // current alignment AdjustAlignment(ref World.CameraCurrentAlignment.Position.X, World.CameraAlignmentDirection.Position.X, ref World.CameraAlignmentSpeed.Position.X, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Position.Y, World.CameraAlignmentDirection.Position.Y, ref World.CameraAlignmentSpeed.Position.Y, TimeElapsed); bool q = World.CameraAlignmentSpeed.Yaw != 0.0 | World.CameraAlignmentSpeed.Pitch != 0.0 | World.CameraAlignmentSpeed.Roll != 0.0; AdjustAlignment(ref World.CameraCurrentAlignment.Yaw, World.CameraAlignmentDirection.Yaw, ref World.CameraAlignmentSpeed.Yaw, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Pitch, World.CameraAlignmentDirection.Pitch, ref World.CameraAlignmentSpeed.Pitch, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Roll, World.CameraAlignmentDirection.Roll, ref World.CameraAlignmentSpeed.Roll, TimeElapsed); double tr = World.CameraCurrentAlignment.TrackPosition; AdjustAlignment(ref World.CameraCurrentAlignment.TrackPosition, World.CameraAlignmentDirection.TrackPosition, ref World.CameraAlignmentSpeed.TrackPosition, TimeElapsed); if (tr != World.CameraCurrentAlignment.TrackPosition) { TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, World.CameraCurrentAlignment.TrackPosition, true, false); q = true; } if (q) { UpdateViewingDistances(); } Vector3 dF = new Vector3(CameraTrackFollower.WorldDirection); Vector3 uF = new Vector3(CameraTrackFollower.WorldUp); Vector3 sF = new Vector3(CameraTrackFollower.WorldSide); Vector3 pF = new Vector3(CameraCurrentAlignment.Position); Vector3 dx2 = new Vector3(dF); Vector3 ux2 = new Vector3(uF); if (World.CameraCurrentAlignment.Yaw != 0.0) { double cosa = Math.Cos(World.CameraCurrentAlignment.Yaw); double sina = Math.Sin(World.CameraCurrentAlignment.Yaw); dF.Rotate(uF, cosa, sina); sF.Rotate(uF, cosa, sina); } double p = World.CameraCurrentAlignment.Pitch; if (p != 0.0) { double cosa = Math.Cos(-p); double sina = Math.Sin(-p); dF.Rotate(sF, cosa, sina); uF.Rotate(sF, cosa, sina); uF.Rotate(sF, cosa, sina); } if (World.CameraCurrentAlignment.Roll != 0.0) { double cosa = Math.Cos(-World.CameraCurrentAlignment.Roll); double sina = Math.Sin(-World.CameraCurrentAlignment.Roll); uF.Rotate(dF, cosa, sina); sF.Rotate(dF, cosa, sina); } AbsoluteCameraPosition = new Vector3(CameraTrackFollower.WorldPosition.X + sF.X * pF.X + ux2.X * pF.Y + dx2.X * pF.Z, CameraTrackFollower.WorldPosition.Y + sF.Y * pF.X + ux2.Y * pF.Y + dx2.Y * pF.Z, CameraTrackFollower.WorldPosition.Z + sF.Z * pF.X + ux2.Z * pF.Y + dx2.Z * pF.Z); AbsoluteCameraDirection = dF; AbsoluteCameraUp = uF; AbsoluteCameraSide = sF; }
// process events private static void ProcessEvents() { SDL.SDL_Event Event; double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0); while (SDL.SDL_PollEvent(out Event) != 0) { switch (Event.type) { // quit case SDL.SDL_EventType.SDL_QUIT: Quit = true; return; // resize case SDL.SDL_EventType.SDL_WINDOWEVENT: if (Event.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED) { Renderer.ScreenWidth = Event.window.data1; Renderer.ScreenHeight = Event.window.data2; UpdateViewport(); } break; // mouse case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: // FIXME implement check whether any track is loaded! if (CurrentRoute != null) { switch (Event.button.button) { case (byte)SDL.SDL_BUTTON_LEFT: World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case (byte)SDL.SDL_BUTTON_RIGHT: World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case (byte)SDL.SDL_BUTTON_MIDDLE: Rotate = true; SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE); CpuReducedMode = false; break; } } break; case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: // FIXME implement check whether any track is loaded! if (CurrentRoute != null) { if (Event.button.button == SDL.SDL_BUTTON_LEFT || Event.button.button == SDL.SDL_BUTTON_RIGHT) { World.CameraAlignmentDirection.TrackPosition = 0.0; } else if (Event.button.button == SDL.SDL_BUTTON_MIDDLE) { SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE); World.CameraAlignmentDirection.Pitch = 0.0; World.CameraAlignmentDirection.Yaw = 0.0; Rotate = false; } } break; case SDL.SDL_EventType.SDL_MOUSEMOTION: // TODO - rotate if (Rotate && CurrentStation != -1) /* * World.CameraAlignmentDirection.Pitch = speedModified * -World.CameraExteriorTopAngularSpeed * Event.motion.yrel/3; * World.CameraAlignmentDirection.Yaw = speedModified * World.CameraExteriorTopAngularSpeed * Event.motion.xrel/3;*/ { } break; // key down case SDL.SDL_EventType.SDL_KEYDOWN: switch (Event.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_LSHIFT: case SDL.SDL_Keycode.SDLK_RSHIFT: ShiftPressed = true; break; case SDL.SDL_Keycode.SDLK_LCTRL: case SDL.SDL_Keycode.SDLK_RCTRL: ControlPressed = true; break; case SDL.SDL_Keycode.SDLK_LALT: case SDL.SDL_Keycode.SDLK_RALT: AltPressed = true; break; case SDL.SDL_Keycode.SDLK_F5: if (CurrentRoute != null) { CurrentlyLoading = true; Renderer.RenderScene(0.0); SwapBuffers(); World.CameraAlignment a = World.CameraCurrentAlignment; if (LoadRoute()) { World.CameraCurrentAlignment = a; TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false); World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); ObjectManager.UpdateVisibility(a.TrackPosition, true); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); } CurrentlyLoading = false; } break; case SDL.SDL_Keycode.SDLK_F7: { OpenFileDialog Dialog = new OpenFileDialog(); Dialog.CheckFileExists = true; Dialog.Filter = "CSV/RW files|*.csv;*.rw|All files|*"; if (Dialog.ShowDialog() == DialogResult.OK) { CurrentlyLoading = true; Renderer.RenderScene(0.0); SwapBuffers(); CurrentRoute = Dialog.FileName; LoadRoute(); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); CurrentlyLoading = false; UpdateCaption(); } } break; case SDL.SDL_Keycode.SDLK_F9: if (Interface.MessageCount != 0) { formMessages.ShowMessages(); } break; case SDL.SDL_Keycode.SDLK_a: case SDL.SDL_Keycode.SDLK_KP_4: World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_d: case SDL.SDL_Keycode.SDLK_KP_6: World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_2: World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_8: World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_w: case SDL.SDL_Keycode.SDLK_KP_9: if (CurrentRoute != null) { World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_s: case SDL.SDL_Keycode.SDLK_KP_3: if (CurrentRoute != null) { World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_LEFT: World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_RIGHT: World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_UP: World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_DOWN: World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_DIVIDE: World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_MULTIPLY: World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_0: World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_PERIOD: World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_1: Game.ApplyPointOfInterest(-1, true); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_7: Game.ApplyPointOfInterest(1, true); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_PAGEUP: JumpToStation(1); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_PAGEDOWN: JumpToStation(-1); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_KP_5: World.CameraCurrentAlignment.Yaw = 0.0; World.CameraCurrentAlignment.Pitch = 0.0; World.CameraCurrentAlignment.Roll = 0.0; World.CameraCurrentAlignment.Position = new World.Vector3D(0.0, 2.5, 0.0); World.CameraCurrentAlignment.Zoom = 0.0; World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); World.VerticalViewingAngle = World.OriginalVerticalViewingAngle; UpdateViewport(); World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_f: Renderer.OptionWireframe = !Renderer.OptionWireframe; CpuReducedMode = false; if (Renderer.OptionWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } break; case SDL.SDL_Keycode.SDLK_n: Renderer.OptionNormals = !Renderer.OptionNormals; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_e: Renderer.OptionEvents = !Renderer.OptionEvents; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_c: CpuAutomaticMode = !CpuAutomaticMode; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_i: Renderer.OptionInterface = !Renderer.OptionInterface; CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_m: SoundManager.Mute = !SoundManager.Mute; break; case SDL.SDL_Keycode.SDLK_PLUS: case SDL.SDL_Keycode.SDLK_KP_PLUS: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "+"; CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_MINUS: case SDL.SDL_Keycode.SDLK_KP_MINUS: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "-"; CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_0: case SDL.SDL_Keycode.SDLK_1: case SDL.SDL_Keycode.SDLK_2: case SDL.SDL_Keycode.SDLK_3: case SDL.SDL_Keycode.SDLK_4: case SDL.SDL_Keycode.SDLK_5: case SDL.SDL_Keycode.SDLK_6: case SDL.SDL_Keycode.SDLK_7: case SDL.SDL_Keycode.SDLK_8: case SDL.SDL_Keycode.SDLK_9: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = string.Empty; } JumpToPositionValue += char.ConvertFromUtf32(48 + Event.key.keysym.sym - SDL.SDL_Keycode.SDLK_0); CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_PERIOD: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "0."; } else if (JumpToPositionValue.IndexOf('.') == -1) { JumpToPositionValue += "."; } CpuReducedMode = false; break; case SDL.SDL_Keycode.SDLK_BACKSPACE: if (JumpToPositionEnabled && JumpToPositionValue.Length != 0) { JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1); CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_RETURN: if (JumpToPositionEnabled) { if (JumpToPositionValue.Length != 0) { int direction; if (JumpToPositionValue[0] == '-') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = -1; } else if (JumpToPositionValue[0] == '+') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = 1; } else { direction = 0; } double value; if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { if (direction != 0) { value = World.CameraTrackFollower.TrackPosition + (double)direction * value; } TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false); World.CameraCurrentAlignment.TrackPosition = value; World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); } } JumpToPositionEnabled = false; CpuReducedMode = false; } break; case SDL.SDL_Keycode.SDLK_ESCAPE: JumpToPositionEnabled = false; CpuReducedMode = false; break; } break; // key up case SDL.SDL_EventType.SDL_KEYUP: switch (Event.key.keysym.sym) { case SDL.SDL_Keycode.SDLK_LSHIFT: case SDL.SDL_Keycode.SDLK_RSHIFT: ShiftPressed = false; break; case SDL.SDL_Keycode.SDLK_LCTRL: case SDL.SDL_Keycode.SDLK_RCTRL: ControlPressed = false; break; case SDL.SDL_Keycode.SDLK_LALT: case SDL.SDL_Keycode.SDLK_RALT: AltPressed = false; break; case SDL.SDL_Keycode.SDLK_a: case SDL.SDL_Keycode.SDLK_KP_4: case SDL.SDL_Keycode.SDLK_d: case SDL.SDL_Keycode.SDLK_KP_6: World.CameraAlignmentDirection.Position.X = 0.0; break; case SDL.SDL_Keycode.SDLK_KP_2: case SDL.SDL_Keycode.SDLK_KP_8: World.CameraAlignmentDirection.Position.Y = 0.0; break; case SDL.SDL_Keycode.SDLK_w: case SDL.SDL_Keycode.SDLK_KP_9: case SDL.SDL_Keycode.SDLK_s: case SDL.SDL_Keycode.SDLK_KP_3: World.CameraAlignmentDirection.TrackPosition = 0.0; break; case SDL.SDL_Keycode.SDLK_LEFT: case SDL.SDL_Keycode.SDLK_RIGHT: World.CameraAlignmentDirection.Yaw = 0.0; break; case SDL.SDL_Keycode.SDLK_UP: case SDL.SDL_Keycode.SDLK_DOWN: World.CameraAlignmentDirection.Pitch = 0.0; break; case SDL.SDL_Keycode.SDLK_KP_DIVIDE: case SDL.SDL_Keycode.SDLK_KP_MULTIPLY: World.CameraAlignmentDirection.Roll = 0.0; break; case SDL.SDL_Keycode.SDLK_KP_0: case SDL.SDL_Keycode.SDLK_KP_PERIOD: World.CameraAlignmentDirection.Zoom = 0.0; break; } break; } } }
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) { double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0); switch (e.Key) { case Key.ShiftLeft: case Key.ShiftRight: ShiftPressed = true; break; case Key.ControlLeft: case Key.ControlRight: ControlPressed = true; break; case Key.LAlt: case Key.RAlt: AltPressed = true; break; case Key.F5: if (CurrentRoute != null && CurrentlyLoading == false) { CurrentlyLoading = true; Renderer.OptionInterface = false; if (!Interface.CurrentOptions.LoadingBackground) { Renderer.RenderScene(0.0); currentGameWindow.SwapBuffers(); Bitmap bitmap = new Bitmap(Renderer.ScreenWidth, Renderer.ScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); GL.ReadPixels(0, 0, Renderer.ScreenWidth, Renderer.ScreenHeight, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0); bitmap.UnlockBits(bData); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); Renderer.TextureLoadingBkg = TextureManager.RegisterTexture(bitmap, false); bitmap.Dispose(); } World.CameraAlignment a = World.CameraCurrentAlignment; if (LoadRoute()) { World.CameraCurrentAlignment = a; TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false); World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); ObjectManager.UpdateVisibility(a.TrackPosition, true); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); } CurrentlyLoading = false; Renderer.OptionInterface = true; TextureManager.UnregisterTexture(ref Renderer.TextureLoadingBkg); } break; case Key.F7: if (CurrentlyLoading == true) { break; } OpenFileDialog Dialog = new OpenFileDialog(); Dialog.CheckFileExists = true; Dialog.Filter = "CSV/RW files|*.csv;*.rw|All files|*"; if (Dialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); CurrentlyLoading = true; CurrentRoute = Dialog.FileName; LoadRoute(); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); CurrentlyLoading = false; UpdateCaption(); } else { if (Program.CurrentlyRunOnMono) { //HACK: Dialog doesn't close properly when pressing the ESC key under Mono //Avoid calling Application.DoEvents() unless absolutely necessary though! Application.DoEvents(); } } Dialog.Dispose(); break; case Key.F8: if (Program.CurrentlyLoading == true) { //Don't allow the user to update the settings during loading, bad idea.... break; } if (formOptions.ShowOptions() == DialogResult.OK) { UpdateGraphicsSettings(); } Application.DoEvents(); break; case Key.F9: if (Interface.MessageCount != 0) { formMessages.ShowMessages(); Application.DoEvents(); } break; case Key.F10: Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay; break; case Key.A: case Key.Keypad4: World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.D: case Key.Keypad6: World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad2: World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad8: World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.W: case Key.Keypad9: World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.S: case Key.Keypad3: World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Left: World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Right: World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Up: World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Down: World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadDivide: World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadMultiply: World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad0: World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadPeriod: World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad1: Game.ApplyPointOfInterest(-1, true); CpuReducedMode = false; break; case Key.Keypad7: Game.ApplyPointOfInterest(1, true); CpuReducedMode = false; break; case Key.PageUp: JumpToStation(1); CpuReducedMode = false; break; case Key.PageDown: JumpToStation(-1); CpuReducedMode = false; break; case Key.Keypad5: World.CameraCurrentAlignment.Yaw = 0.0; World.CameraCurrentAlignment.Pitch = 0.0; World.CameraCurrentAlignment.Roll = 0.0; World.CameraCurrentAlignment.Position = new Vector3(0.0, 2.5, 0.0); World.CameraCurrentAlignment.Zoom = 0.0; World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); World.VerticalViewingAngle = World.OriginalVerticalViewingAngle; UpdateViewport(); World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); CpuReducedMode = false; break; case Key.F: Renderer.OptionWireframe = !Renderer.OptionWireframe; CpuReducedMode = false; if (Renderer.OptionWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } break; case Key.N: Renderer.OptionNormals = !Renderer.OptionNormals; CpuReducedMode = false; break; case Key.E: Renderer.OptionEvents = !Renderer.OptionEvents; CpuReducedMode = false; break; case Key.C: CpuAutomaticMode = !CpuAutomaticMode; CpuReducedMode = false; break; case Key.I: Renderer.OptionInterface = !Renderer.OptionInterface; CpuReducedMode = false; break; case Key.M: //SoundManager.Mute = !SoundManager.Mute; break; case Key.Plus: case Key.KeypadPlus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "+"; CpuReducedMode = false; } break; case Key.Minus: case Key.KeypadMinus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "-"; CpuReducedMode = false; } break; case Key.Number0: case Key.Number1: case Key.Number2: case Key.Number3: case Key.Number4: case Key.Number5: case Key.Number6: case Key.Number7: case Key.Number8: case Key.Number9: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = string.Empty; } JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0); CpuReducedMode = false; break; case Key.Period: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "0."; } else if (JumpToPositionValue.IndexOf('.') == -1) { JumpToPositionValue += "."; } CpuReducedMode = false; break; case Key.BackSpace: if (JumpToPositionEnabled && JumpToPositionValue.Length != 0) { JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1); CpuReducedMode = false; } break; case Key.Enter: if (JumpToPositionEnabled) { if (JumpToPositionValue.Length != 0) { int direction; if (JumpToPositionValue[0] == '-') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = -1; } else if (JumpToPositionValue[0] == '+') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = 1; } else { direction = 0; } double value; if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { if (value < TrackManager.CurrentTrack.Elements[TrackManager.CurrentTrack.Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100) { if (direction != 0) { value = World.CameraTrackFollower.TrackPosition + (double)direction * value; } TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false); World.CameraCurrentAlignment.TrackPosition = value; World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); } } } } JumpToPositionEnabled = false; CpuReducedMode = false; break; case Key.Escape: JumpToPositionEnabled = false; CpuReducedMode = false; break; } }
internal static bool ApplyPointOfInterest(int Value, bool Relative) { double t = 0.0; int j = -1; if (Relative) { // relative if (Value < 0) { // previous poi t = double.NegativeInfinity; for (int i = 0; i < PointsOfInterest.Length; i++) { if (PointsOfInterest[i].TrackPosition < World.CameraTrackFollower.TrackPosition) { if (PointsOfInterest[i].TrackPosition > t) { t = PointsOfInterest[i].TrackPosition; j = i; } } } } else if (Value > 0) { // next poi t = double.PositiveInfinity; for (int i = 0; i < PointsOfInterest.Length; i++) { if (PointsOfInterest[i].TrackPosition > World.CameraTrackFollower.TrackPosition) { if (PointsOfInterest[i].TrackPosition < t) { t = PointsOfInterest[i].TrackPosition; j = i; } } } } } else { // absolute j = Value >= 0 & Value < PointsOfInterest.Length ? Value : -1; } // process poi if (j >= 0) { TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, t, true, false); World.CameraCurrentAlignment.Position = PointsOfInterest[j].TrackOffset; World.CameraCurrentAlignment.Yaw = PointsOfInterest[j].TrackYaw; World.CameraCurrentAlignment.Pitch = PointsOfInterest[j].TrackPitch; World.CameraCurrentAlignment.Roll = PointsOfInterest[j].TrackRoll; World.CameraCurrentAlignment.TrackPosition = t; World.UpdateAbsoluteCamera(0.0); return(true); } else { return(false); } }
/// <summary>Changes to or from fullscreen mode.</summary> internal static void ToggleFullscreen() { Fullscreen = !Fullscreen; // begin HACK // Renderer.ClearDisplayLists(); GL.Disable(EnableCap.Fog); GL.Disable(EnableCap.Lighting); Renderer.LightingEnabled = false; Textures.UnloadAllTextures(); if (Fullscreen) { IList <DisplayResolution> resolutions = OpenTK.DisplayDevice.Default.AvailableResolutions; for (int i = 0; i < resolutions.Count; i++) { //Test each resolution if (resolutions[i].Width == Interface.CurrentOptions.FullscreenWidth && resolutions[i].Height == Interface.CurrentOptions.FullscreenHeight && resolutions[i].BitsPerPixel == Interface.CurrentOptions.FullscreenBits) { OpenTK.DisplayDevice.Default.ChangeResolution(resolutions[i]); Program.currentGameWindow.Width = resolutions[i].Width; Program.currentGameWindow.Height = resolutions[i].Height; Screen.Width = Interface.CurrentOptions.FullscreenWidth; Screen.Height = Interface.CurrentOptions.FullscreenHeight; Program.currentGameWindow.WindowState = WindowState.Fullscreen; break; } } if (Program.currentGameWindow.WindowState != WindowState.Fullscreen) { MessageBox.Show(Interface.GetInterfaceString("errors_fullscreen_switch1") + System.Environment.NewLine + Interface.GetInterfaceString("errors_fullscreen_switch2"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); Fullscreen = false; } } else { OpenTK.DisplayDevice.Default.RestoreResolution(); Program.currentGameWindow.WindowState = WindowState.Normal; Program.currentGameWindow.Width = Interface.CurrentOptions.WindowWidth; Program.currentGameWindow.Height = Interface.CurrentOptions.WindowHeight; Screen.Width = Interface.CurrentOptions.WindowWidth; Screen.Height = Interface.CurrentOptions.WindowHeight; } Renderer.InitializeLighting(); MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange); MainLoop.InitializeMotionBlur(); Timetable.CreateTimetable(); Timetable.UpdateCustomTimetable(null, null); World.InitializeCameraRestriction(); if (Renderer.OptionBackfaceCulling) { GL.Enable(EnableCap.CullFace); } else { GL.Disable(EnableCap.CullFace); } Renderer.ReAddObjects(); // end HACK // //Reset the camera when switching between fullscreen and windowed mode //Otherwise, if the aspect ratio changes distortion will occur until the view is changed or the camera reset if (World.CameraMode == World.CameraViewMode.Interior | World.CameraMode == World.CameraViewMode.InteriorLookAhead) { World.CameraCurrentAlignment.Position = new OpenBveApi.Math.Vector3(0.0, 0.0, 0.0); } World.CameraCurrentAlignment.Yaw = 0.0; World.CameraCurrentAlignment.Pitch = 0.0; World.CameraCurrentAlignment.Roll = 0.0; if (World.CameraMode == World.CameraViewMode.Track) { TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition, true, false); } }
/// <summary>This method is called once the route and train data have been preprocessed, in order to physically setup the simulation</summary> private void SetupSimulation() { if (Loading.Cancel) { Close(); } Timetable.CreateTimetable(); //Check if any critical errors have occured during the route or train loading for (int i = 0; i < Interface.MessageCount; i++) { if (Interface.Messages[i].Type == Interface.MessageType.Critical) { MessageBox.Show("A critical error has occured:\n\n" + Interface.Messages[i].Text + "\n\nPlease inspect the error log file for further information.", "Load", MessageBoxButtons.OK, MessageBoxIcon.Hand); Close(); } } Renderer.InitializeLighting(); Game.LogRouteName = System.IO.Path.GetFileName(MainLoop.currentResult.RouteFile); Game.LogTrainName = System.IO.Path.GetFileName(MainLoop.currentResult.TrainFolder); Game.LogDateTime = DateTime.Now; if (Interface.CurrentOptions.LoadInAdvance) { Textures.LoadAllTextures(); } else { Textures.UnloadAllTextures(); } // camera ObjectManager.InitializeVisibility(); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -0.1, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.1, true, false); World.CameraTrackFollower.TriggerType = TrackManager.EventTriggerType.Camera; // starting time and track position Game.SecondsSinceMidnight = 0.0; Game.StartupTime = 0.0; int PlayerFirstStationIndex = -1; double PlayerFirstStationPosition = 0.0; int os = -1; bool f = false; for (int i = 0; i < Game.Stations.Length; i++) { if (!String.IsNullOrEmpty(Game.InitialStationName)) { if (Game.InitialStationName.ToLowerInvariant() == Game.Stations[i].Name.ToLowerInvariant()) { PlayerFirstStationIndex = i; } } if (Game.Stations[i].StopMode == Game.StationStopMode.AllStop | Game.Stations[i].StopMode == Game.StationStopMode.PlayerStop & Game.Stations[i].Stops.Length != 0) { if (f == false) { os = i; f = true; } } } if (PlayerFirstStationIndex == -1) { PlayerFirstStationIndex = os; } { int s = Game.GetStopIndex(PlayerFirstStationIndex, TrainManager.PlayerTrain.Cars.Length); if (s >= 0) { PlayerFirstStationPosition = Game.Stations[PlayerFirstStationIndex].Stops[s].TrackPosition; double TrainLength = 0.0; for (int c = 0; c < TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars.Length; c++) { TrainLength += TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars[c].Length; } for (int j = 0; j < Game.BufferTrackPositions.Length; j++) { if (PlayerFirstStationPosition > Game.BufferTrackPositions[j] && PlayerFirstStationPosition - TrainLength < Game.BufferTrackPositions[j]) { /* * HACK: The initial start position for the player train is stuck on a set of buffers * This means we have to make some one the fly adjustments to the first station stop position */ //Set the start position to be the buffer position plus the train length plus 1m PlayerFirstStationPosition = Game.BufferTrackPositions[j] + TrainLength + 1; //Update the station stop location if (s >= 0) { Game.Stations[PlayerFirstStationIndex].Stops[s].TrackPosition = PlayerFirstStationPosition; } else { Game.Stations[PlayerFirstStationIndex].DefaultTrackPosition = PlayerFirstStationPosition; } break; } } } else { PlayerFirstStationPosition = Game.Stations[PlayerFirstStationIndex].DefaultTrackPosition; } if (Game.InitialStationTime != -1) { Game.SecondsSinceMidnight = Game.InitialStationTime; Game.StartupTime = Game.InitialStationTime; } else { if (Game.Stations[PlayerFirstStationIndex].ArrivalTime < 0.0) { if (Game.Stations[PlayerFirstStationIndex].DepartureTime < 0.0) { Game.SecondsSinceMidnight = 0.0; Game.StartupTime = 0.0; } else { Game.SecondsSinceMidnight = Game.Stations[PlayerFirstStationIndex].DepartureTime - Game.Stations[PlayerFirstStationIndex].StopTime; Game.StartupTime = Game.Stations[PlayerFirstStationIndex].DepartureTime - Game.Stations[PlayerFirstStationIndex].StopTime; } } else { Game.SecondsSinceMidnight = Game.Stations[PlayerFirstStationIndex].ArrivalTime; Game.StartupTime = Game.Stations[PlayerFirstStationIndex].ArrivalTime; } } } int OtherFirstStationIndex = -1; double OtherFirstStationPosition = 0.0; double OtherFirstStationTime = 0.0; for (int i = 0; i < Game.Stations.Length; i++) { if (Game.Stations[i].StopMode == Game.StationStopMode.AllStop | Game.Stations[i].StopMode == Game.StationStopMode.PlayerPass & Game.Stations[i].Stops.Length != 0) { OtherFirstStationIndex = i; int s = Game.GetStopIndex(i, TrainManager.PlayerTrain.Cars.Length); if (s >= 0) { OtherFirstStationPosition = Game.Stations[i].Stops[s].TrackPosition; } else { OtherFirstStationPosition = Game.Stations[i].DefaultTrackPosition; } if (Game.Stations[i].ArrivalTime < 0.0) { if (Game.Stations[i].DepartureTime < 0.0) { OtherFirstStationTime = 0.0; } else { OtherFirstStationTime = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime; } } else { OtherFirstStationTime = Game.Stations[i].ArrivalTime; } break; } } if (Game.PrecedingTrainTimeDeltas.Length != 0) { OtherFirstStationTime -= Game.PrecedingTrainTimeDeltas[Game.PrecedingTrainTimeDeltas.Length - 1]; if (OtherFirstStationTime < Game.SecondsSinceMidnight) { Game.SecondsSinceMidnight = OtherFirstStationTime; } } // initialize trains for (int i = 0; i < TrainManager.Trains.Length; i++) { TrainManager.InitializeTrain(TrainManager.Trains[i]); int s = i == TrainManager.PlayerTrain.TrainIndex ? PlayerFirstStationIndex : OtherFirstStationIndex; if (s >= 0) { if (Game.Stations[s].OpenLeftDoors) { for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++) { TrainManager.Trains[i].Cars[j].Specs.AnticipatedLeftDoorsOpened = true; } } if (Game.Stations[s].OpenRightDoors) { for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++) { TrainManager.Trains[i].Cars[j].Specs.AnticipatedRightDoorsOpened = true; } } } if (Game.Sections.Length != 0) { Game.Sections[0].Enter(TrainManager.Trains[i]); } for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++) { double length = TrainManager.Trains[i].Cars[0].Length; TrainManager.MoveCar(TrainManager.Trains[i], j, -length, 0.01); TrainManager.MoveCar(TrainManager.Trains[i], j, length, 0.01); } } // score Game.CurrentScore.ArrivalStation = PlayerFirstStationIndex + 1; Game.CurrentScore.DepartureStation = PlayerFirstStationIndex; Game.CurrentScore.Maximum = 0; for (int i = 0; i < Game.Stations.Length; i++) { if (i != PlayerFirstStationIndex & Game.PlayerStopsAtStation(i)) { if (i == 0 || Game.Stations[i - 1].StationType != Game.StationType.ChangeEnds) { Game.CurrentScore.Maximum += Game.ScoreValueStationArrival; } } } if (Game.CurrentScore.Maximum <= 0) { Game.CurrentScore.Maximum = Game.ScoreValueStationArrival; } // signals if (Game.Sections.Length > 0) { Game.UpdateSection(Game.Sections.Length - 1); } // move train in position for (int i = 0; i < TrainManager.Trains.Length; i++) { double p; if (i == TrainManager.PlayerTrain.TrainIndex) { p = PlayerFirstStationPosition; } else if (TrainManager.Trains[i].State == TrainManager.TrainState.Bogus) { p = Game.BogusPretrainInstructions[0].TrackPosition; TrainManager.Trains[i].AI = new Game.BogusPretrainAI(TrainManager.Trains[i]); } else { p = OtherFirstStationPosition; } for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++) { TrainManager.MoveCar(TrainManager.Trains[i], j, p, 0.01); } } // timetable if (Timetable.DefaultTimetableDescription.Length == 0) { Timetable.DefaultTimetableDescription = Game.LogTrainName; } // initialize camera if (World.CameraRestriction == World.CameraRestrictionMode.NotAvailable) { World.CameraMode = World.CameraViewMode.InteriorLookAhead; } //Place the initial camera in the driver car TrainManager.UpdateCamera(TrainManager.PlayerTrain, TrainManager.PlayerTrain.DriverCar); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); World.CameraSavedInterior = new World.CameraAlignment(); World.CameraSavedExterior = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-2.5, 1.5, -15.0), 0.3, -0.2, 0.0, PlayerFirstStationPosition, 1.0); World.CameraSavedTrack = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-3.0, 2.5, 0.0), 0.3, 0.0, 0.0, TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition - 10.0, 1.0); // signalling sections for (int i = 0; i < TrainManager.Trains.Length; i++) { int s = TrainManager.Trains[i].CurrentSectionIndex; Game.Sections[s].Enter(TrainManager.Trains[i]); } if (Game.Sections.Length > 0) { Game.UpdateSection(Game.Sections.Length - 1); } // fast-forward until start time { Game.MinimalisticSimulation = true; const double w = 0.25; double u = Game.StartupTime - Game.SecondsSinceMidnight; if (u > 0) { while (true) { double v = u < w ? u : w; u -= v; Game.SecondsSinceMidnight += v; TrainManager.UpdateTrains(v); if (u <= 0.0) { break; } TotalTimeElapsedForSectionUpdate += v; if (TotalTimeElapsedForSectionUpdate >= 1.0) { if (Game.Sections.Length > 0) { Game.UpdateSection(Game.Sections.Length - 1); } TotalTimeElapsedForSectionUpdate = 0.0; } } } Game.MinimalisticSimulation = false; } // animated objects ObjectManager.UpdateAnimatedWorldObjects(0.0, true); TrainManager.UpdateTrainObjects(0.0, true); //HACK: This function calls a single update on all objects attached to the player's train // but ignores any specified damping so that all needles etc. are in the correct place // for the first frame, rather than spinning wildly to get to the starting point. TrainManager.UpdateCabObjects(TrainManager.PlayerTrain); // timetable if (TrainManager.PlayerTrain.Station >= 0) { Timetable.UpdateCustomTimetable(Game.Stations[TrainManager.PlayerTrain.Station].TimetableDaytimeTexture, Game.Stations[TrainManager.PlayerTrain.Station].TimetableNighttimeTexture); if (Timetable.CustomObjectsUsed != 0 & Timetable.CustomTimetableAvailable && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.AutoGenerated && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.None) { Timetable.CurrentTimetable = Timetable.TimetableState.Custom; } } //Create AI driver for the player train if specified via the commmand line if (Game.InitialAIDriver == true) { TrainManager.PlayerTrain.AI = new Game.SimpleHumanDriverAI(TrainManager.PlayerTrain); if (TrainManager.PlayerTrain.Plugin != null && !TrainManager.PlayerTrain.Plugin.SupportsAI) { Game.AddMessage(Interface.GetInterfaceString("notification_aiunable"), MessageManager.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.White, Game.SecondsSinceMidnight + 10.0, null); } } // warnings / errors if (Interface.MessageCount != 0) { int filesNotFound = 0; int errors = 0; int warnings = 0; for (int i = 0; i < Interface.MessageCount; i++) { if (Interface.Messages[i].FileNotFound) { filesNotFound++; } else if (Interface.Messages[i].Type == Interface.MessageType.Error) { errors++; } else if (Interface.Messages[i].Type == Interface.MessageType.Warning) { warnings++; } } string NotFound = null; string Messages = null; if (filesNotFound != 0) { NotFound = filesNotFound.ToString() + " file(s) not found"; Game.AddMessage(NotFound, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null); } if (errors != 0 & warnings != 0) { Messages = errors.ToString() + " error(s), " + warnings.ToString() + " warning(s)"; Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null); } else if (errors != 0) { Messages = errors.ToString() + " error(s)"; Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null); } else { Messages = warnings.ToString() + " warning(s)"; Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null); } Game.RouteInformation.FilesNotFound = NotFound; Game.RouteInformation.ErrorsAndWarnings = Messages; //Print the plugin error encountered (If any) for 10s //This must be done after the simulation has init, as otherwise the timeout doesn't work if (Loading.PluginError != null) { Game.AddMessage(Loading.PluginError, MessageManager.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0, null); Game.AddMessage(Interface.GetInterfaceString("errors_plugin_failure2"), MessageManager.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0, null); } } loadComplete = true; RenderRealTimeElapsed = 0.0; RenderTimeElapsed = 0.0; World.InitializeCameraRestriction(); }
/// <summary>Moves the camera to a point of interest</summary> /// <param name="Value">The value of the jump to perform: /// -1= Previous POI /// 0= Return to currently selected POI (From cab etc.) /// 1= Next POI</param> /// <param name="Relative">Whether the relative camera position should be retained</param> /// <returns>False if the previous / next POI would be outside those defined, true otherwise</returns> internal static bool ApplyPointOfInterest(int Value, bool Relative) { double t = 0.0; int j = -1; if (Relative) { // relative if (Value < 0) { // previous poi t = double.NegativeInfinity; for (int i = 0; i < PointsOfInterest.Length; i++) { if (PointsOfInterest[i].TrackPosition < World.CameraTrackFollower.TrackPosition) { if (PointsOfInterest[i].TrackPosition > t) { t = PointsOfInterest[i].TrackPosition; j = i; } } } } else if (Value > 0) { // next poi t = double.PositiveInfinity; for (int i = 0; i < PointsOfInterest.Length; i++) { if (PointsOfInterest[i].TrackPosition > World.CameraTrackFollower.TrackPosition) { if (PointsOfInterest[i].TrackPosition < t) { t = PointsOfInterest[i].TrackPosition; j = i; } } } } } else { // absolute j = Value >= 0 & Value < PointsOfInterest.Length ? Value : -1; } // process poi if (j < 0) { return(false); } TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, t, true, false); World.CameraCurrentAlignment.Position = PointsOfInterest[j].TrackOffset; World.CameraCurrentAlignment.Yaw = PointsOfInterest[j].TrackYaw; World.CameraCurrentAlignment.Pitch = PointsOfInterest[j].TrackPitch; World.CameraCurrentAlignment.Roll = PointsOfInterest[j].TrackRoll; World.CameraCurrentAlignment.TrackPosition = t; World.UpdateAbsoluteCamera(0.0); if (PointsOfInterest[j].Text != null) { double n = 3.0 + 0.5 * Math.Sqrt((double)PointsOfInterest[j].Text.Length); Game.AddMessage(PointsOfInterest[j].Text, MessageManager.MessageDependency.PointOfInterest, Interface.GameMode.Expert, MessageColor.White, Game.SecondsSinceMidnight + n, null); } return(true); }
// update absolute camera internal static void UpdateAbsoluteCamera(double TimeElapsed) { // zoom double zm = World.CameraCurrentAlignment.Zoom; AdjustAlignment(ref World.CameraCurrentAlignment.Zoom, World.CameraAlignmentDirection.Zoom, ref World.CameraAlignmentSpeed.Zoom, TimeElapsed, World.CameraAlignmentSpeed.Zoom != 0.0); if (zm != World.CameraCurrentAlignment.Zoom) { ApplyZoom(); } // current alignment AdjustAlignment(ref World.CameraCurrentAlignment.Position.X, World.CameraAlignmentDirection.Position.X, ref World.CameraAlignmentSpeed.Position.X, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Position.Y, World.CameraAlignmentDirection.Position.Y, ref World.CameraAlignmentSpeed.Position.Y, TimeElapsed); bool q = World.CameraAlignmentSpeed.Yaw != 0.0 | World.CameraAlignmentSpeed.Pitch != 0.0 | World.CameraAlignmentSpeed.Roll != 0.0; AdjustAlignment(ref World.CameraCurrentAlignment.Yaw, World.CameraAlignmentDirection.Yaw, ref World.CameraAlignmentSpeed.Yaw, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Pitch, World.CameraAlignmentDirection.Pitch, ref World.CameraAlignmentSpeed.Pitch, TimeElapsed); AdjustAlignment(ref World.CameraCurrentAlignment.Roll, World.CameraAlignmentDirection.Roll, ref World.CameraAlignmentSpeed.Roll, TimeElapsed); double tr = World.CameraCurrentAlignment.TrackPosition; AdjustAlignment(ref World.CameraCurrentAlignment.TrackPosition, World.CameraAlignmentDirection.TrackPosition, ref World.CameraAlignmentSpeed.TrackPosition, TimeElapsed); if (tr != World.CameraCurrentAlignment.TrackPosition) { TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, World.CameraCurrentAlignment.TrackPosition, true, false); q = true; } if (q) { UpdateViewingDistances(); } double dx = World.CameraTrackFollower.WorldDirection.X; double dy = World.CameraTrackFollower.WorldDirection.Y; double dz = World.CameraTrackFollower.WorldDirection.Z; double ux = World.CameraTrackFollower.WorldUp.X; double uy = World.CameraTrackFollower.WorldUp.Y; double uz = World.CameraTrackFollower.WorldUp.Z; double sx = World.CameraTrackFollower.WorldSide.X; double sy = World.CameraTrackFollower.WorldSide.Y; double sz = World.CameraTrackFollower.WorldSide.Z; double tx = World.CameraCurrentAlignment.Position.X; double ty = World.CameraCurrentAlignment.Position.Y; double tz = World.CameraCurrentAlignment.Position.Z; double dx2 = dx, dy2 = dy, dz2 = dz; double ux2 = ux, uy2 = uy, uz2 = uz; double cx = World.CameraTrackFollower.WorldPosition.X + sx * tx + ux2 * ty + dx2 * tz; double cy = World.CameraTrackFollower.WorldPosition.Y + sy * tx + uy2 * ty + dy2 * tz; double cz = World.CameraTrackFollower.WorldPosition.Z + sz * tx + uz2 * ty + dz2 * tz; if (World.CameraCurrentAlignment.Yaw != 0.0) { double cosa = Math.Cos(World.CameraCurrentAlignment.Yaw); double sina = Math.Sin(World.CameraCurrentAlignment.Yaw); World.Rotate(ref dx, ref dy, ref dz, ux, uy, uz, cosa, sina); World.Rotate(ref sx, ref sy, ref sz, ux, uy, uz, cosa, sina); } double p = World.CameraCurrentAlignment.Pitch; if (p != 0.0) { double cosa = Math.Cos(-p); double sina = Math.Sin(-p); World.Rotate(ref dx, ref dy, ref dz, sx, sy, sz, cosa, sina); World.Rotate(ref ux, ref uy, ref uz, sx, sy, sz, cosa, sina); } if (World.CameraCurrentAlignment.Roll != 0.0) { double cosa = Math.Cos(-World.CameraCurrentAlignment.Roll); double sina = Math.Sin(-World.CameraCurrentAlignment.Roll); World.Rotate(ref ux, ref uy, ref uz, dx, dy, dz, cosa, sina); World.Rotate(ref sx, ref sy, ref sz, dx, dy, dz, cosa, sina); } AbsoluteCameraPosition = new Vector3(cx, cy, cz); AbsoluteCameraDirection = new Vector3(dx, dy, dz); AbsoluteCameraUp = new Vector3(ux, uy, uz); AbsoluteCameraSide = new Vector3(sx, sy, sz); }
private static void LoadEverythingThreaded() { string RailwayFolder = GetRailwayFolder(CurrentRouteFile); string ObjectFolder = OpenBveApi.Path.CombineDirectory(RailwayFolder, "Object"); string SoundFolder = OpenBveApi.Path.CombineDirectory(RailwayFolder, "Sound"); // string CompatibilityFolder = OpenBveApi.Path.CombineDirectory(Application.StartupPath, "Compatibility"); // reset Game.Reset(); Game.MinimalisticSimulation = true; // screen World.CameraTrackFollower = new TrackManager.TrackFollower(); World.CameraTrackFollower.Train = null; World.CameraTrackFollower.CarIndex = -1; World.CameraMode = CameraViewMode.Interior; // load route bool IsRW = string.Equals(System.IO.Path.GetExtension(CurrentRouteFile), ".rw", StringComparison.OrdinalIgnoreCase); CsvRwRouteParser.ParseRoute(CurrentRouteFile, IsRW, CurrentRouteEncoding, Application.StartupPath, ObjectFolder, SoundFolder, false); System.Threading.Thread.Sleep(1); if (Cancel) { return; } Game.CalculateSeaLevelConstants(); RouteProgress = 1.0; // camera ObjectManager.InitializeVisibility(); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.1, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -0.1, true, false); World.CameraTrackFollower.TriggerType = TrackManager.EventTriggerType.Camera; // default starting time Game.SecondsSinceMidnight = 0.0; Game.StartupTime = 0.0; // finished created objects System.Threading.Thread.Sleep(1); if (Cancel) { return; } ObjectManager.FinishCreatingObjects(); // signals System.Threading.Thread.Sleep(1); if (Cancel) { return; } if (Game.Sections.Length > 0) { Game.UpdateSection(Game.Sections.Length - 1); } // starting track position System.Threading.Thread.Sleep(1); if (Cancel) { return; } // int FirstStationIndex = -1; double FirstStationPosition = 0.0; for (int i = 0; i < Game.Stations.Length; i++) { if (Game.Stations[i].Stops.Length != 0) { // FirstStationIndex = i; FirstStationPosition = Game.Stations[i].Stops[Game.Stations[i].Stops.Length - 1].TrackPosition; if (Game.Stations[i].ArrivalTime < 0.0) { if (Game.Stations[i].DepartureTime < 0.0) { Game.SecondsSinceMidnight = 0.0; } else { Game.SecondsSinceMidnight = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime; } } else { Game.SecondsSinceMidnight = Game.Stations[i].ArrivalTime; } Game.StartupTime = Game.SecondsSinceMidnight; break; } } // initialize camera TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, FirstStationPosition, true, false); World.CameraCurrentAlignment = new World.CameraAlignment(new Vector3(0.0, 2.5, 0.0), 0.0, 0.0, 0.0, FirstStationPosition, 1.0); World.UpdateAbsoluteCamera(0.0); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); }
private void button1_Click(object sender, EventArgs e) { TextureManager.InterpolationMode previousInterpolationMode = Interface.CurrentOptions.Interpolation; int previousAntialasingLevel = Interface.CurrentOptions.AntialiasingLevel; int previousAnsiotropicLevel = Interface.CurrentOptions.AnisotropicFilteringLevel; //Interpolation mode switch (InterpolationMode.SelectedIndex) { case 0: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.NearestNeighbor; break; case 1: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.Bilinear; break; case 2: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.NearestNeighborMipmapped; break; case 3: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.BilinearMipmapped; break; case 4: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.TrilinearMipmapped; break; case 5: Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering; break; } //Ansiotropic filtering level Interface.CurrentOptions.AnisotropicFilteringLevel = (int)AnsiotropicLevel.Value; //Antialiasing level Interface.CurrentOptions.AntialiasingLevel = (int)AntialiasingLevel.Value; if (Interface.CurrentOptions.AntialiasingLevel != previousAntialasingLevel) { Program.currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntialiasingLevel); } //Transparency quality switch (TransparencyQuality.SelectedIndex) { case 0: Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Sharp; break; default: Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Smooth; break; } //Set width and height if (Renderer.ScreenWidth != width.Value || Renderer.ScreenHeight != height.Value) { Renderer.ScreenWidth = (int)width.Value; Renderer.ScreenHeight = (int)height.Value; Program.currentGameWindow.Width = (int)width.Value; Program.currentGameWindow.Height = (int)height.Value; Program.UpdateViewport(); } //Check if interpolation mode or ansiotropic filtering level has changed, and trigger a reload if (previousInterpolationMode != Interface.CurrentOptions.Interpolation || previousAnsiotropicLevel != Interface.CurrentOptions.AnisotropicFilteringLevel) { if (Program.CurrentRoute != null) { Program.CurrentlyLoading = true; Renderer.RenderScene(0.0); Program.currentGameWindow.SwapBuffers(); World.CameraAlignment a = World.CameraCurrentAlignment; if (Program.LoadRoute()) { World.CameraCurrentAlignment = a; TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false); World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); ObjectManager.UpdateVisibility(a.TrackPosition, true); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); } Program.CurrentlyLoading = false; } } Renderer.TransparentColorDepthSorting = Interface.CurrentOptions.TransparencyMode == Renderer.TransparencyMode.Smooth & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.NearestNeighbor & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.Bilinear; Options.SaveOptions(); this.Dispose(); }
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) { double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0); switch (e.Key) { case Key.ShiftLeft: case Key.ShiftRight: ShiftPressed = true; break; case Key.ControlLeft: case Key.ControlRight: ControlPressed = true; break; case Key.LAlt: case Key.RAlt: AltPressed = true; break; case Key.F5: if (CurrentRoute != null) { CurrentlyLoading = true; Renderer.RenderScene(0.0); currentGameWindow.SwapBuffers(); World.CameraAlignment a = World.CameraCurrentAlignment; if (LoadRoute()) { World.CameraCurrentAlignment = a; TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false); World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); ObjectManager.UpdateVisibility(a.TrackPosition, true); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); } CurrentlyLoading = false; } break; case Key.F7: OpenFileDialog Dialog = new OpenFileDialog(); Dialog.CheckFileExists = true; Dialog.Filter = "CSV/RW files|*.csv;*.rw|All files|*"; if (Dialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); CurrentlyLoading = true; Renderer.RenderScene(0.0); Program.currentGameWindow.SwapBuffers(); CurrentRoute = Dialog.FileName; LoadRoute(); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); CurrentlyLoading = false; UpdateCaption(); } break; case Key.F8: formOptions.ShowOptions(); Application.DoEvents(); break; case Key.F9: if (Interface.MessageCount != 0) { formMessages.ShowMessages(); Application.DoEvents(); } break; case Key.F10: Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay; break; case Key.A: case Key.Keypad4: World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.D: case Key.Keypad6: World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad2: World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad8: World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.W: case Key.Keypad9: World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.S: case Key.Keypad3: World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Left: World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Right: World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Up: World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Down: World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadDivide: World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadMultiply: World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad0: World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadPeriod: World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad1: Game.ApplyPointOfInterest(-1, true); CpuReducedMode = false; break; case Key.Keypad7: Game.ApplyPointOfInterest(1, true); CpuReducedMode = false; break; case Key.PageUp: JumpToStation(1); CpuReducedMode = false; break; case Key.PageDown: JumpToStation(-1); CpuReducedMode = false; break; case Key.Keypad5: World.CameraCurrentAlignment.Yaw = 0.0; World.CameraCurrentAlignment.Pitch = 0.0; World.CameraCurrentAlignment.Roll = 0.0; World.CameraCurrentAlignment.Position = new World.Vector3D(0.0, 2.5, 0.0); World.CameraCurrentAlignment.Zoom = 0.0; World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); World.VerticalViewingAngle = World.OriginalVerticalViewingAngle; UpdateViewport(); World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); CpuReducedMode = false; break; case Key.F: Renderer.OptionWireframe = !Renderer.OptionWireframe; CpuReducedMode = false; if (Renderer.OptionWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } break; case Key.N: Renderer.OptionNormals = !Renderer.OptionNormals; CpuReducedMode = false; break; case Key.E: Renderer.OptionEvents = !Renderer.OptionEvents; CpuReducedMode = false; break; case Key.C: CpuAutomaticMode = !CpuAutomaticMode; CpuReducedMode = false; break; case Key.I: Renderer.OptionInterface = !Renderer.OptionInterface; CpuReducedMode = false; break; case Key.M: SoundManager.Mute = !SoundManager.Mute; break; case Key.Plus: case Key.KeypadPlus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "+"; CpuReducedMode = false; } break; case Key.Minus: case Key.KeypadMinus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "-"; CpuReducedMode = false; } break; case Key.Number0: case Key.Number1: case Key.Number2: case Key.Number3: case Key.Number4: case Key.Number5: case Key.Number6: case Key.Number7: case Key.Number8: case Key.Number9: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = string.Empty; } JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0); CpuReducedMode = false; break; case Key.Period: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "0."; } else if (JumpToPositionValue.IndexOf('.') == -1) { JumpToPositionValue += "."; } CpuReducedMode = false; break; case Key.BackSpace: if (JumpToPositionEnabled && JumpToPositionValue.Length != 0) { JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1); CpuReducedMode = false; } break; case Key.Enter: if (JumpToPositionEnabled) { if (JumpToPositionValue.Length != 0) { int direction; if (JumpToPositionValue[0] == '-') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = -1; } else if (JumpToPositionValue[0] == '+') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = 1; } else { direction = 0; } double value; if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { if (direction != 0) { value = World.CameraTrackFollower.TrackPosition + (double)direction * value; } TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false); World.CameraCurrentAlignment.TrackPosition = value; World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); } } JumpToPositionEnabled = false; CpuReducedMode = false; } break; case Key.Escape: JumpToPositionEnabled = false; CpuReducedMode = false; break; } }