Exemple #1
0
KeyFrame Curve::setKeyFrameDerivatives(double left, double right,int index,int* newIndex)
{
    bool evaluateAnimation = false;
    KeyFrame ret;
    {
        
        QWriteLocker l(&_imp->_lock);
        KeyFrameSet::iterator it = atIndex(index);
        assert(it != _imp->keyFrames.end());
        
        if (left != it->getLeftDerivative() || right != it->getRightDerivative()) {
            KeyFrame newKey(*it);
            newKey.setLeftDerivative(left);
            newKey.setRightDerivative(right);
            it = addKeyFrameNoUpdate(newKey).first;
            it = evaluateCurveChanged(DERIVATIVES_CHANGED,it);
            evaluateAnimation = true;
            
        }
        if (newIndex) {
            *newIndex = std::distance(_imp->keyFrames.begin(),it);
        }
        ret = *it;
    }
    if (evaluateAnimation && _imp->owner) {
        _imp->owner->evaluateAnimationChange();
    }
    return ret;
    
}
Exemple #2
0
KeyFrame Curve::setKeyFrameInterpolation(Natron::KeyframeType interp,int index,int* newIndex)
{
    
    bool evaluateAnimation = false;
    KeyFrame ret;
    {
        QWriteLocker l(&_imp->_lock);
        KeyFrameSet::iterator it = atIndex(index);
        assert(it != _imp->keyFrames.end());
        
        ///if the curve is a string_curve or bool_curve the interpolation is bound to be constant.
        if ((_imp->type == CurvePrivate::STRING_CURVE || _imp->type == CurvePrivate::BOOL_CURVE ||
             _imp->type == CurvePrivate::INT_CURVE_CONSTANT_INTERP) && interp != Natron::KEYFRAME_CONSTANT) {
            return *it;
        }
        
        
        if (interp != it->getInterpolation()) {
            it = setKeyframeInterpolation_internal(it, interp);
        }
        if (newIndex) {
            *newIndex = std::distance(_imp->keyFrames.begin(),it);
        }
        ret = *it;
    }
    if (evaluateAnimation && _imp->owner) {
        _imp->owner->evaluateAnimationChange();
    }
    return ret;
}
Exemple #3
0
KeyFrame Curve::setKeyFrameValueAndTime(double time,double value,int index,int* newIndex)
{
    bool evaluateAnimation = false;
    KeyFrame ret;
    {
        QWriteLocker l(&_imp->_lock);
        KeyFrameSet::iterator it = atIndex(index);
        if (it == _imp->keyFrames.end()) {
            QString err = QString("No such keyframe at index %1").arg(index);
            throw std::invalid_argument(err.toStdString());
        }
        
        bool setTime = (time != it->getTime());
        bool setValue = (value != it->getValue());
        
        if (setTime || setValue) {
            it = setKeyFrameValueAndTimeNoUpdate(value,time, it);
            it = evaluateCurveChanged(KEYFRAME_CHANGED,it);
            evaluateAnimation = true;
        }
        if (newIndex) {
            *newIndex = std::distance(_imp->keyFrames.begin(),it);
        }
        ret = *it;
        
    }
    if (evaluateAnimation && _imp->owner) {
        _imp->owner->evaluateAnimationChange();
    }
    return ret;

}
Exemple #4
0
bool Curve::getKeyFrameWithIndex(int index, KeyFrame* k) const
{
    assert(k);
    QReadLocker l(&_imp->_lock);
    if (index >= (int)_imp->keyFrames.size()) {
        return false;
    }
    *k = *atIndex(index);
    return true;
}
Exemple #5
0
void Apsis::Map::lift(float amount) {
  // Just the one tile is raised at all corners
  Apsis::Tile* tile;

  tile = atIndex(_x, _z);
  for (unsigned int i = 0; i < 4; i++) {
    tile->cornerHeight(i, tile->cornerHeight(i) + amount);
    tile->firstControl(i, tile->firstControl(i) + amount);
    tile->secondControl(i, tile->secondControl(i) + amount);
  }
}
Foam::labelList Foam::equationReader::findMaxOperation
(
    const labelList& opLvl,
    const labelList& indices
) const
{
    label maxOpLvl(-1);
    label atIndex(-1);
    labelList returnMe(indices.size());
    bool groupDone(false);

    forAll(indices, i)
    {
        if (opLvl[indices[i]] > maxOpLvl)
        {
            atIndex = 0;
            returnMe[0] = indices[i];
            if (i > 0)
            {
                atIndex++;
                returnMe[0] = indices[i - 1];
                returnMe[1] = indices[i];
            }
            groupDone = false;
            maxOpLvl = opLvl[indices[i]];
        }
        else if
        (
            (
                (opLvl[indices[i]] == maxOpLvl)
             || (opLvl[indices[i]] == 0)
            )
         && !groupDone
        )
        {
            atIndex++;
            returnMe[atIndex] = indices[i];
        }
        else if ((opLvl[indices[i]] < maxOpLvl) && (opLvl[indices[i]] != 0))
        {
            groupDone = true;
        }
    }
    returnMe.setSize(atIndex + 1);
    return returnMe;
}
Foam::labelList Foam::equationReader::findMaxParenthesis
(
    const labelList& parenthesisList,
    const labelList& equationIndices
) const
{
    labelList returnMe(equationIndices.size());
    label currentMax(-1);
    label atIndex(0);
    bool groupDone(false);

    forAll(equationIndices, i)
    {
        if (mag(parenthesisList[equationIndices[i]]) > currentMax)
        {
            groupDone = false;
            atIndex = 0;
            currentMax = mag(parenthesisList[equationIndices[i]]);
            returnMe[atIndex] = equationIndices[i];
        }
        else if
        (
            (mag(parenthesisList[equationIndices[i]]) == currentMax)
         && (!groupDone)
        )
        {
            atIndex++;
            returnMe[atIndex] = equationIndices[i];
        }
        else if (mag(parenthesisList[equationIndices[i]]) < currentMax)
        {
            groupDone = true;
        }
    }
    returnMe.setSize(atIndex + 1);
    return returnMe;
}
Exemple #8
0
void Curve::removeKeyFrameWithIndex(int index)
{
    QWriteLocker l(&_imp->_lock);
    removeKeyFrame(atIndex(index));
}
Exemple #9
0
void Apsis::Map::raise(float amount) {
  // Every tile this touches is raised a little bit
  Apsis::Tile* tile;
  float old_height;

  if (_x != _width && _z != _height) {
    // Bottom Right
    tile = atIndex(_x, _z);
    old_height = tile->cornerHeight(Apsis::TOP_LEFT);
    tile->cornerHeight(Apsis::TOP_LEFT, old_height + amount);
  }

  if (_x != 0 && _z != _height) {
    // Bottom Left
    tile = atIndex(_x-1, _z);
    old_height = tile->cornerHeight(Apsis::TOP_RIGHT);
    tile->cornerHeight(Apsis::TOP_RIGHT, old_height + amount);
  }

  if (_x != _width && _z != 0) {
    // Top Right
    tile = atIndex(_x, _z-1);
    old_height = tile->cornerHeight(Apsis::BOT_LEFT);
    tile->cornerHeight(Apsis::BOT_LEFT, old_height + amount);
  }

  if (_x != 0 && _z != 0) {
    // Top Left
    tile = atIndex(_x-1, _z-1);
    old_height = tile->cornerHeight(Apsis::BOT_RIGHT);
    tile->cornerHeight(Apsis::BOT_RIGHT, old_height + amount);
  }

  // Regenerate curve points along this point

  // Horizontal

  Point* line;
  Point* first;
  Point* second;
  line = new Point[_width+1];
  first = new Point[_width];
  second = new Point[_width];

  for (unsigned int x = 0; x < _width; x++) {
    tile = atIndex(x, _z);
    line[x].x = (float)x;
    line[x].y = tile->cornerHeight(Apsis::TOP_LEFT);
    line[x].z = 0.0f; // does not matter
  }
  line[_width].x = (float)_width;
  line[_width].y = tile->cornerHeight(Apsis::TOP_RIGHT);
  line[_width].z = 0.0f;

  controlPoints(line, first, second, _width+1);

  // Pass control points back to tiles

  for (unsigned int x = 0; x < _width; x++) {
    tile = atIndex(x, _z);
    tile->firstControl(Apsis::TOP_LEFT, first[x].y);
    tile->secondControl(Apsis::TOP_LEFT, second[x].y);
    if (_z != 0) {
      tile = atIndex(x, _z-1);
      tile->firstControl(Apsis::BOT_RIGHT, first[x].y);
      tile->secondControl(Apsis::BOT_RIGHT, second[x].y);
    }
  }

  delete [] first;
  delete [] second;
  delete [] line;

  // Vertical

  line = new Point[_height+1];
  first = new Point[_height+1];
  second = new Point[_height+1];

  for (unsigned int z = 0; z < _height; z++) {
    tile = atIndex(_x, z);
    line[z].x = (float)z; // does not matter
    line[z].y = tile->cornerHeight(Apsis::TOP_LEFT);
    line[z].z = 0.0f;
  }
  line[_height].x = (float)_height;
  line[_height].y = tile->cornerHeight(Apsis::BOT_LEFT);
  line[_height].z = 0.0f;

  controlPoints(line, first, second, _height+1);

  // Pass control points back to tiles

  for (unsigned int z = 0; z < _height; z++) {
    tile = atIndex(_x, z);
    tile->firstControl(Apsis::BOT_LEFT, first[z].y);
    tile->secondControl(Apsis::BOT_LEFT, second[z].y);
    if (_x != 0) {
      tile = atIndex(_x-1, z);
      tile->firstControl(Apsis::TOP_RIGHT, first[z].y);
      tile->secondControl(Apsis::TOP_RIGHT, second[z].y);
    }
  }

  delete [] first;
  delete [] second;
  delete [] line;
}