private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (this.CanMoveCamera)
            {
                if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    mouseDownLM      = 2;
                    mouseDown        = true;
                    centerOfViewport = viewport.PointToScreen(new Point(viewport.ActualWidth / 2, viewport.ActualHeight / 2));
                    MouseUtilities.SetPosition(centerOfViewport);
                    this.Cursor = Cursors.None;
                }
                else if (e.LeftButton == MouseButtonState.Pressed)
                {
                    mouseDownLM = 1;
                    mouseDown   = true;

                    diffOffset.X = translacija0.OffsetX;
                    diffOffset.Y = translacija0.OffsetY;
                    start        = e.GetPosition(this);


                    // oblacic
                    Point    pozicijaMisa = e.GetPosition(viewport);
                    Point3D  point3D      = new Point3D(pozicijaMisa.X, pozicijaMisa.Y, 0);
                    Vector3D pravac       = new Vector3D(pozicijaMisa.X, pozicijaMisa.Y, 10);

                    PointHitTestParameters pointParameters = new PointHitTestParameters(pozicijaMisa);
                    RayHitTestParameters   rayParameters   = new RayHitTestParameters(point3D, pravac);

                    VisualTreeHelper.HitTest(viewport, null, HTResult, pointParameters);
                }
            }
        }
        private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.CanMoveCamera)
            {
                if (!mouseDown)
                {
                    return;
                }



                if (mouseDownLM == 1)
                {
                    Point  end     = e.GetPosition(this);
                    double rasponX = end.X - start.X;
                    double rasponY = end.Y - start.Y;

                    double sirina = this.ActualWidth;
                    double visina = this.ActualHeight;

                    int    pomocna      = 300;
                    double translacijaX = (rasponX * pomocna) / sirina;
                    double translacijaY = (-rasponY * pomocna) / visina;

                    translacija0.OffsetX = diffOffset.X + (translacijaX / (pomocna * 1));
                    translacija0.OffsetY = diffOffset.Y + (translacijaY / (pomocna * 1));

                    translacija1.OffsetX = translacija0.OffsetX;
                    translacija1.OffsetY = translacija0.OffsetY;
                    translacija2.OffsetX = translacija0.OffsetX;
                    translacija2.OffsetY = translacija0.OffsetY;
                    translacija3.OffsetX = translacija0.OffsetX;
                    translacija3.OffsetY = translacija0.OffsetY;
                    translacija4.OffsetX = translacija0.OffsetX;
                    translacija4.OffsetY = translacija0.OffsetY;
                }
                else if (mouseDownLM == 2)
                {
                    Point relativePos       = Mouse.GetPosition(viewport);
                    Point actualRelativePos = new Point(relativePos.X - viewport.ActualWidth / 2,
                                                        viewport.ActualHeight / 2 - relativePos.Y);

                    double dx = actualRelativePos.X;
                    double dy = actualRelativePos.Y;

                    yaw   += dx;
                    pitch += dy;

                    // Rotate
                    this.Rotate();

                    // Set mouse position back to the center of the viewport in screen coordinates
                    MouseUtilities.SetPosition(centerOfViewport);
                }
            }
        }