Exemple #1
0
            private void EventSource_MouseDown(object sender, MouseEventArgs e)
            {
                // By capturing the mouse, mouse events will still come in even when they are moving the mouse
                // outside the element/form
                Mouse.Capture(_eventSource, CaptureMode.SubTree);               // I had a case where I used the grid as the event source.  If they clicked one of the 3D objects, the scene would jerk.  But by saying subtree, I still get the event

                _previousPosition2D = e.GetPosition(_eventSource);
                _previousPosition3D = TrackballTransform.ProjectToTrackball(_eventSource.ActualWidth, _eventSource.ActualHeight, _previousPosition2D);

                #region Detect Autoscroll

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                    }
                    else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                    }
                    else
                    {
                        _autoscroll.StartAutoScroll(_previousPosition2D, UtilityWPF.TransformToScreen(_previousPosition2D, _eventSource));
                    }
                }

                #endregion
            }
Exemple #2
0
            private void EventSource_MouseMove(object sender, MouseEventArgs e)
            {
                Point currentPosition = e.GetPosition(_eventSource);

                // avoid any zero axis conditions
                if (currentPosition == _previousPosition2D)
                {
                    return;
                }

                _autoscroll.MouseMove(currentPosition);

                Vector3D currentPosition3D = TrackballTransform.ProjectToTrackball(_eventSource.ActualWidth, _eventSource.ActualHeight, currentPosition);

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    SlideCamera(currentPosition);
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        RotateCameraAroundLookDir(currentPosition, currentPosition3D);
                    }
                    else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                        ZoomCamera(currentPosition);
                    }
                    else
                    {
                        // Nothing to do here, this is taken care of in the mouse down and mouse up
                        //AutoscrollCamera(currentPosition);
                    }
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        RotateCamera(currentPosition);
                    }
                    else
                    {
                        OrbitCamera(currentPosition, currentPosition3D);
                    }
                }

                _previousPosition2D = currentPosition;
                _previousPosition3D = currentPosition3D;
            }
