private void DisposeDXViewportView() { if (_mainDXViewportView == null) { return; } if (_camera1 != null) { _camera1.StopRotation(); RootGrid.Children.Remove(_camera1); _camera1 = null; } if (_mouseCameraController != null) { RootGrid.Children.Remove(_mouseCameraController); _mouseCameraController = null; } _mainDXViewportView.SceneRendered -= MainDxViewportViewOnSceneRendered; _mainDXViewportView.Dispose(); _mainDXViewportView = null; }
public BackgroundRenderingSample() { InitializeComponent(); if (!IsRenderingInBackgroundThread) // In case we are running BackgroundDXEngineRenderer on the Main UI thread, mark that on the GUI { BGRenderingTitleTextBlock.TextDecorations.Add(TextDecorations.Strikethrough); } // We need to wait until this sample is loaded, otherwise we do not get the correct dpiScale values. this.Loaded += delegate(object sender, RoutedEventArgs args) { // Get dpi scale setting and store that for later BackgroundDXEngineRenderer.GetActualDpiScaleValues(this, out _dpiScaleX, out _dpiScaleY); // Create D3DHost control that will host the 3D rendered scene CreateD3DHost(); // Create MouseCameraController that will allow user to rotate the camera CreateMouseCameraController(); }; // Subscribe to rendering to collect Main UI thread FPS statistics CompositionTarget.Rendering += UpdateMainUIThreadFPS; // We also count mouse move events to see when the UI thread is not responsing well this.PreviewMouseMove += delegate(object sender, MouseEventArgs args) { _uiThreadMouseMovesCount++; }; // Handle cleanup this.Unloaded += delegate(object sender, RoutedEventArgs args) { if (_targetPositionCamera.IsRotating) { _targetPositionCamera.StopRotation(); } CompositionTarget.Rendering -= UpdateMainUIThreadFPS; DXViewportBorder.Child = null; if (_d3dHost != null) { _d3dHost.Dispose(); _d3dHost = null; } if (_backgroundDXEngineRenderer != null) { _backgroundDXEngineRenderer.Dispose(); } }; }
private void ToggleCameraAnimation() { if (_targetPositionCamera.IsRotating) { _targetPositionCamera.StopRotation(); animateButton.Text = "Start animation"; } else { _targetPositionCamera.StartRotation(10, 0); // animate the camera with changing heading for 10 degrees in one second animateButton.Text = "Stop animation"; } }