示例#1
0
        private void HideModelRotator()
        {
            if (_modelRotator != null)
            {
                OverlayViewport.Children.Remove(_modelRotator);
                _modelRotator = null;
            }

            RotateButton.IsChecked = false;
        }
示例#2
0
        private void EnsureModelRotator()
        {
            if (_modelRotator != null)
            {
                return;
            }


            _modelRotator = new ModelRotatorVisual3D();

            // Setup events on ModelRotatorVisual3D
            _modelRotator.ModelRotateStarted += delegate(object sender, ModelRotatedEventArgs args)
            {
                if (_selectedVisual3D == null || _standardTransform3D == null)
                {
                    return;
                }

                _startRotateX = _standardTransform3D.RotateX;
                _startRotateY = _standardTransform3D.RotateY;
                _startRotateZ = _standardTransform3D.RotateZ;
            };

            _modelRotator.ModelRotated += delegate(object sender, ModelRotatedEventArgs args)
            {
                if (_selectedVisual3D == null || _standardTransform3D == null)
                {
                    return;
                }

                if (args.RotationAxis == ModelRotatorVisual3D.XRotationAxis)
                {
                    _standardTransform3D.RotateX = _startRotateX + args.RotationAngle;
                }

                else if (args.RotationAxis == ModelRotatorVisual3D.YRotationAxis)
                {
                    _standardTransform3D.RotateY = _startRotateY + args.RotationAngle;
                }

                else if (args.RotationAxis == ModelRotatorVisual3D.ZRotationAxis)
                {
                    _standardTransform3D.RotateZ = _startRotateZ + args.RotationAngle;
                }
            };

            _modelRotator.ModelRotateEnded += delegate(object sender, ModelRotatedEventArgs args)
            {
                // Nothing to do here in this sample
                // The event handler is here only for description purposes
            };
        }
        private void SetupModelRotator()
        {
            _modelRotator = new ModelRotatorVisual3D();

            var selectedModelBounds = RootModelVisual3D.Content.Bounds;

            // Calculate axis length from model size
            double circleWidth = Math.Max(selectedModelBounds.Size.X, Math.Max(selectedModelBounds.Size.Y, selectedModelBounds.Size.Z));

            _modelRotator.InnerRadius = circleWidth * 0.6;
            _modelRotator.OuterRadius = _modelRotator.InnerRadius + 10;


            // Setup events on ModelRotatorVisual3D
            _modelRotator.ModelRotateStarted += delegate(object sender, ModelRotatedEventArgs args)
            {
                _selectedAxisAngleRotation3D = null;

                if (args.RotationAxis == Ab3d.Common.Constants.XAxis)
                {
                    _selectedAxisAngleRotation3D = _xAxisAngleRotation3D;
                }

                else if (args.RotationAxis == Ab3d.Common.Constants.YAxis)
                {
                    _selectedAxisAngleRotation3D = _yAxisAngleRotation3D;
                }

                else if (args.RotationAxis == Ab3d.Common.Constants.ZAxis)
                {
                    _selectedAxisAngleRotation3D = _zAxisAngleRotation3D;
                }


                if ((IsCumulativeRotationCheckBox.IsChecked ?? false) && _selectedAxisAngleRotation3D != null)
                {
                    _selectedAxisAngleRotation3D = new AxisAngleRotation3D(_selectedAxisAngleRotation3D.Axis, 0);
                    var rotateTransform3D = new RotateTransform3D(_selectedAxisAngleRotation3D);

                    // Insert before TranslateTransform3D
                    _transform3DGroup.Children.Insert(_transform3DGroup.Children.Count - 2, rotateTransform3D);

                    _startRotationAngle = 0;
                }
                else
                {
                    if (_selectedAxisAngleRotation3D != null)
                    {
                        _startRotationAngle = _selectedAxisAngleRotation3D.Angle;
                    }
                }
            };

            _modelRotator.ModelRotated += delegate(object sender, ModelRotatedEventArgs args)
            {
                if (_selectedAxisAngleRotation3D == null)
                {
                    return;
                }

                _selectedAxisAngleRotation3D.Angle = _startRotationAngle + args.RotationAngle;
            };

            _modelRotator.ModelRotateEnded += delegate(object sender, ModelRotatedEventArgs args)
            {
                _selectedAxisAngleRotation3D = null;
            };


            OverlayViewport.Children.Add(_modelRotator);
        }