Ejemplo n.º 1
0
        public PicViewer()
        {
            InitializeComponent();
            DoubleBuffered = true;

            Font = new Font("Tahoma", 8.25f, FontStyle.Regular);
            MinScale = minZoom;
            MaxScale = maxZoom;
            CurrentScale = 1.0f;

            var ck = new Curve();
            ck.Add(0.0f, 1.0f);
            ck.Add(0.75f, 3.0f);
            ck.Add(1.0f, 6.0f);
            ZoomCurve = ck;
        }
Ejemplo n.º 2
0
        public static float CatRomEval(Curve curve, float t)
        {
            if (curve == null || curve.Keys.Count == 0)
            {
                return 0.0f;
            }

            int i2 = 0;
            foreach (var a in curve.Keys)
            {
                if (t < a.Time)
                {
                    break;
                }

                i2++;
            }

            if (i2 == 0)
            {
                return curve.Keys[0].Value;
            }

            if (i2 == curve.Keys.Count)
            {
                return curve.Keys[curve.Keys.Count - 1].Value;
            }

            int i1 = i2 - 1;

            // Previous point if it exists, otherwise point opposite first from second:
            // Four points are:  prev-first-second-next
            float prevValue, nextValue;

            if (i1 == 0)
            {
                prevValue = 2.0f * curve.Keys[i1].Value + (-1.0f * curve.Keys[i2].Value);
            }
            else
            {
                prevValue = curve.Keys[i1 - 1].Value;
            }

            // Previous point if it exists, otherwise point opposite second from first
            int n = i2 + 1;
            if (n >= curve.Keys.Count - 1)
            {
                nextValue = 2.0f * curve.Keys[i2].Value + (-1.0f * curve.Keys[i1].Value);
            }
            else
            {
                nextValue = curve.Keys[n].Value;
            }

            // interp
            t = (t - curve.Keys[i1].Time) / (curve.Keys[i2].Time - curve.Keys[i1].Time);

            return ((-t + 2.0f) * t - 1.0f) * t / 2.0f * prevValue +
                    (((3.0f * t - 5.0f) * t) * t + 2.0f) / 2.0f * curve.Keys[i1].Value +
                    ((-3.0f * t + 4.0f) * t + 1.0f) * t / 2.0f * curve.Keys[i2].Value +
                    ((t - 1.0f) * t * t) / 2.0f * nextValue;
        }