Exemplo n.º 1
0
        private void StartAnimation()
        {
            Camera1.StartRotation(20, 0); // animate 20 degrees in second
            AnimationButton.Content = "Stop camera animation";

            _isAnimationStarted = true;
        }
Exemplo n.º 2
0
        private void StartAnimation(bool isActionImmediate)
        {
            // Camera can be animated with using StartRotation method.
            // StartRotation take two parameters - headingChangeInSecond and attitudeChangeInSecond
            // Advantage of using StartRotation method over using Storyboard animation of Heading or Attitude properties is that
            // StartRotation does not lock the Heading and Attitude properties.
            // The StartRotation also works very good with CameraControlPanel and MouseCameraController - while the camera is rotating it is possible
            // to manually change camera with the mouse or with the buttons on CameraControlPanel

            double headingChangeInSecond  = HeadingChangeInSecondSlider.Value;
            double attitudeChangeInSecond = AttitudeChangeInSecondSlider.Value;

            if (isActionImmediate)
            {
                Camera1.StartRotation(headingChangeInSecond, attitudeChangeInSecond); // No easing
            }
            else
            {
                double accelerationSpeed = AccelerationSpeedSlider.Value;
                SphericalCamera.EasingFunctionDelegate easingFunction = GetEaseInFunction(); // NOTE that ease in and ease out are different functions

                Camera1.StartRotation(headingChangeInSecond, attitudeChangeInSecond, accelerationSpeed, easingFunction);
            }

            StartStopSlowlyButton.Content   = "STOP rotation slowly";
            StartStopNowButton.Content      = "STOP rotation now";
            AccelerationSpeedTextBlock.Text = "decelerationSpeed (0 = disabled):";

            _isRotationStarted = true;
        }
Exemplo n.º 3
0
        public BillboardsSample()
        {
            InitializeComponent();

            _transparencySorter = new Ab3d.Utilities.TransparencySorter(TreesPlaceholerVisual3D)
            {
                UsedCamera = Camera1
            };

            // Explicitly set which Visual3D objects should be considered transparent.
            // This is needed because TransparencySorter does not know if texture image have transparency or not and therefore does not consider them transparent.
            // With calling AddTransparentModels we define that.
            // Another option to "persuade" TransparencySorter to consider objects are transparent is to set very small opacity to the ImageBrush - for example set Opacity to 0.99
            _transparencySorter.AddTransparentModels(TreePlaneVisual1, TreePlaneVisual2, TreePlaneVisual3, TreePlaneVisual4);

            _transparencySorter.Sort(TransparencySorter.SortingModeTypes.ByCameraDistance);


            Camera1.CameraChanged += Camera1OnCameraChanged;

            Camera1.StartRotation(30, 0);

            // PlaneVisual3D uses MatrixTransform3D to position, scale and orient the plane. This greatly improves the performance.
            // To disable that and change MeshGeometry3D instead of MatrixTransform3D, set UseMatrixTransform3D to false:
            //PlaneVisual1.UseMatrixTransform3D = false;

            MainViewport.SizeChanged += (sender, args) => UpdateOverlayCanvasElements();
        }
        public AdjustingTextDirectionSample()
        {
            InitializeComponent();

            Camera1.StartRotation(45, 0);

            Camera1.CameraChanged += Camera1OnCameraChanged;
        }
        private void StartAnimation()
        {
            AnimationButton.Content = "Stop camera rotation";

            // start rotating the camera with changing heading by 30 degrees per second.
            // Note that while the camera is rotating, it is still possible to rotate the camera with the mouse (during mouse rotation the animation is suspended).
            Camera1.StartRotation(30, 0);

            _isAnimationStarted = true;
        }
Exemplo n.º 6
0
 private void CameraRotationButton_OnClick(object sender, RoutedEventArgs e)
 {
     if (Camera1.IsRotating)
     {
         Camera1.StopRotation();
     }
     else
     {
         Camera1.StartRotation(45, 0);
     }
 }
        public BackgroundObjectsCreation()
        {
            InitializeComponent();

            _objFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Models\\dragon_vrip_res3.obj");

            // Load the test file before the actual test so that the file gets into File System cache
            var readerObj = new Ab3d.ReaderObj();

            readerObj.ReadModel3D(_objFileName);

            Camera1.StartRotation(30, 0);
        }
 private void CameraRotationButton_OnClick(object sender, RoutedEventArgs e)
 {
     if (Camera1.IsRotating)
     {
         Camera1.StopRotation();
         CameraRotationButton.Content = "Start camera rotation";
     }
     else
     {
         Camera1.StartRotation(20, 0);
         CameraRotationButton.Content = "Stop camera rotation";
     }
 }
