summaryrefslogtreecommitdiff
path: root/imgtest/src/ofApp.h
diff options
context:
space:
mode:
Diffstat (limited to 'imgtest/src/ofApp.h')
-rw-r--r--imgtest/src/ofApp.h171
1 files changed, 171 insertions, 0 deletions
diff --git a/imgtest/src/ofApp.h b/imgtest/src/ofApp.h
new file mode 100644
index 0000000..bde4958
--- /dev/null
+++ b/imgtest/src/ofApp.h
@@ -0,0 +1,171 @@
+#pragma once
+
+#include "ofMain.h"
+
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
+/*
+try to set up coords manually for a sequence of images and prototype a flythrough
+
+a linked list with
+image
+pointer to next image
+position, scale and rotation of next image
+
+
+*/
+
+class chainImage : public ofImage{
+ //todo: threaded image loader
+
+ public:
+ void init(ofPoint _linkPos,float _linkScale,float _linkRot,float _speed=0.99f,float _fadeIn=1.0f){
+ linkPos=_linkPos;
+ linkScale=_linkScale;
+ linkRot=_linkRot;
+ speed=_speed;
+ fadeIn=_fadeIn;
+ setAnchorPoint(getWidth()/2,getHeight()/2);
+ }
+
+ void start(){
+ transition=0.0f;
+ time=ofGetElapsedTimef();
+ setUseTexture(true);
+ scale=linkScale;
+ }
+
+ bool update(){
+ //transition+=(ofGetElapsedTimef()-time)*speed;
+
+ //hard to make the algorithm framerate invariant
+ //if it's exponenential
+
+
+ scale*=speed;
+
+ transition=-(scale-linkScale)/(linkScale-(linkScale*link->linkScale));
+
+ //time=ofGetElapsedTimef();
+ if (scale>linkScale*link->linkScale) return false;
+ else {
+ transition = 1.0f;
+ return true;
+ }
+ }
+ ofVec3f getTransform(){
+ //move from linkPos to link->linkPos
+ /*
+ ofVec3f _scaledTarget = link->linkPos * linkScale;
+ return linkPos + ( _scaledTarget * transition );
+ */
+
+ /*
+ ofPoint o;
+ o = linkPos + ( _scaledTarget * transition );
+ o.x=linkPos.x+((link->linkPos.x/scale)-linkPos.x)*link->linkScale*transition);
+ o.y=linkPos.y+((link->linkPos.y-linkPos.y)*link->linkScale*transition);
+ o.z=linkPos.z+((link->linkPos.z-linkPos.z)*link->linkScale*transition);
+ return o;
+ */
+
+ ///*
+ ofVec3f _scaledTarget = link->linkPos * linkScale;
+
+/*
+ ofVec3f _st = _scaledTarget * transition;
+
+ printf(">>scaledTarget %f,%f,%f %f to %f,%f,%f\n",
+ _scaledTarget.x,
+ _scaledTarget.y,
+ _scaledTarget.z,
+ transition,
+ _st.x,
+ _st.y,
+ _st.z);
+*/
+ return linkPos + ( _scaledTarget * transition );
+ //*/
+ }
+ float getScale(){
+ //rather than each frame scale being an increment of the previous
+ //each frame should be the same ratio from the previous
+ //to get from 0.2 to .04 in 400 frames then 0.2 * (X ^ 400) = 0.04
+ //x = 400 v- 0.2
+ //or, just do it empirically with an exponential factor
+ return scale;
+ //return ofLerp(linkScale,link->linkScale*linkScale,transition);
+ }
+
+
+ void drawChain(){
+
+ glPushMatrix();
+
+ ofDisableAlphaBlending();
+
+ ofSetColor(255,255,255,255);
+
+ draw(0,0,getWidth(),getHeight());
+
+ glTranslatef(linkPos.x,linkPos.y,0);
+
+ glScalef(linkScale,linkScale,linkScale);
+
+ ofEnableAlphaBlending();
+
+ ofSetColor(255,255,255,255*min(1.0,transition/fadeIn));
+
+ link->draw(0,0,link->getWidth(),link->getHeight());
+
+ glPopMatrix();
+ }
+
+ chainImage *link;
+ ofPoint linkPos;
+ float linkScale;
+ float linkRot;
+ float transition;
+ float fadeIn;
+ float speed;
+ float time;
+ float scale;
+
+
+};
+
+class ofApp : public ofBaseApp{
+
+ public:
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed(int key);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void mouseEntered(int x, int y);
+ void mouseExited(int x, int y);
+ void windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+ void gotMessage(ofMessage msg);
+
+ chainImage i1,i2,i3;
+
+ chainImage *currentImage;
+
+ ofImage grab;
+
+ vector<string> arguments;
+
+ ofCamera viewpoint;
+
+ float startTime,timescaling;
+
+ int currentFrame;
+
+};