Пример #1
0
        private void AutoRotate_MouseEnter()
        {
            if (_autoRotateOnMouseHover && _rotateTimer == null && _rotateTransform != null)
            {
                _rotateTimer = new DispatcherTimer();
                _rotateTimer.Interval = TimeSpan.FromMilliseconds(25);
                _rotateTimer.Tick += RotateTimer_Tick;

                _rotateAnimate = AnimateRotation.Create_AnyOrientation(_rotateTransform, 45d);
            }

            if (_autoRotateOnMouseHover && _rotateTimer != null)
            {
                _lastTick = DateTime.UtcNow;
                _rotateTimer.IsEnabled = true;
            }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //_quick = new BackdropQuick();
                //_quick.Show();
                //_quick.ValueChanged += _quick_ValueChanged;


                //NOTE: This MUST be set in loaded, or keyboard events get very flaky (even if the usercontrol has focus, something
                //inside of it must also have focus)
                lblFocusable.Focus();

                // Setting these up now so that the order stays consistent (so that semitransparency will work)

                #region Back visual

                _backVisual = new ModelVisual3D();
                if (_graphic == null)
                {
                    _backVisual.Content = GetBlankModel();
                }
                else
                {
                    _backVisual.Content = _graphic.Model;
                }

                _viewport.Children.Add(_backVisual);

                #endregion

                #region 2D panel

                DiffuseMaterial diffuse = new DiffuseMaterial(Brushes.White);
                Viewport2DVisual3D.SetIsVisualHostMaterial(diffuse, true);

                grd3D = new Grid();

                grd3D.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Star) });
                grd3D.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(.5, GridUnitType.Star) });
                grd3D.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });

                Grid.SetColumn(pnlLeft, 0);
                Grid.SetColumn(pnlDetail, 2);

                grd3D.Children.Add(pnlLeft);
                grd3D.Children.Add(pnlDetail);

                _visual2D3D = new Viewport2DVisual3D();
                _visual2D3D.Material = diffuse;
                //_visual2D3D.Geometry = GetGeometry(_quick.CylinderNumSegments, _quick.CylinderThetaOffset, _quick.CylinderHeight, _quick.CylinderRadius, _quick.CylinderTranslate);
                _visual2D3D.Geometry = GetGeometry(NUMSEGMENTS, THETA, HEIGHT, RADIUS, TRANSLATE);
                _visual2D3D.Visual = grd3D;
                _visual2D3D.Transform = new TranslateTransform3D(0, 0, _cameraLength * .3);

                _viewport.IsHitTestVisible = true;

                _viewport.Children.Add(_visual2D3D);

                #endregion

                #region Detail Visual

                _detailVisual = new ModelVisual3D();
                _detailVisual.Content = GetBlankModel();

                Transform3DGroup transform = new Transform3DGroup();

                _detailRotationInitial = new QuaternionRotation3D();
                transform.Children.Add(new RotateTransform3D(_detailRotationInitial));

                _detailRotationAnimate = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
                transform.Children.Add(new RotateTransform3D(_detailRotationAnimate));

                _detailTranslate = new TranslateTransform3D(0, 0, 0);       // this one is so the model can be centered on zero
                transform.Children.Add(_detailTranslate);

                _detailScale = new ScaleTransform3D(1, 1, 1);
                transform.Children.Add(_detailScale);

                transform.Children.Add(new TranslateTransform3D(_cameraLength * .1, 0, 0));     // this one is so the visual is shifted into the final place on screen

                _detailVisual.Transform = transform;

                _viewport.Children.Add(_detailVisual);

                UpdateDetailVisual();

                #endregion

                _detailAnimate = AnimateRotation.Create_Constant(_detailRotationAnimate, 30);

                chkIs3D.IsChecked = _is3DPanel;

                _isInitialized = true;

                Update2D3DPanels();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "BackdropPanel", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }