Example #1
0
        public MainViewModel()
        {
            //Create the Effects Manager
            this.EffectsManager = new DefaultEffectsManager();

            //Create the Material
            this.MeshMaterial = DiffuseMaterials.Bisque;

            //Set the initial rotation point to the origin
            this.RotationPoint = Point3D.Zero;

            //Create the Camera
            this.MainCamera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
            {
                Position      = new System.Windows.Media.Media3D.Point3D(0f, 40, 40),
                LookDirection = new System.Windows.Media.Media3D.Vector3D(0f, -40, -40),
                UpDirection   = new System.Windows.Media.Media3D.Vector3D(0, 0, 1)
            };
        }
Example #2
0
        private void InitCamera()
        {
            Camera.LookAt(new Point3D(0, 0, 0),
                          new Vector3D(-4e3, -4e3, -4e3),
                          0);

            switch (Camera)
            {
            case PerspectiveCamera camera:
                camera.FieldOfView       = 60;
                camera.FarPlaneDistance  = AstronomicalObject.Au;
                camera.NearPlaneDistance = 1;
                break;

            case OrthographicCamera camera:
                camera.FarPlaneDistance  = AstronomicalObject.Au;
                camera.NearPlaneDistance = 0;
                break;
            }

            Viewport3DX.CameraMode = CameraMode.Inspect;
        }
        protected BaseViewModel()
        {
            // camera models
            CameraModelCollection = new List<string>()
            {
                Orthographic,
                Perspective,
            };

            // on camera changed callback
            this.CameraModelChanged += (s, e) =>
            {
                if (this.cameraModel == Orthographic)
                {
                    //if (this.Camera != null)
                    //{
                    //    var newCamera = new OrthographicCamera();
                    //    this.Camera.CopyTo(newCamera);
                    //    newCamera.NearPlaneDistance = znear;
                    //    newCamera.FarPlaneDistance = zfar;
                    //    this.Camera = newCamera;

                    //}
                    //else
                    {
                        this.Camera = this.defaultOrthographicCamera;
                    }
                }
                else if (this.cameraModel == Perspective)
                {
                    //if (this.Camera != null)
                    //{
                    //    var newCamera = new PerspectiveCamera();
                    //    this.Camera.CopyTo(newCamera);
                    //    newCamera.NearPlaneDistance = znear;
                    //    newCamera.FarPlaneDistance = zfar;
                    //    this.Camera = newCamera;
                    //}
                    //else
                    {
                        this.Camera = this.defaultPerspectiveCamera;
                    }
                }
                else
                {
                    throw new HelixToolkitException("Camera Model Error.");
                }
            };

            // default camera model
            this.CameraModel = Perspective;

            this.Title = "Demo (HelixToolkitDX)";
            this.SubTitle = "Default Base View Model";
            this.RenderTechnique = Techniques.RenderPhong;
        }
 private void OnEdgeMouse3DUp(object sender, RoutedEventArgs e)
 {            
     if (this.isCaptured)
     {
         Application.Current.MainWindow.Cursor = Cursors.Arrow;
         this.isCaptured = false;
         this.camera = null;
         this.viewport = null;
     }
 }
        private void OnEdgeMouse3DDown(object sender, RoutedEventArgs e)
        {
            var args = e as Mouse3DEventArgs;
            if (args == null) return;
            if (args.Viewport == null) return;

            this.isCaptured = true;
            this.viewport = args.Viewport;
            this.camera = args.Viewport.Camera;
            this.lastHitPos = args.HitTestResult.PointHit;
        }
Example #6
0
        public static void AddPointCloud(Dictionary <KeyValuePair <int, int>, double> PointCollection, out PointModel Points,
                                         out GridModel Grid, out AxisModel Axis, out HelixToolkit.Wpf.SharpDX.Camera Camera, bool cameraType = false)
        {
            Camera = null;
            Points = null;
            Grid   = null;
            Axis   = null;

            var points = new PointGeometry3D();
            var col    = new Color4Collection();  // color gradient
            var ptPos  = new Vector3Collection(); // point positions
            var ptIdx  = new IntCollection();     // point indexes

            if (PointCollection != null && PointCollection.Count() > 1)
            {
                //newdataFromTxt(path, positionX, positionY, positionZ);
                var maxX    = PointCollection.Max(x => x.Key.Key);   // X
                var minX    = PointCollection.Min(x => x.Key.Key);   // X
                var maxY    = PointCollection.Max(x => x.Key.Value); // Y
                var minY    = PointCollection.Min(x => x.Key.Value); // Y
                var maxZ    = PointCollection.Max(x => x.Value);     // Z
                var minZ    = PointCollection.Min(x => x.Value);     // Z
                var minYObj = PointCollection.First(x => x.Key.Value == minY);

                Trace.WriteLine($"{maxX} {minX} {maxY} {minY} {maxZ} {minZ}");

                if (PointCollection.Count() <= 0)
                {
                    return;
                }
                foreach (var point in PointCollection)
                {
                    var positionToColour = point.Value;

                    ptIdx.Add(ptPos.Count);
                    ptPos.Add(new Vector3((float)point.Key.Key, ((float)point.Key.Value), (float)point.Value));
                    col.Add(new Color4(RedBlueScale((float)minZ, (float)maxZ, (float)positionToColour)));
                }
                Points = new PointModel
                {
                    // indexes and color gradient
                    PointsGeometry = new PointGeometry3D {
                        Positions = ptPos, Indices = ptIdx, Colors = col
                    },
                    PointsColor     = Colors.White,
                    PointsTransform = new TranslateTransform3D(-minX, -minY, -minZ)
                };
                // floor plane grid
                LineBuilder gridLines = new LineBuilder();
                VisualizationTools.CreateGrid(gridLines, maxX, minX, maxY, minY, minZ);
                Grid = new GridModel
                {
                    GridGeometry  = gridLines.ToLineGeometry3D(),
                    GridColor     = new Color4(153 / 255.0f, 204 / 255.0f, 255 / 255.0f, 0.3f).ToColor(),
                    GridTransform = new TranslateTransform3D(0, 0, 0)
                };
                // lines
                LineBuilder arrows = new LineBuilder();
                VisualizationTools.CreateAxes(arrows, (float)maxX, (float)minX, (float)maxY, (float)minY, (float)maxZ, (float)minZ);
                Axis = new AxisModel
                {
                    AxisGeometry  = arrows.ToLineGeometry3D(),
                    AxisColor     = new Color4(0, 255 / 255.0f, 255 / 255.0f, 0.5f).ToColor(),
                    AxisTransform = new TranslateTransform3D(0, 0, 0)
                };

                if (cameraType == false)
                {
                    Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
                    {
                        Position         = new Point3D(0, 0, Math.Abs(minZ * 100)),
                        LookDirection    = new Vector3D(((float)maxX - (float)minX) / 2, ((float)maxY - (float)minY) / 2, -Math.Abs(minZ * 100)),//z kamerą jest problem przy przybliżaniu prawdopodobnie przez ten LookDirection albo sposób poruszania kamerą
                        UpDirection      = new Vector3D(0, 1, 0),
                        FarPlaneDistance = 5000000
                    };
                }
                else
                {
                    Camera = new HelixToolkit.Wpf.SharpDX.OrthographicCamera
                    {
                        Position         = new Point3D(0, 0, Math.Abs(minZ * 100)),
                        LookDirection    = new Vector3D(((float)maxX - (float)minX) / 2, ((float)maxY - (float)minY) / 2, -Math.Abs(minZ * 100)),//z kamerą jest problem przy przybliżaniu prawdopodobnie przez ten LookDirection albo sposób poruszania kamerą
                        UpDirection      = new Vector3D(0, 1, 0),
                        FarPlaneDistance = 5000000
                    };
                }
            }
        }