Exemplo n.º 9
0
 private void ToggleCameraAnimation()
 {
     if (Camera1.IsRotating)
     {
         Camera1.StopRotation();
         AnimateButton.Content = "Start animation";
     }
     else
     {
         Camera1.StartRotation(10, 0); // animate with changing heading for 10 degrees in one second
         AnimateButton.Content = "Stop animation";
     }
 }
        private void OnAnimateCameraCheckBoxChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            if (AnimateCameraCheckBox.IsChecked ?? false)
            {
                Camera1.StartRotation(30, 0);
            }
            else
            {
                Camera1.StopRotation();
            }
        }
        public LandscapeGeneratorSample()
        {
            InitializeComponent();


            // Setup RadioBoxes and Comboboxes
            FillPossibleLandscapeSizes();

            // Create linear gradient that will be used for Legent and for coloring vertexes
            var linearGradientBrush = CreateDataGradientBrush();

            _gradientColor4Array = CreateGradientColorsArray(linearGradientBrush);

            AddLegendControl(linearGradientBrush);


            // Adjust the CameraAxis control to show a coordinate system with Z up (more standard when showing height map).
            // Note: WPF uses right handed coordinate system with Y up.
            CameraAxisPanel1.CustomizeAxes(new Vector3D(1, 0, 0), "X", Colors.Red,
                                           new Vector3D(0, 1, 0), "Z", Colors.Green,
                                           new Vector3D(0, 0, -1), "Y", Colors.Blue);


            Camera1.StartRotation(10, 0);

            this.Loaded += delegate(object sender, RoutedEventArgs args)
            {
                GoToNextRandomSeed(); // Set new random seed - after seed text will be changed, the CreateLandscape will be called
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                }

                MainDXViewportView.Dispose();
            };
        }
        public VertexColorRenderingSample()
        {
            InitializeComponent();

            AddTestModel();

            Camera1.StartRotation(45, 0);


            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all DXEngine objects that are created here - in this case _vertexColorMaterial
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                    _vertexColorMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }
 private void StartCameraRotation()
 {
     Camera1.StartRotation(45, 0);
     StartStopCameraRotateButton.Content = "Stop camera rotate";
 }
Exemplo n.º 14
0
 private void StartAnimation()
 {
     Camera1.StartRotation(20, 0);
     AnimationButton.Content = "Stop camera animation";
 }
        public LinesSelector()
        {
            InitializeComponent();

            // LineSelectorData is a utility class that can be used to get the closest distance
            // of a specified screen position to the 3D line.
            _lineSelectorData = new List <LineSelectorData>();

            for (int i = 0; i < 15; i++)
            {
                // Create random 3D lines
                var randomColor  = GetRandomColor();
                var lineVisual3D = GenerateRandomLine(randomColor, 10);

                // Create LineSelectorData from each line.
                // When adjustLineDistanceWithLineThickness is true, then distance is measured from line edge.
                // If adjustLineDistanceWithLineThickness is false, then distance is measured from center of the line.
                var lineSelectorData = new LineSelectorData(lineVisual3D, Camera1, adjustLineDistanceWithLineThickness: true);

                // LineSelectorData transform the line positions when there is any transformation set to the lineVisual3D's Transform property
                // (in this case the lineSelectorData.PositionsTransform3D is set to the used transformation).
                //
                // But when the lineVisual3D is added to a parent Visual3D that has its own transformation,
                // then LineSelectorData is not "aware" of that transformation.
                // To demonstrate that, the lineVisual3D in this sample is added to a RootVisual3D that has TranslateTransform3D with OffsetX = 20.
                //
                // Because we know the organization of objects in this sample, we could simple write the following to support that:
                // lineSelectorData.PositionsTransform3D = RootVisual3D.Transform;
                //
                // But there is a more general way that can be used.
                // With help of TransformationsHelper.GetVisual3DTotalTransform it is possible
                // to get the combined (total) transformation from Viewport3D to the lineVisual3D.
                // This also includes the transformation on lineVisual3D (second parameter in GetVisual3DTotalTransform is true).
                //
                // This methods can be also used to check if specified Visual3D is connected to Viewport3D (it sets an out parameter isVisualConnected).
                // There is also another override of this method that takes two Visual3D objects and gets the transformation from the first to the second.

                bool isVisualConnected; // This will be set to true if lineVisual3D is connected to Viewport3D (always true in our case).
                lineSelectorData.PositionsTransform3D = Ab3d.Utilities.TransformationsHelper.GetVisual3DTotalTransform(lineVisual3D, true, out isVisualConnected);


                _lineSelectorData.Add(lineSelectorData);
            }



            _isCameraChanged = true; // When true, the CalculateScreenSpacePositions method is called before calculating line distances

            Camera1.CameraChanged += delegate(object sender, CameraChangedRoutedEventArgs e)
            {
                _isCameraChanged = true;
                UpdateClosestLine();
            };

            this.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                _lastMousePosition = e.GetPosition(MainBorder);
                UpdateClosestLine();
            };

            Camera1.StartRotation(20, 0);
        }
