private void ProcessKeyboard(float timeDifference) { Vector3 moveVector = new Vector3(0, 0, 0); KeyboardState keyState = Keyboard.GetState(); Func <Keys, bool> KeyDown = key => keyState.IsKeyDown(key); Func <Keys, bool> KeyPressed = key => keyState.IsKeyDown(key) && !oldKeyboardState.IsKeyDown(key); // Перемещение камеры if (KeyDown(Keys.Up)) { moveVector += Vector3.Forward; } if (KeyDown(Keys.Down)) { moveVector += Vector3.Backward; } if (KeyDown(Keys.Right)) { moveVector += Vector3.Right; } if (KeyDown(Keys.Left)) { moveVector += Vector3.Left; } if (KeyDown(Keys.PageUp)) { moveVector += Vector3.Up; } if (KeyDown(Keys.PageDown)) { moveVector += Vector3.Down; } // Ускоренное перемещениеи камеры bool fast = keyState.IsKeyDown(Keys.LeftShift) || keyState.IsKeyDown(Keys.RightShift); if (KeyPressed(Keys.Escape)) { usingMouse = !usingMouse; if (usingMouse) { Mouse.SetPosition(Device.Viewport.Width / 2, Device.Viewport.Height / 2); } } if (KeyPressed(Keys.W)) { wireframeMode = !wireframeMode; } oldKeyboardState = keyState; camera.UpdatePosition(moveVector * timeDifference * (fast? fastMoveSpeed : slowMoveSpeed)); }
public void Initialize() { camera = new Camera(); camera.UpdatePosition(new Vector3(0, 100, 0)); textInfoPanel = new InfoPanelFor3Dview(Content); textInfoPanel.Camera = camera; AddSubRenderer(textInfoPanel); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Device.Viewport.AspectRatio, Config.Instance.Rendering.NearClippingDistance, Config.Instance.Rendering.FarClippingDistance); effect = Content.Load <Effect>("effect"); waterRenderer = new WaterRenderer(Content, SceneContent, camera); skyRenderer = new SkyRenderer(Content, camera); secondDepthBuffer = new DepthStencilBuffer(Device, Device.PresentationParameters.BackBufferWidth, Device.PresentationParameters.BackBufferHeight, Device.DepthStencilBuffer.Format); Mouse.SetPosition(Device.Viewport.Width / 2, Device.Viewport.Height / 2); originalMouseState = Mouse.GetState(); }
public void Initialize() { camera = new Camera(); camera.UpdatePosition(new Vector3(0, 100, 0)); textInfoPanel = new InfoPanelFor3Dview(Content); textInfoPanel.Camera = camera; AddSubRenderer(textInfoPanel); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Device.Viewport.AspectRatio, Config.Instance.Rendering.NearClippingDistance, Config.Instance.Rendering.FarClippingDistance); effect = Content.Load<Effect>("effect"); waterRenderer = new WaterRenderer(Content, SceneContent, camera); skyRenderer = new SkyRenderer(Content, camera); secondDepthBuffer = new DepthStencilBuffer(Device, Device.PresentationParameters.BackBufferWidth, Device.PresentationParameters.BackBufferHeight, Device.DepthStencilBuffer.Format); Mouse.SetPosition(Device.Viewport.Width / 2, Device.Viewport.Height / 2); originalMouseState = Mouse.GetState(); }