summaryrefslogtreecommitdiff
path: root/imgtest/src/ofApp.h
blob: bde4958cba947e2f299eb24b277af85137c28971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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;

};