/// <summary> /// intern helper to update view angles by mouse /// </summary> protected void UpdateThetaPhiFromMouse(float passedTimeSinceLastFrame, DPFCanvas canvas) { MouseState stateMouse = Mouse.GetCurrentState(); KeyboardState stateKeyboard = Keyboard.GetCurrentState(); // Left button pressed. Perform plane intersection. if (stateMouse.IsPressed(0)) { System.Windows.Point mouse = System.Windows.Input.Mouse.GetPosition(canvas); _releaseMouseRelative.X = (float)((2 * mouse.X - canvas.ActualWidth) / canvas.ActualWidth); _releaseMouseRelative.Y = (float)((2 * mouse.Y - canvas.ActualHeight) / canvas.ActualHeight); //Console.WriteLine(_releaseMouseRelative.ToString()); if (_setMouseRelative == null) { _setMouseRelative = _releaseMouseRelative; } RedSea.Singleton.UpdateSelection(); } // Mouse wheel pressed. Move camera. else if (_setMouseRelative != null) { RedSea.Singleton.EndSelection(); _setMouseRelative = null; } if (stateMouse.IsPressed(2)) { // mouse movement double deltaX = Cursor.Position.X - lastMouseX; double deltaY = Cursor.Position.Y - lastMouseY; phi -= deltaX * rotationSpeed; theta -= deltaY * rotationSpeed; } else { //theta += (stateKeyboard.IsPressed(Key.UpArrow) ? rotationSpeed * passedTimeSinceLastFrame * 0.3f : 0.0f); //theta -= (stateKeyboard.IsPressed(Key.DownArrow) ? rotationSpeed * passedTimeSinceLastFrame * 0.3f : 0.0f); //phi -= (stateKeyboard.IsPressed(Key.RightArrow) ? rotationSpeed * passedTimeSinceLastFrame * 0.3f : 0.0f); //phi += (stateKeyboard.IsPressed(Key.LeftArrow) ? rotationSpeed * passedTimeSinceLastFrame * 0.3f : 0.0f); } lastMouseX = Cursor.Position.X; lastMouseY = Cursor.Position.Y; }
/// <summary> /// Updates the Camera /// </summary> public void Update(float passedTimeSinceLastFrame, Device device, DPFCanvas canvas) { KeyboardState state = Keyboard.GetCurrentState(); if (state.IsPressed(Key.R)) { ResetCamera(); } if (state.IsPressed(Key.C)) { RedSea.Singleton.WPFWindow.Screenshot(RedSea.Singleton.SnapFileName + "Snape_" + RedSea.Singleton.Filename + ".png"); } if (state.IsPressed(Key.F12)) { for (int t = 0; t <= 80; t += 10) { RedSea.Singleton.WPFWindow.SetSliceTimeMain(t); } } if (state.IsPressed(Key.F11)) { RedSea.Singleton.WPFWindow.SetDiffusionMeasure((int)RedSea.DiffusionMeasure.Direction); RedSea.Singleton.WPFWindow.SetDiffusionMeasure((int)RedSea.DiffusionMeasure.Neighbor); RedSea.Singleton.WPFWindow.SetDiffusionMeasure((int)RedSea.DiffusionMeasure.FTLE); } // Map mouse movement to angles. UpdateThetaPhiFromMouse(passedTimeSinceLastFrame, canvas); // Compute view direction from angles. viewDirection = new Vector3((float)(System.Math.Cos(phi) * System.Math.Sin(theta)), (float)(System.Math.Cos(theta)), (float)(System.Math.Sin(phi) * System.Math.Sin(theta))); // Compute up vector. float theta2 = (float)theta + (float)System.Math.PI / 2.0f; upVec = new Vector3((float)(System.Math.Cos(phi) * System.Math.Sin(theta2)), (float)(System.Math.Cos(theta2)), (float)(System.Math.Sin(phi) * System.Math.Sin(theta2))); rightVec = Vector3.Cross(upVec, viewDirection); // Update. // Forward movement. float forward = (state.IsPressed(Key.W) ? 1.0f : 0.0f) - (state.IsPressed(Key.S) ? 1.0f : 0.0f); position += forward * forwardSpeed * viewDirection; // Side movement. float side = (state.IsPressed(Key.D) ? 1.0f : 0.0f) - (state.IsPressed(Key.A) ? 1.0f : 0.0f); position += side * sideSpeed * rightVec; // Upward movement. float up = state.IsPressed(Key.Space) ? 1.0f : 0.0f - (state.IsPressed(Key.LeftAlt) ? 1.0f : 0.0f); position += up * upSpeed * upVec; // Compute view matrix. View = Matrix.LookAtLH(position, position + viewDirection, upVec); UpdateResources(device); }
public void SetCanvas(DPFCanvas canv) { _canvas = canv; }