Exemple #3
0
        private void radCamera_Checked(object sender, RoutedEventArgs e)
        {
            if (_camera1 == null || _camera2 == null)
            {
                // This event is getting invoked from InitializeComponent
                return;
            }

            #region Disable Controls

            chkIsActive4.IsEnabled = false;
            button1.IsEnabled      = false;

            #endregion

            #region Dispose Current Trackballs

            if (_trackball2 != null)
            {
                _trackball2.EventSource = null;
                _trackball2             = null;
            }

            if (_trackball3 != null)
            {
                _trackball3.EventSource = null;
                _trackball3             = null;
            }

            if (_trackball4 != null)
            {
                _trackball4.EventSource = null;
                _trackball4             = null;
            }

            #endregion

            if (radCamera1.IsChecked.Value)
            {
                #region Camera 1

                _camera1.Position      = new Point3D(0, 0, 25);
                _camera1.LookDirection = new Vector3D(0, 0, -10);
                _camera1.UpDirection   = new Vector3D(0, 1, 0);
                _camera1.FieldOfView   = 45;

                _viewport.Camera = _camera1;

                #endregion
            }
            else if (radCamera2.IsChecked.Value)
            {
                #region Camera 2

                //_camera2.Position = new Point3D(0, 0, 25);
                //_camera2.LookDirection = new Vector3D(0, 0, -10);
                //_camera2.UpDirection = new Vector3D(0, 1, 0);
                //_camera2.FieldOfView = 45;

                _camera2.Position      = new Point3D(0, 25, 0);         // this alternate location is to test placing the camera somewhere other than the z axis
                _camera2.LookDirection = new Vector3D(0, -1, 0);
                _camera2.UpDirection   = new Vector3D(0, 0, -1);
                _camera2.FieldOfView   = 45;

                _trackball2             = new TrackballTransform(_camera2);
                _trackball2.EventSource = grdViewPort;
                _camera2.Transform      = _trackball2.Transform;

                _viewport.Camera = _camera2;

                #endregion
            }
            else if (radCamera3.IsChecked.Value)
            {
                #region Camera 3

                //_camera3.Position = new Point3D(0, 0, 25);
                //_camera3.LookDirection = new Vector3D(0, 0, -10);
                //_camera3.UpDirection = new Vector3D(0, 1, 0);
                //_camera3.FieldOfView = 45;

                _camera3.Position      = new Point3D(0, 25, 0);         // this alternate location is to test placing the camera somewhere other than the z axis
                _camera3.LookDirection = new Vector3D(0, -1, 0);
                _camera3.UpDirection   = new Vector3D(0, 0, -1);
                _camera3.FieldOfView   = 45;

                _trackball3             = new TrackBallRoam_local(_camera3);
                _trackball3.EventSource = grdViewPort;

                _viewport.Camera = _camera3;

                #endregion
            }
            else if (radCamera4.IsChecked.Value)
            {
                #region Camera 4

                chkIsActive4.IsEnabled = true;
                button1.IsEnabled      = true;

                _camera4.Position      = new Point3D(0, 0, 25);
                _camera4.LookDirection = new Vector3D(0, 0, -10);
                _camera4.UpDirection   = new Vector3D(0, 1, 0);
                _camera4.FieldOfView   = 45;

                //_camera4.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                //_camera4.LookDirection = new Vector3D(0, -1, 0);
                //_camera4.UpDirection = new Vector3D(0, 0, -1);
                //_camera4.FieldOfView = 45;

                _trackball4             = new TrackBallRoam(_camera4);
                _trackball4.EventSource = grdViewPort;

                _trackball4.AllowZoomOnMouseWheel = true;
                _trackball4.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));

                _trackball4.IsActive = chkIsActive4.IsChecked.Value;

                _viewport.Camera = _camera4;

                #endregion
            }
            else
            {
                MessageBox.Show("Unknown camera selected", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                _viewport.Camera = null;
            }
        }
        private void radCamera_Checked(object sender, RoutedEventArgs e)
        {
            if (_camera1 == null || _camera2 == null)
            {
                // This event is getting invoked from InitializeComponent
                return;
            }

            #region Disable Controls

            chkIsActive4.IsEnabled = false;
            button1.IsEnabled = false;

            #endregion

            #region Dispose Current Trackballs

            if (_trackball2 != null)
            {
                _trackball2.EventSource = null;
                _trackball2 = null;
            }

            if (_trackball3 != null)
            {
                _trackball3.EventSource = null;
                _trackball3 = null;
            }

            if (_trackball4 != null)
            {
                _trackball4.EventSource = null;
                _trackball4 = null;
            }

            #endregion

            if (radCamera1.IsChecked.Value)
            {
                #region Camera 1

                _camera1.Position = new Point3D(0, 0, 25);
                _camera1.LookDirection = new Vector3D(0, 0, -10);
                _camera1.UpDirection = new Vector3D(0, 1, 0);
                _camera1.FieldOfView = 45;

                _viewport.Camera = _camera1;

                #endregion
            }
            else if (radCamera2.IsChecked.Value)
            {
                #region Camera 2

                //_camera2.Position = new Point3D(0, 0, 25);
                //_camera2.LookDirection = new Vector3D(0, 0, -10);
                //_camera2.UpDirection = new Vector3D(0, 1, 0);
                //_camera2.FieldOfView = 45;

                _camera2.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                _camera2.LookDirection = new Vector3D(0, -1, 0);
                _camera2.UpDirection = new Vector3D(0, 0, -1);
                _camera2.FieldOfView = 45;

                _trackball2 = new TrackballTransform(_camera2);
                _trackball2.EventSource = grdViewPort;
                _camera2.Transform = _trackball2.Transform;

                _viewport.Camera = _camera2;

                #endregion
            }
            else if (radCamera3.IsChecked.Value)
            {
                #region Camera 3

                //_camera3.Position = new Point3D(0, 0, 25);
                //_camera3.LookDirection = new Vector3D(0, 0, -10);
                //_camera3.UpDirection = new Vector3D(0, 1, 0);
                //_camera3.FieldOfView = 45;

                _camera3.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                _camera3.LookDirection = new Vector3D(0, -1, 0);
                _camera3.UpDirection = new Vector3D(0, 0, -1);
                _camera3.FieldOfView = 45;

                _trackball3 = new TrackBallRoam_local(_camera3);
                _trackball3.EventSource = grdViewPort;

                _viewport.Camera = _camera3;

                #endregion
            }
            else if (radCamera4.IsChecked.Value)
            {
                #region Camera 4

                chkIsActive4.IsEnabled = true;
                button1.IsEnabled = true;

                _camera4.Position = new Point3D(0, 0, 25);
                _camera4.LookDirection = new Vector3D(0, 0, -10);
                _camera4.UpDirection = new Vector3D(0, 1, 0);
                _camera4.FieldOfView = 45;

                //_camera4.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                //_camera4.LookDirection = new Vector3D(0, -1, 0);
                //_camera4.UpDirection = new Vector3D(0, 0, -1);
                //_camera4.FieldOfView = 45;

                _trackball4 = new TrackBallRoam(_camera4);
                _trackball4.EventSource = grdViewPort;

                _trackball4.AllowZoomOnMouseWheel = true;
                _trackball4.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));

                _trackball4.IsActive = chkIsActive4.IsChecked.Value;

                _viewport.Camera = _camera4;

                #endregion
            }
            else
            {
                MessageBox.Show("Unknown camera selected", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                _viewport.Camera = null;
            }
        }