protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } MouseInteraction.Update(); CurrentScene.Update(); base.Update(gameTime); }
protected override void Update(GameTime gameTime) { _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds; ClickTimer += gameTime.ElapsedGameTime.TotalMilliseconds; if (_elapsed_time > 1000.0f) { fps = _total_frames; _total_frames = 0; _elapsed_time = 0.0f; SunCollisionActive = true; } InputManager.Update(); MouseInteraction.Update(); if (Mouse.GetState().LeftButton == ButtonState.Released) { LeftButtonPressed = false; } if (Mouse.GetState().RightButton == ButtonState.Pressed) { if (!RightButtonPressed) { Observer.Camera.MouseSensity = .00025f; MousePositionSpace = MouseInteraction.GetXZAtY(MouseInteraction.GetRay(GraphicsDevice, Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1f, 1000.0f), Observer.Camera.ViewMatrix), Observer.Camera.CameraPosition.Y); MousePositionSpace = new Vector3(MousePositionSpace.X - CelestialBody.GLOBALX, MousePositionSpace.Y - CelestialBody.GLOBALY, MousePositionSpace.Z - CelestialBody.GLOBALZ); RightButtonPressed = true; } Observer.Camera.SetLookAt(MousePositionSpace, Zoom); } if (Mouse.GetState().RightButton == ButtonState.Released) { Observer.Camera.MouseSensity = .0008f; RightButtonPressed = false; } if (MouseInteraction.IsScrollingUp) { Zoom -= 5.5f; Observer.Camera.Move(new Vector3(0, 0, -5.5f)); } if (MouseInteraction.IsScrollingDown) { Zoom += 5.5f; Observer.Camera.Move(new Vector3(0, 0, 5.5f)); } Observer.Camera.Update(); CelestialBody.GLOBALX = Observer.Camera.CameraPosition.X; CelestialBody.GLOBALY = Observer.Camera.CameraPosition.Y; CelestialBody.GLOBALZ = Observer.Camera.CameraPosition.Z; for (int i = 0; i < CelestialBodies.Count; i++) { CelestialBodies[i].Update(gameTime); if (SunCollisionActive) { if (CelestialBodies[i].Name != "Sun") { if (CelestialBodies[i].BoundingBox.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox)) { CelestialBodies.RemoveAt(i); } } } } if (Mouse.GetState().LeftButton == ButtonState.Pressed) { if (!LeftButtonPressed) { LeftButtonPressed = true; Ray r = ToolKit.CalculateRay(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Observer.Camera.ViewMatrix, Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.01f, 150000.0f), GraphicsDevice.Viewport); if (ClickTimer < TimerDelay) { for (int i = 0; i < CelestialBodies.Count; i++) { if (r.Intersects(CelestialBodies[i].BoundingBox) > 1) { Observer.Camera.Flush(); UI.SetPlanet(CelestialBodies[i]); CelestialBodies[i].Follow(); break; } } } else { for (int i = 0; i < CelestialBodies.Count; i++) { if (r.Intersects(CelestialBodies[i].BoundingBox) > 1) { UI.SetPlanet(CelestialBodies[i]); CelestialBodies[i].SetFocus(); break; } } } ClickTimer = 0; } } UI.UpdateQR(gameTime); CelestialBodies = CelestialBodies.OrderByDescending(p => p.DistanceToObserver).ToList(); }