public void sodoff(object sender, MouseEventArgs e)
        {
            GraphView_StateManager manager = ProjectStateManager.Instance.StateManagers.OfType <GraphView_StateManager>().First();
            CurveGraphViewModel    vm      = ((CurveGraphViewModel)manager.ViewModel);

            if (vm == null)
            {
                return;
            }

            Point pos = e.GetPosition(sender as Canvas);

            pos.X -= vm.Camera.GetTransform(0, 0);
            pos.Y -= vm.Camera.GetTransform(0, 1);

            double value = 0;

            for (int x = 0; x < vm.ModelItems.Item.Curve.Count; x++)
            {
                var curve = vm.ModelItems.Item.Curve[x].Points;

                for (int i = 0; i < curve.Count; i++)
                {
                    if (i != 0 && pos.X < curve[i].X)
                    {
                        Point point1 = curve[i - 1];
                        Point point2 = curve[i];

                        value = LerpMath.Lerp(point1, point2, pos.X / point2.X).Y;
                        break;
                    }
                }
            }

            double[] camCoords = new double[] {
                vm.Camera.GetTransform(0, 0),
                vm.Camera.GetTransform(0, 1)
            };
            double scale = vm.Camera.GetScale;

            xLabel.Content = String.Format("Mouse: {0:N2} {1:N2} | Camera: {2:N2} {3:N2} | Scale: {4:N2} |  Curve value: {5:N2}",
                                           (e.GetPosition(_View.GraphView).X - camCoords[0]) * scale,
                                           (e.GetPosition(_View.GraphView).Y - camCoords[1]) * scale,
                                           camCoords[0],
                                           camCoords[1],
                                           scale,
                                           value
                                           );
        }
Exemplo n.º 2
0
        public static List <Point> Draw(BezierCurve curve, Camera cam)
        {
            double[] offset = new double[] { cam.GetTransform(0, 0), cam.GetTransform(0, 1) };
            double   scale  = cam.GetScale;

            BezierCurve     _Curve   = BezierCurve.ScaleAdjusted(curve, cam);
            PointCollection lerpList = new PointCollection();


            for (int i = 0; i < _Curve.Smoothness.Count; i++)
            {
                double steps      = 0;
                int    multiplier = 0;

                for (int j = 0; j < i; j++)
                {
                    multiplier += _Curve.Smoothness[j] + 1;
                }

                try {
                    int lineSmoothness = _Curve.Smoothness[i];

                    while (steps < 1.05)
                    {
                        if (lineSmoothness != 0)
                        {
                            if (lineSmoothness == 1)
                            {
                                Point lerp1 = LerpMath.Lerp(_Curve.Points[multiplier], _Curve.Points[1 + multiplier], steps);
                                Point lerp2 = LerpMath.Lerp(_Curve.Points[1 + multiplier], _Curve.Points[2 + multiplier], steps);

                                Point lerp4 = LerpMath.Lerp(lerp1, lerp2, steps);

                                lerpList.Add(lerp4);
                            }
                            else
                            {
                                Point lerp1 = LerpMath.Lerp(_Curve.Points[multiplier], _Curve.Points[1 + (multiplier)], steps);
                                Point lerp2 = LerpMath.Lerp(_Curve.Points[1 + multiplier], _Curve.Points[2 + multiplier], steps);

                                Point lerp3 = LerpMath.Lerp(_Curve.Points[2 + multiplier], _Curve.Points[3 + multiplier], steps);

                                Point lerp4 = LerpMath.Lerp(lerp1, lerp2, steps);
                                Point lerp5 = LerpMath.Lerp(lerp2, lerp3, steps);

                                Point lerp6 = LerpMath.Lerp(lerp4, lerp5, steps);

                                lerpList.Add(lerp6);
                            }
                        }
                        else
                        {
                            lerpList.Add(LerpMath.Lerp(_Curve.Points[multiplier], _Curve.Points[multiplier + 1], steps));
                        }

                        if (scale < 0.5)
                        {
                            steps += 0.05;
                        }
                        else
                        {
                            steps += 0.1;
                        }
                    }
                }
                catch (Exception) {
                    //throw;
                }
            }

            return(lerpList.ToList());
        }