diff options
| author | Tim Redfern <tim@getdrop.com> | 2017-10-27 16:34:53 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2017-10-27 16:34:53 +0100 |
| commit | 4d3ec3d2ef37102e5b233704deb4cd7af727e1a3 (patch) | |
| tree | c5cd84a3dca801dc13c6ad2667f2c80090dd4cde /gui | |
| parent | 3426aeebba3ec51e6b6bf7e1f0de947c97f97a36 (diff) | |
moving images with no glitches
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/chainImage.cpp | 61 | ||||
| -rw-r--r-- | gui/src/chainImage.h | 7 | ||||
| -rw-r--r-- | gui/src/chainImageSet.cpp | 16 |
3 files changed, 64 insertions, 20 deletions
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp index 7053961..3c5f408 100644 --- a/gui/src/chainImage.cpp +++ b/gui/src/chainImage.cpp @@ -14,6 +14,10 @@ void chainImage::init(ofPoint _linkPos,float _linkScale,float _linkRot){ linkScale=_linkScale; linkRot=_linkRot; setAnchorPercent(0.5,0.5); + + dragPos=ofPoint(0,0); + dragRot=0; + dragScale=0; } void chainImage::start(bool reverse){ @@ -44,25 +48,33 @@ void chainImage::updateRotationTimeline(){ //rotation curve always starts at the origin as it's relative to where we have already rotated to rotationTimeline.addVertex(0,0); + //float dR; + + //if (abs(link->linkRot-linkRot)>abs((link->linkRos+360.0f)-linkRot)){ + // dR=link->linkRot; + //} + //else dR=link->linkRos+360.0f; + //try to choose the shortest + ofPoint cp1,cp2,p; - if(linked->linkRot==0.0f){ //hmm, shouldn't use float equality + if(linked->getLinkRot()==0.0f){ //hmm, shouldn't use float equality cp1=ofPoint(ROTATION_BEZIER_FRACTION, 0); } else { - float slope=link->linkRot-linked->linkRot; + float slope=link->getLinkRot()-linked->getLinkRot(); cp1=ofPoint(ROTATION_BEZIER_FRACTION,slope/ROTATION_BEZIER_FRACTION); } - if(link->linkRot==link->link->linkRot){ //hmm, shouldn't use float equality - cp2=ofPoint(1.0f-ROTATION_BEZIER_FRACTION, link->linkRot); + if(link->getLinkRot()==link->link->getLinkRot()){ //hmm, shouldn't use float equality + cp2=ofPoint(1.0f-ROTATION_BEZIER_FRACTION, link->getLinkRot()); } else { - float slope=link->link->linkRot-linkRot; - cp2=ofPoint(1.0f-ROTATION_BEZIER_FRACTION, link->linkRot); + float slope=link->link->getLinkRot()-getLinkRot(); + cp2=ofPoint(1.0f-ROTATION_BEZIER_FRACTION, link->getLinkRot()); } - p=ofPoint(1.0f, link->linkRot); + p=ofPoint(1.0f, link->getLinkRot() ); rotationTimeline.bezierTo(cp1,cp2,p); @@ -76,19 +88,19 @@ int chainImage::updateOutput(float decayRatio){ path.clear(); - path.addVertex(linkPos); + path.addVertex(getLinkPos()); //path.addVertex(linkPos+(link->linkPos*linkScale)); ofPoint rotated_destination=ofPoint( - (link->linkPos.x*cos(linkRot*(PI/180)))-(link->linkPos.y*sin(linkRot*(PI/180))), - (link->linkPos.y*cos(linkRot*(PI/180)))+(link->linkPos.x*sin(linkRot*(PI/180))) + (link->getLinkPos().x*cos(getLinkRot()*(PI/180)))-(link->getLinkPos().y*sin(getLinkRot()*(PI/180))), + (link->getLinkPos().y*cos(getLinkRot()*(PI/180)))+(link->getLinkPos().x*sin(getLinkRot()*(PI/180))) ); - ofPoint destination=linkPos+(rotated_destination*linkScale); - ofPoint previous=linkPos+(rotated_destination*linkScale*(1.0f-BEZIER_IN)); + ofPoint destination=getLinkPos()+(rotated_destination*getLinkScale()); + ofPoint previous=getLinkPos()+(rotated_destination*getLinkScale()*(1.0f-BEZIER_IN)); path.bezierTo( - linkPos.x*(1.0f+BEZIER_OUT),linkPos.y*(1.0f+BEZIER_OUT), + getLinkPos().x*(1.0f+BEZIER_OUT),getLinkPos().y*(1.0f+BEZIER_OUT), previous.x,previous.y, destination.x,destination.y); @@ -107,7 +119,7 @@ int chainImage::updateOutput(float decayRatio){ //n = log(decayRatio,1/256) - transition=-(scale-linkScale)/(linkScale-(linkScale*link->linkScale)); + transition=-(scale-getLinkScale())/(getLinkScale()-(getLinkScale()*link->getLinkScale())); //transition=min(1.0f,((float)framecount)/totalframes); /* @@ -118,11 +130,11 @@ int chainImage::updateOutput(float decayRatio){ transition); */ - if (scale>linkScale){ + if (scale>getLinkScale()){ transition = 0.0f; return SWITCH_REVERSE; } - if (scale>linkScale*link->linkScale){ + if (scale>getLinkScale()*link->getLinkScale()){ return SWITCH_NONE; } transition = 1.0f; @@ -153,8 +165,17 @@ float chainImage::getRotation(){ //linkRot is no longer seen //return linkRot+(transition*link->linkRot); //linkRot+ - return linkRot+rotationTimeline.getPointAtPercent(transition).y; + return getLinkRot()+rotationTimeline.getPointAtPercent(transition).y; }; +ofPoint chainImage::getLinkPos(){ + return linkPos+dragPos; +} +float chainImage::getLinkRot(){ + return linkRot+dragRot; +} +float chainImage::getLinkScale(){ + return linkScale*(1.0f+dragScale); +} void chainImage::makeThumbnail(){ thumbnail.setUseTexture(false); thumbnail=(const ofImage)*this; //copy the ofImage itself @@ -225,11 +246,11 @@ void chainImage::drawChain(float fadeIn,bool additive,float intensity,float zoom glPopMatrix(); - glTranslatef(linkPos.x,linkPos.y,0); + glTranslatef(getLinkPos().x,getLinkPos().y,0); - glRotatef(linkRot,0,0,1); + glRotatef(getLinkRot(),0,0,1); - glScalef(linkScale,linkScale,linkScale); + glScalef(getLinkScale(),getLinkScale(),getLinkScale()); //ofEnableAlphaBlending(); glEnable(GL_BLEND); diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h index 984b0d6..f391db8 100644 --- a/gui/src/chainImage.h +++ b/gui/src/chainImage.h @@ -47,6 +47,9 @@ class chainImage : public ofImage{ ofVec3f getTransform(); float getScale(); float getRotation(); + ofPoint getLinkPos(); + float getLinkRot(); + float getLinkScale(); void updateRotationTimeline(); @@ -64,8 +67,12 @@ class chainImage : public ofImage{ chainImage *linked; ofPoint linkPos; + ofPoint dragPos; float linkScale; + float dragScale; float linkRot; + float dragRot; + std::string filename; float transition; diff --git a/gui/src/chainImageSet.cpp b/gui/src/chainImageSet.cpp index 7e6e351..dd43fec 100644 --- a/gui/src/chainImageSet.cpp +++ b/gui/src/chainImageSet.cpp @@ -380,14 +380,23 @@ void chainImageSet::mouseDragged(int x, int y, int button){ switch (button){ case OF_MOUSE_BUTTON_1: dragPoint=ofPoint(x-clickPoint.x,y-clickPoint.y)*((*selected)->getHeight()/ofGetWindowHeight()); + if (images.size()){ + (*selected)->dragPos=dragPoint; + } break; case OF_MOUSE_BUTTON_2: //alt-click dragRotate=((clickPoint.x-x)/((*selected)->thumbnail.getWidth()))*180.0f; + if (images.size()){ + (*selected)->dragRot=dragRotate; + } break; case OF_MOUSE_BUTTON_3: //control-click dragScale=(y-clickPoint.y)/((*selected)->thumbnail.getHeight()); + if (images.size()){ + (*selected)->dragScale=dragScale; + } //if (dragScale*selected->linkScale<0.15){ // dragScale=0.15/selected->linkScale; //} @@ -406,10 +415,15 @@ void chainImageSet::mouseReleased(int x, int y, int button){ if (images.size()){ (*selected)->linkPos+=dragPoint; dragPoint=ofPoint(0,0); + (*selected)->dragPos=dragPoint; + (*selected)->linkScale*=(1.0f+dragScale); dragScale=0.0f; + (*selected)->dragScale=dragScale; + (*selected)->linkRot+=dragRotate; dragRotate=0.0f; + (*selected)->dragRot=dragRotate; } } @@ -489,6 +503,8 @@ void chainImageSet::updateOutput(){ (*images.begin())->linked=&(*(*images.rbegin())); (*images.rbegin())->setUseTexture(true); + (*images.rbegin())->linkRot=(*images.rbegin())->linked->linkRot; + (*images.rbegin())->linkScale=(*images.rbegin())->linked->linkScale; printf("Linked: %s -> %s <- %s\n", (*images.rbegin())->filename.c_str(), |
