public SharpHorizontalAndVerticalLines()
        {
            InitializeComponent();

            _twoDimensionalCamera = new TwoDimensionalCamera(MainDXViewportView,
                                                             ViewportBorder,
                                                             useScreenPixelUnits: true,
                                                             coordinateSystemType: TwoDimensionalCamera.CoordinateSystemTypes.CenterOfViewOrigin)
            {
                MoveCameraConditions       = MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                QuickZoomConditions        = MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed | MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                IsMouseAndTouchZoomEnabled = true,
                ShowCameraLight            = ShowCameraLightType.Always
            };

            MouseCameraControllerInfo1.MouseCameraController = _twoDimensionalCamera.UsedMouseCameraController;


            // Use Loaded on TwoDimensionalCamera to delay creating the scene
            // until the TwoDimensionalCamera is loaded - then the view's size and dpi scale are known.
            _twoDimensionalCamera.Loaded += delegate(object sender, EventArgs args)
            {
                CreateTestScene();
            };


            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                // Do we need to show warning - it is shown when using super-sampling
                if (MainDXViewportView.DXScene.SupersamplingCount > 1)
                {
                    SupersamplingWarningTextBlock.Visibility = Visibility.Visible;
                }

                // NOTE:
                // To render all lines without anti-aliasing and without geometry shader,
                // set UseGeometryShaderFor3DLines and RenderAntialiased3DLines to false:
                //
                //MainDXViewportView.DXScene.UseGeometryShaderFor3DLines = false;
                //MainDXViewportView.DXScene.RenderAntialiased3DLines    = false;
            };


            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }
        public TwoDimensionalCameraSample()
        {
            InitializeComponent();

            // NOTE: TwoDimensionalCamera class is available with full source in this samples project in the Common folder.

            // Create an instance of TwoDimensionalCamera.
            // TwoDimensionalCamera will internally create a TargetPositionCamera and MouseCameraController (when mouseEventsSourceElement is not null).
            // They will be used to show the 2D scene.
            _twoDimensionalCamera = new TwoDimensionalCamera(MainDXViewportView,
                                                             mouseEventsSourceElement: ViewportBorder,   // if mouseEventsSourceElement is null, then MouseCameraController will not be created by TwoDimensionalCamera
                                                             useScreenPixelUnits: false,                 // when false, then the size in device independent units is used (as size of DXViewportView); when true size in screen pixels is used (see SharpHorizontalAndVerticalLines sample)
                                                             coordinateSystemType: TwoDimensionalCamera.CoordinateSystemTypes.CenterOfViewOrigin)
            {
                MoveCameraConditions       = MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                QuickZoomConditions        = MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed | MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                IsMouseAndTouchZoomEnabled = true,
                ShowCameraLight            = ShowCameraLightType.Always
            };

            _twoDimensionalCamera.CameraChanged += delegate(object sender, EventArgs args)
            {
                UpdateSceneInfo();
            };


            // You can access the create TargetPositionCamera with UsedCamera property
            // and MouseCameraController with UsedMouseCameraController property.
            CameraAxisPanel1.TargetCamera = _twoDimensionalCamera.UsedCamera;
            MouseCameraControllerInfo1.MouseCameraController = _twoDimensionalCamera.UsedMouseCameraController;



            CreateShapesSample();
            //LoadSampleLinesData(lineThickness: 0.8, new Rect(-400, -300, 800, 600));

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }
예제 #3
0
        public TwoDimensionalCameraLineEditor()
        {
            InitializeComponent();

            MouseCameraControllerInfo1.AddCustomInfoLine(0, MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed, "Create new line");


            // NOTE: TwoDimensionalCamera class is available with full source in this samples project in the Common folder.

            // Create an instance of TwoDimensionalCamera.
            // TwoDimensionalCamera will internally create a TargetPositionCamera and MouseCameraController (when mouseEventsSourceElement is not null).
            // They will be used to show the 2D scene.
            _twoDimensionalCamera = new TwoDimensionalCamera(MainDXViewportView,
                                                             mouseEventsSourceElement: ViewportBorder,   // if mouseEventsSourceElement is null, then MouseCameraController will not be created by TwoDimensionalCamera
                                                             useScreenPixelUnits: false,                 // when false, then the size in device independent units is used (as size of DXViewportView); when true size in screen pixels is used (see SharpHorizontalAndVerticalLines sample)
                                                             coordinateSystemType: TwoDimensionalCamera.CoordinateSystemTypes.CenterOfViewOrigin)
            {
                MoveCameraConditions       = MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                QuickZoomConditions        = MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed | MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                ShowCameraLight            = ShowCameraLightType.Always,
                IsMouseAndTouchZoomEnabled = true,
            };

            // You can access the create TargetPositionCamera with UsedCamera property
            // and MouseCameraController with UsedMouseCameraController property.
            MouseCameraControllerInfo1.MouseCameraController = _twoDimensionalCamera.UsedMouseCameraController;

            // If we want to use LeftMouseButton for mouse movement, then we can also start new line with the same button with setting MouseMoveThreshold:
            //// Set MouseMoveThreshold so that mouse move starts after the mouse is moved
            //// for at least 3 pixels. This way we can use mouse click to start / end line drawing.
            //_twoDimensionalCamera.UsedMouseCameraController.MouseMoveThreshold = 3;


            _twoDimensionalCamera.CameraChanged += delegate(object sender, EventArgs args)
            {
                // When zoom is changed, we need to update all line markers
                if (!MathUtils.IsSame(_lastZoomFactor, _twoDimensionalCamera.ZoomFactor))
                {
                    // Update line markers size (we want that at each zoom level their WPF size is _positionMarkerWpfSize
                    _positionMarkerHalfSize = _twoDimensionalCamera.GetViewSizeFromWpfSize(_positionMarkerWpfSize) * 0.5;

                    if (double.IsNaN(_snappedViewPosition.X)) // Check if _snappedViewPosition is actually set
                    {
                        return;
                    }

                    // Reuse last position
                    var mousePosition = _twoDimensionalCamera.ToWpfPosition(_snappedViewPosition);
                    CheckPositionMarkers(mousePosition, updateExistingPositionMarkers: true); // _positionMarkerHalfSize is changed so we need to update all shown position markers

                    _lastZoomFactor = _twoDimensionalCamera.ZoomFactor;
                }
            };


            _twoDimensionalCamera.UsedMouseCameraController.CameraMoveStarted += delegate(object sender, EventArgs args)
            {
                _isMouseButtonPressed = false; // when we started mouse camera movement, we need to prevent creating the line when the mouse button is released
            };

            _twoDimensionalCamera.UsedMouseCameraController.CameraQuickZoomStarted += delegate(object sender, EventArgs args)
            {
                _isMouseButtonPressed = false; // when we started quick zoom, we need to prevent creating the line when the mouse button is released
            };


            // We store lines in our List of Points.
            // The main purpose of this is that we can have a very fast access to line positions.
            // (if we would read the Positions from MultiLineVisual3D this would be much slower because accessing DependencyProperties and Point3DCollection is very slow).
            _allPositions = new List <Point>();

            // _positionMarkers is a list that stores all created line markers. The size of array is the same as the size of _allPositions
            _positionMarkers = new List <PolyLineVisual3D>();


            // One MultiLineVisual3D will show fully created 3D lines (this is the much faster then creating individual LineVisual3D objects)
            _multiLineVisual3D = new MultiLineVisual3D()
            {
                Positions     = new Point3DCollection(),
                LineColor     = Colors.Black,
                LineThickness = 1
            };

            MainViewport.Children.Add(_multiLineVisual3D);


            // _creatingLine will show the line that is currently being created - user has not placed the end position yet.
            _creatingLine = new LineVisual3D()
            {
                LineColor     = Colors.Gray,
                LineThickness = 1,
                IsVisible     = false
            };

            MainViewport.Children.Add(_creatingLine);


            // _snappedPositionMarker will be shown over standard gray position marker and will indicate with its black color that mouse position is snapped to the marked position.
            _snappedPositionMarker = new PolyLineVisual3D()
            {
                Positions     = new Point3DCollection(5),
                LineColor     = Colors.Black,
                LineThickness = 1,
                IsVisible     = false
            };

            MainViewport.Children.Add(_snappedPositionMarker);


            _positionMarkerHalfSize = _twoDimensionalCamera.GetViewSizeFromWpfSize(_positionMarkerWpfSize) * 0.5;

            AddAxisLines();

            AddRandomLines(10);

            _snappedViewPosition = new Point(double.NaN, double.NaN); // Mark as invalid


            // We use ViewportBorder to get our mouse events
            ViewportBorder.MouseLeftButtonDown += delegate(object o, MouseButtonEventArgs args)
            {
                _isMouseButtonPressed = true; // we will start the line on mouse up
            };

            ViewportBorder.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs args)
            {
                if (!_isMouseButtonPressed)
                {
                    return;
                }

                if (_creatingLine.IsVisible)
                {
                    CompleteNewLine();
                }
                else
                {
                    StartNewLine(_snappedViewPosition);
                }

                _isMouseButtonPressed = false;
            };

            ViewportBorder.MouseMove += delegate(object o, MouseEventArgs args)
            {
                var mousePosition = args.GetPosition(ViewportBorder);
                CheckPositionMarkers(mousePosition, updateExistingPositionMarkers: false);

                if (_creatingLine.IsVisible)
                {
                    UpdateLastLinePosition(_snappedViewPosition);
                }
            };


            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }