private void BuildScene02() { var uri = new Uri("ziyang.ciml", UriKind.Relative); var map = new TongJi.Gis.Map(XDocument.Load(Application.GetResourceStream(uri).Stream).Root); var city = new TongJi.City.Analysis3D.CityScene(map); BuildScene(city.Meshes); var pos = ToVector3(city.Meshes[0].Bounds.min); pos.Z = 500; Camera = new OneAxisLevelFlyCamera(pos, Vector3.UnitX + Vector3.UnitY, GraphicsDevice); //Camera = new ArcBallCamera(ToVector3(city.Meshes[0].Bounds.min), ToVector3(city.Meshes[0].Bounds.min), -MathHelper.Pi * 100, MathHelper.Pi * 100, 1, 1000, GraphicsDevice); }
void UpdateCamera() { float c1 = 1; float c2 = 30; // Get the new keyboard and mouse state MouseState mouseState = Mouse.GetState(); KeyboardState keyState = Microsoft.Xna.Framework.Input.Keyboard.GetState(); // Determine how much the camera should turn float deltaX = (float)lastMouseState.X - (float)mouseState.X; float deltaY = (float)lastMouseState.Y - (float)mouseState.Y; float vX = 0; float vY = 0; if (mouseState.X > 0.9 * width) { vX = -1; } else if (mouseState.X < 0.1 * width) { vX = 1; } if (mouseState.Y > 0.9 * height) { vY = -1; } else if (mouseState.Y < 0.1 * height) { vY = 1; } //WriteLine(deltaX); //WriteLine(deltaY); if (scene.Camera is FreeFlyCamera) { FreeFlyCamera camera = scene.Camera as FreeFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .0005f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } else if (scene.Camera is OneAxisLevelFlyCamera) { OneAxisLevelFlyCamera camera = scene.Camera as OneAxisLevelFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .0005f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } else if (scene.Camera is TwoAxesLevelFlyCamera) { TwoAxesLevelFlyCamera camera = scene.Camera as TwoAxesLevelFlyCamera; // Rotate the camera camera.RotateLeftRight((c1 * deltaX + c2 * vX) * .0005f); camera.RotateUpDown(-(c1 * deltaY + c2 * vY) * .05f); // Determine in which direction to move the camera if (keyState.IsKeyDown(Key.W)) { camera.Move(1, 0); } if (keyState.IsKeyDown(Key.S)) { camera.Move(-1, 0); } if (keyState.IsKeyDown(Key.A)) { camera.Move(0, 1); } if (keyState.IsKeyDown(Key.D)) { camera.Move(0, -1); } // Update the camera camera.Update(); } // Update the mouse state lastMouseState = mouseState; }