Exemplo n.º 16
0
        public ShadedPointCloudSample()
        {
            InitializeComponent();

            // First create an instance of AssemblyShaderBytecodeProvider.
            // This will allow using EffectsManager to cache and get the shaders from the assembly's EmbeddedResources.
            // See ShadedPointCloudEffect.EnsureShaders method for more info.
            var resourceAssembly = this.GetType().Assembly;
            var assemblyShaderBytecodeProvider = new AssemblyShaderBytecodeProvider(resourceAssembly, resourceAssembly.GetName().Name + ".Resources.Shaders.");

            EffectsManager.RegisterShaderResourceStatic(assemblyShaderBytecodeProvider);

            MainDXViewportView.PresentationType = DXView.PresentationTypes.DirectXImage;

            //MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { GraphicsProfile.LowQualityHardwareRendering };

            //Ab3d.DirectX.Controls.D3DHost.RenderAsManyFramesAsPossible = true;



            // Subscribe to DXSceneDeviceCreated event - there the DirectX 11 device was already created
            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                var dxScene = MainDXViewportView.DXScene;

                if (dxScene == null) // When null, then we are probably using WPF 3D rendering
                {
                    return;
                }

                // Create a new instance of ShadedPointCloudEffect
                _shadedPointCloudEffect = new ShadedPointCloudEffect();

                // Register effect with EffectsManager - this will also initialize the effect with calling OnInitializeResources method in the ShadedPointCloudEffect class
                dxScene.DXDevice.EffectsManager.RegisterEffect(_shadedPointCloudEffect);


                // Set global effect settings
                _shadedPointCloudEffect.DiffuseColor  = Colors.Orange.ToColor4();
                _shadedPointCloudEffect.SpecularColor = Color3.White;
                _shadedPointCloudEffect.SpecularPower = 64;
                _shadedPointCloudEffect.PointSize     = (float)PointSizeComboBox.SelectedItem;


                // Create new material from the effect
                _effectMaterial = new EffectMaterial(_shadedPointCloudEffect);
                //_disposables.Add(_effectMaterial); // is not added to disposables because it is disposed separately and can be disposed after the number of positions is changed in the DropDown


                // Create the demo data and show them
                RecreatePointCloud();
            };



            ModelsCountComboBox.ItemsSource   = new int[] { 1, 2, 3, 4, 5, 10, 20, 50, 60, 100, 200, 500 };
            ModelsCountComboBox.SelectedIndex = 2;

            PointsCountComboBox.ItemsSource   = new int[] { 100000, 500000, 1000000, 2000000, 5000000, 10000000, 20000000, 30000000, 40000000, 50000000, 60000000 };
            PointsCountComboBox.SelectedIndex = 2;

            PointSizeComboBox.ItemsSource   = new float[] { 0.001f, 0.005f, 0.01f, 0.02f, 0.05f, 0.1f, 0.2f, 0.5f, 1.0f, 2.0f, 5.0f, 10.0f };
            PointSizeComboBox.SelectedIndex = 8;


            if (SampleDataFile != null)
            {
                PointsCountTextBlock.Visibility = Visibility.Collapsed;
                PointsCountComboBox.Visibility  = Visibility.Collapsed;
            }


            Camera1.StartRotation(45, 0);
            StartStopCameraButton.Content = "Stop camera rotation";

            Camera1.CameraChanged += delegate(object sender, CameraChangedRoutedEventArgs args)
            {
                if (MainDXViewportView.DXScene == null)
                {
                    return;
                }

                MainDXViewportView.DXScene.Camera.Update();
                double pixelSize = OptimizedPointMesh <PositionNormal> .GetPixel3DSize(MainDXViewportView.DXScene.Camera, MainDXViewportView.DXScene.Width, new Vector3(0, 0, 0));

                if (Camera1.CameraType == BaseCamera.CameraTypes.OrthographicCamera)
                {
                    InfoTextBlock.Text = $"CameraWidth:  {Camera1.CameraWidth:F0}; Pixel size: {pixelSize:F2}";
                }
                else
                {
                    InfoTextBlock.Text = $"Camera Distance:  {Camera1.Distance:F0}; Pixel size: {pixelSize:F2}";
                }
            };

            this.Unloaded += (sender, args) => Dispose();
        }