Пример #1
0
//-----------------------------------------------------------------------
float PUDynamicAttributeCurved::getValue (float x)
{
    switch (_interpolationType)
    {
    case IT_LINEAR:
        {
            // Search the interval in which 'x' resides and apply linear interpolation
            if (_controlPoints.empty())
                return 0;

            ControlPointList::iterator it1 = findNearestControlPointIterator(x);
            ControlPointList::iterator it2 = it1 + 1;
            if (it2 != _controlPoints.end())
            {
                // Calculate fraction: y = y1 + ((y2 - y1) * (x - x1)/(x2 - x1))
                return (*it1).y + (((*it2).y - (*it1).y) * (x - (*it1).x)/((*it2).x - (*it1).x));
            }
            else
            {
                return (*it1).y;
            }
        }
        break;

    case IT_SPLINE:
        {
            // Fit using spline
            if (_spline.getNumPoints() < 1)
                return 0;

            float fraction = x / _range;
            return (_spline.interpolate(fraction < 1.0f ? fraction : 1.0f)).y;
        }
        break;
    }

    return 0;
}
Пример #2
0
veReal veValueCurved::getValue(veReal x)
{
    switch (_iType)
    {
        case InterpolationType::IT_LINEAR:
        {
            // Search the interval in which 'x' resides and apply linear interpolation
            if (_cpList.empty())
                return 0.0f;
            
            ControlPointList::iterator it1 = findNearestControlPointIterator(x);
            ControlPointList::iterator it2 = it1 + 1;
            if (it2 != _cpList.end())
            {
                // Calculate fraction: y = y1 + ((y2 - y1) * (x - x1)/(x2 - x1))
                return (*it1).y() + (((*it2).y() - (*it1).y()) * (x - (*it1).x())/((*it2).x() - (*it1).x()));
            }
            else
            {
                return (*it1).y();
            }
        }
            break;
            
        case InterpolationType::IT_SPLINE:
        {
            // Fit using spline
            if (_spline.getNumPoints() < 1)
                return 0.0f;
            
            float fraction = x / _range;
            return (_spline.interpolate(fraction < 1.0f ? fraction : 1.0f)).y();
        }
            break;
    }
    
    return 0.0f;
}