Beispiel #1
0
        public void Initialize()
        {
            Background        = null;
            viewport3DControl = new Viewport3DControl();
            viewport3DControl.SetValue(Grid.ZIndexProperty, 100);
            this.Children.Add(viewport3DControl);

            viewport3DImage = viewport3DControl.Viewport3DImage;
            if (viewport3DImage == null)
            {
                axes = new Axes3D();
                SetValue(ModelsProperty, new Model3DCollection(null));
                return;
            }
            viewport3DImage.ViewPort3D = this;

            SetValue(ModelsProperty, viewport3DImage.Models);
            // Set the owner of the Model3DCollection to be the D3DImageViewport
            // This ensures that the Model3D objects are rendered by the D3DImageViewport
            viewport3DImage.SetLayer2D(viewport3DImage.Canvas, GraphToWorld);

            viewport3DImage.Models.Changed += new Model3DCollection.ItemEventHandler(Models_Changed);

            trackball                       = new Trackball();
            trackball.EventSource           = viewport3DControl; //viewport3DImage.Canvas;
            trackball.OnTrackBallMoved     += new TrackballEventHandler(trackball_TrackBallMoved);
            trackball.OnTrackBallZoom      += new TrackballEventHandler(trackball_OnTrackBallZoom);
            trackball.OnTrackBallTranslate += new TrackballEventHandler(trackball_OnTrackBallTranslate);

            axes = new Axes3D();
            viewport3DImage.Models.Add(axes);

            viewport3DImage.CameraPosition = new Vector3(-3f, -3f, 2f);
            viewport3DImage.CameraTarget   = new Vector3(0f, 0f, 0f);
            //
            Binding bindingGraphMin = new Binding("GraphMin");

            bindingGraphMin.Source = this;
            bindingGraphMin.Mode   = BindingMode.TwoWay;
            BindingOperations.SetBinding(axes, Axes3D.GraphMinProperty, bindingGraphMin);
            Binding bindingGraphMax = new Binding("GraphMax");

            bindingGraphMax.Source = this;
            bindingGraphMax.Mode   = BindingMode.TwoWay;
            BindingOperations.SetBinding(axes, Axes3D.GraphMaxProperty, bindingGraphMax);
            Binding bindingGraphToWorld = new Binding("GraphToWorld");

            bindingGraphToWorld.Source = this;
            bindingGraphToWorld.Mode   = BindingMode.OneWay;
            BindingOperations.SetBinding(viewport3DImage, ViewportImage.ModelToWorldProperty, bindingGraphToWorld);
            ////
            GraphMax = new Point3D(1, 1, 1);
            GraphMin = new Point3D(-1, -1, -1);
            WorldMin = new Point3D(-1, -1, -1);
            WorldMax = new Point3D(1, 1, 1);
            axes.UpdateOpenSides(FindPhi());

            this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(Viewport3D_IsVisibleChanged);
        }
Beispiel #2
0
        public void Initialize()
        {
            Background = null;
            viewport3DControl = new Viewport3DControl();
            viewport3DControl.SetValue(Grid.ZIndexProperty, 100);
            this.Children.Add(viewport3DControl);

            viewport3DImage = viewport3DControl.Viewport3DImage;
            if (viewport3DImage == null)
            {
                axes = new Axes3D();
                SetValue(ModelsProperty, new Model3DCollection(null));
                return;
            }
            viewport3DImage.ViewPort3D = this;

            SetValue(ModelsProperty, viewport3DImage.Models);
            // Set the owner of the Model3DCollection to be the D3DImageViewport
            // This ensures that the Model3D objects are rendered by the D3DImageViewport
            viewport3DImage.SetLayer2D(viewport3DImage.Canvas, GraphToWorld);

            viewport3DImage.Models.Changed += new Model3DCollection.ItemEventHandler(Models_Changed);

            trackball = new Trackball();
            trackball.EventSource = viewport3DControl; //viewport3DImage.Canvas;
            trackball.OnTrackBallMoved += new TrackballEventHandler(trackball_TrackBallMoved);
            trackball.OnTrackBallZoom += new TrackballEventHandler(trackball_OnTrackBallZoom);
            trackball.OnTrackBallTranslate += new TrackballEventHandler(trackball_OnTrackBallTranslate);

            axes = new Axes3D();
            viewport3DImage.Models.Add(axes);

            viewport3DImage.CameraPosition = new Vector3(-3f, -3f, 2f);
            viewport3DImage.CameraTarget = new Vector3(0f, 0f, 0f);
            //
            Binding bindingGraphMin = new Binding("GraphMin");
            bindingGraphMin.Source = this;
            bindingGraphMin.Mode = BindingMode.TwoWay;
            BindingOperations.SetBinding(axes, Axes3D.GraphMinProperty, bindingGraphMin);
            Binding bindingGraphMax = new Binding("GraphMax");
            bindingGraphMax.Source = this;
            bindingGraphMax.Mode = BindingMode.TwoWay;
            BindingOperations.SetBinding(axes, Axes3D.GraphMaxProperty, bindingGraphMax);
            Binding bindingGraphToWorld = new Binding("GraphToWorld");
            bindingGraphToWorld.Source = this;
            bindingGraphToWorld.Mode = BindingMode.OneWay;
            BindingOperations.SetBinding(viewport3DImage, ViewportImage.ModelToWorldProperty, bindingGraphToWorld);
            ////
            GraphMax = new Point3D(1, 1, 1);
            GraphMin = new Point3D(-1, -1, -1);
            WorldMin = new Point3D(-1, -1, -1);
            WorldMax = new Point3D(1, 1, 1);
            axes.UpdateOpenSides(FindPhi());

            this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(Viewport3D_IsVisibleChanged);
        }