Mercurial > hg > soniczoomios
diff grid.mm @ 46:1e266647840d
beta 2.
interpolation movement , smoothing (crap) and timbre only.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 24 Apr 2013 17:58:08 +0100 |
parents | c2fffc8ea84d |
children | 0d3a993405e4 |
line wrap: on
line diff
--- a/grid.mm Tue Apr 23 18:29:55 2013 +0100 +++ b/grid.mm Wed Apr 24 17:58:08 2013 +0100 @@ -428,7 +428,9 @@ } //-------------------------------------------------------------- void Grid::update(){ // ? - + if(automatedMovementInProgress){ + continueInterpolatedAnimation(); + } } //-------------------------------------------------------------- @@ -449,9 +451,9 @@ cout << "DOUBLE tapped preset: " << tappedPreset->name << "\n"; //TODO interpolate to this! exciting! - setCoord(tappedPreset->coordinates); // should just go there and do all the calcs - ((testApp *)ofGetAppPtr())->setAllGUISliders(getParams()); - eventLogger.logEvent(PRESET_DOUBLE_TAPPED, getCoord(), scale); + + startInterpolatedAnimation(tappedPreset->coordinates); + eventLogger.logEvent(PRESET_DOUBLE_TAPPED, tappedPreset->coordinates, scale); } @@ -461,7 +463,51 @@ // nothing ? } } +//----------------- +void Grid::startInterpolatedAnimation(TwoVector endCoordinate){ + automatedMovementInProgress = true; + + framesRemaining = PRESET_INTERP_TIME; + + startInterpParams = calculateParamsFromCoord(centre); + endInterpParams = calculateParamsFromCoord(endCoordinate); + endInterpCoord = endCoordinate; +} +//----------------- +void Grid::continueInterpolatedAnimation(){ + + framesRemaining--; + if(framesRemaining <= 0){ + //finished + // set position to preset + centre = endInterpCoord; + + //will do snapping and checking + viewWasChanged(); + // update all the sliders and shit + + ((testApp *)ofGetAppPtr())->setAllGUISliders(getParams()); + // set flag in testapp + automatedMovementInProgress = false; + return; + } + // calculate next step + TwoVector moveVector = (endInterpCoord - centre)*(1/(float)framesRemaining); + + centre = centre + moveVector; + topLeft.x = centre.x - size.x/2; + topLeft.y = centre.y - size.y/2; + + float frac = (float)framesRemaining/(float)PRESET_INTERP_TIME; + + vector<int> currentParams = interpVector( startInterpParams,endInterpParams, frac); + + ((testApp *)ofGetAppPtr())->setAllGUISliders(currentParams); + + eventLogger.logEvent(SCROLL,getCoord(),getScale()); + +} //-------------------------------------------------------------- void Grid::move(TwoVector moveP){ @@ -479,6 +525,17 @@ } //-------------------------------------------------------------- +// move the grid to a point (coordinate rather than pixel value) without triggering calculations +void Grid::animateTo(TwoVector point){ + + centre = point; + topLeft.x = centre.x - size.x/2; + topLeft.y = centre.y - size.y/2; + + eventLogger.logEvent(SCROLL, getCoord(), scale); // TODO not *really* a user scroll... + +} +//-------------------------------------------------------------- void Grid::zoom(float factor){ if(snapped)centre = (centre + snapCentre)*0.5; // clunky @@ -515,7 +572,8 @@ // TODO just in case we're freezing something // snapping actually change centre centre = snapCentre; - + topLeft.x = centre.x - size.x/2; + topLeft.y = centre.y - size.y/2; } //-------------------------------------------------------------- Preset * Grid::getClosestPresetOf(vector<Preset *> somepresets){