Example #1
0
        public void RemoveV(double u)
        {
            var state = State;

            state.Table.Remove(u);
            SplineInterpolator.UpdateTangents(state.Table.ToList());

            TriggerChangedEventIfEnabled();
        }
Example #2
0
        public void AddOrUpdateV(double u, VDefinition key)
        {
            var state = State;

            state.Table[u] = key.Clone();
            SplineInterpolator.UpdateTangents(state.Table.ToList());

            TriggerChangedEventIfEnabled();
        }
Example #3
0
        public double GetSampledValue(double u)
        {
            var state = State;

            if (state.Table.Count < 1 || double.IsNaN(u) || double.IsInfinity(u))
            {
                return(0.0);
            }

            double offset  = 0.0;
            double mappedU = u;
            var    first   = state.Table.First();
            var    last    = state.Table.Last();

            if (u <= first.Key)
            {
                state.PreCurveMapper.Calc(u, state.Table, out mappedU, out offset);
            }
            else if (u >= last.Key)
            {
                state.PostCurveMapper.Calc(u, state.Table, out mappedU, out offset);
            }

            double resultValue = 0.0;

            if (mappedU <= first.Key)
            {
                resultValue = offset + first.Value.Value;
            }
            else if (mappedU >= last.Key)
            {
                resultValue = offset + last.Value.Value;
            }
            else
            {
                //interpolate
                var a = state.Table.Last(e => e.Key <= mappedU);
                var b = state.Table.First(e => e.Key > mappedU);

                if (a.Value.OutType == VDefinition.Interpolation.Constant)
                {
                    resultValue = offset + ConstInterpolator.Interpolate(a, b, mappedU);
                }
                else if (a.Value.OutType == VDefinition.Interpolation.Linear && b.Value.OutType == VDefinition.Interpolation.Linear)
                {
                    resultValue = offset + LinearInterpolator.Interpolate(a, b, mappedU);
                }
                else
                {
                    resultValue = offset + SplineInterpolator.Interpolate(a, b, mappedU);
                }
            }

            return(resultValue);
        }
Example #4
0
        public void MoveV(double u, double newU)
        {
            var state = State;

            if (!state.Table.ContainsKey(u))
            {
                Logger.Warn("Tried to move a non-existing keyframe from {0} to {1}", u, newU);
                return;
            }
            var key = state.Table[u];

            state.Table.Remove(u);
            state.Table[newU] = key;
            SplineInterpolator.UpdateTangents(state.Table.ToList());

            TriggerChangedEventIfEnabled();
        }