private void UpdateCamera() { Vector3 direction = Vector3.Zero; //if (Math.Abs(mouseDelta.X) > Math.Abs(mouseDelta.Y)) // direction.X = (dx > 0) ? 0.1f : -0.1f; //else // direction.Y = (dy > 0) ? 0.1f : -0.1f; direction = new Vector3(mouseDelta); float xAngle = (direction.X); float yAngle = (direction.Y); camera.ApplyYaw(xAngle); camera.ApplyPitch(yAngle); camera.ApplyRotation(); }
private void updateCamera() { if (NavigationInfo.NavigationType == NavigationType.Examine) { // MOUSE ORBIT/PAN NAVIGATION if (mouseDragging) { if (ispanning) { ActiveCamera.PanXY(mouseDelta.X * mouseScale, mouseDelta.Y * mouseScale); //ActiveCamera.ScaleXY(mouseDelta.X, mouseDelta.Y); } else if (iszooming) { // orbits using shape's centerOfRotation ActiveCamera.OrbitObjectsXY(mouseDelta.X / 0.5f, -1 * mouseDelta.Y / 0.5f); } } } if (NavigationInfo.NavigationType == NavigationType.Fly || NavigationInfo.NavigationType == NavigationType.Walk) { // TEST new camera walk/fly implementation: Vector3 direction = Vector3.Zero; //if (Math.Abs(mouseDelta.X) > Math.Abs(mouseDelta.Y)) // direction.X = (dx > 0) ? 0.1f : -0.1f; //else // direction.Y = (dy > 0) ? 0.1f : -0.1f; direction = new Vector3(mouseDelta); float xAngle = (direction.X); float yAngle = (direction.Y); ActiveCamera.ApplyYaw(xAngle); ActiveCamera.ApplyPitch(yAngle); ActiveCamera.ApplyRotation(); } }
private void ApplyKeyBindings(FrameEventArgs e) { Vector3 direction = Vector3.Zero; bool rotated = false; bool translated = false; slowFlySpeed = Keyboard[Key.AltLeft]; fastFlySpeed = Keyboard[Key.ShiftLeft]; movementSpeed = fastFlySpeed ? 10.0f : 0.3f; movementSpeed = slowFlySpeed ? 0.01f : movementSpeed; // Calibrator (for translation debugging) if (Keyboard[Key.Number1]) { ActiveCamera.calibTrans.X += ActiveCamera.calibSpeed.X; } if (Keyboard[Key.Number2]) { ActiveCamera.calibTrans.X -= ActiveCamera.calibSpeed.X; } if (Keyboard[Key.Number3]) { ActiveCamera.calibTrans.Y += ActiveCamera.calibSpeed.Y; } if (Keyboard[Key.Number4]) { ActiveCamera.calibTrans.Y -= ActiveCamera.calibSpeed.Y; } if (Keyboard[Key.Number5]) { ActiveCamera.calibTrans.Z += ActiveCamera.calibSpeed.Z; } if (Keyboard[Key.Number6]) { ActiveCamera.calibTrans.Z -= ActiveCamera.calibSpeed.Z; } // Calibrator (for orientation debugging) if (Keyboard[Key.Number6]) { ActiveCamera.calibOrient.X += ActiveCamera.calibSpeed.X; } if (Keyboard[Key.Number7]) { ActiveCamera.calibOrient.X -= ActiveCamera.calibSpeed.X; } if (Keyboard[Key.Number8]) { ActiveCamera.calibOrient.Y += ActiveCamera.calibSpeed.Y; } if (Keyboard[Key.Number9]) { ActiveCamera.calibOrient.Y -= ActiveCamera.calibSpeed.Y; } if (Keyboard[Key.Minus]) { ActiveCamera.calibOrient.Z += ActiveCamera.calibSpeed.Z; } if (Keyboard[Key.Plus]) { ActiveCamera.calibOrient.Z -= ActiveCamera.calibSpeed.Z; } if (Keyboard[Key.Escape] || Keyboard[Key.Q]) { // QUIT APPLICATION if (WindowState == WindowState.Fullscreen) { WindowState = WindowState.Normal; } //X3DProgram.Quit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); // Fast ! } if (Keyboard[Key.R]) { // RESET CAMERA POSITION+ORIENTATION ActiveCamera.Reset(); } if (NavigationInfo.NavigationType != NavigationType.Examine) { if (Keyboard[Key.T]) { ActiveCamera.Fly(playerDirectionMagnitude * movementSpeed); translated = true; } if (Keyboard[Key.G]) { ActiveCamera.Fly(-playerDirectionMagnitude * movementSpeed); translated = true; } if (Keyboard[Key.W]) { ActiveCamera.Walk(playerDirectionMagnitude * movementSpeed); translated = true; } if (Keyboard[Key.S]) { ActiveCamera.Walk(-playerDirectionMagnitude * movementSpeed); translated = true; } if (Keyboard[Key.A]) { ActiveCamera.Strafe(playerDirectionMagnitude * movementSpeed); translated = true; } if (Keyboard[Key.D]) { ActiveCamera.Strafe(-playerDirectionMagnitude * movementSpeed); translated = true; } #region G.3 Emulate pointing device Key Bindings if (Keyboard[Key.Left]) { ActiveCamera.ApplyYaw(-playerDirectionMagnitude * movementSpeed); rotated = true; } if (Keyboard[Key.Right]) { ActiveCamera.ApplyYaw(playerDirectionMagnitude * movementSpeed); rotated = true; } if (Keyboard[Key.Up]) { ActiveCamera.ApplyPitch(-playerDirectionMagnitude * movementSpeed); rotated = true; } if (Keyboard[Key.Down]) { ActiveCamera.ApplyPitch(playerDirectionMagnitude * movementSpeed); rotated = true; } if (Keyboard[Key.Number0]) { ActiveCamera.ApplyRoll(-0.1f); rotated = true; } if (Keyboard[Key.Number9]) { ActiveCamera.ApplyRoll(0.1f); rotated = true; } #endregion } if (rotated) { ActiveCamera.ApplyRotation(); } }