summaryrefslogtreecommitdiff
path: root/imgtest/src/ofApp.cpp
blob: 3f33d8d0e14f87fdba80283c88a1c83c41b77b22 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "ofApp.h"
#include "glew.h"

//--------------------------------------------------------------
void ofApp::setup(){

	std::string filename;

	float speedscale=0.999;
	float overlapscale=0.3;
	float transitionscale=0.6;

	if (arguments.size()>1){
		filename=arguments.at(1);
	}
	else filename="jukebox_1.JPG"; //"tile-grid-png-6.png"; // //hubble_Orion_nebula.tif"; //

	float t=ofGetElapsedTimef();
	if (i1.load(filename)){
		ofLogNotice() << "Loaded : "<<filename<< " in "<<(ofGetElapsedTimef()-t)<<" seconds.";
	
		ofLogNotice() << i1.getWidth() << " x " << i1.getHeight();

		//i1 is 2272 x 1704 or +- 1136 x 852
		//i2 is 454 x 340 scaled
		//i1.init(ofPoint(30,-20),0.2,0,speedscale,transitionscale);
		i1.init(ofPoint(0,0),overlapscale,0,speedscale,transitionscale);
	}
	else ofLogNotice() << "Could not load : "<<filename;

	i2.load("jukebox_2.JPG"); //"tile-grid-png-6.png"); //
	i2.init(ofPoint(-400,250),0.2,0,speedscale,transitionscale);
	i2.init(ofPoint(0,0),overlapscale,0,speedscale,transitionscale);
	i1.link=&i2;

	i3.load("jukebox_3.JPG"); //"tile-grid-png-6.png"); //
	i3.init(ofPoint(500,200),0.2,0,speedscale,transitionscale);
	//i3.init(ofPoint(0,0),overlapscale,0,speedscale,transitionscale);
	i2.link=&i3;

	i3.link=&i1;

	viewpoint.resetTransform();
	viewpoint.setFov(60);
	viewpoint.setFarClip(10000.0f);

	startTime=ofGetElapsedTimef();
	timescaling=.01;

	currentImage=&i1;
	currentImage->start();

	currentFrame=0;

}

//--------------------------------------------------------------
void ofApp::update(){

	std::stringstream strm;
	strm << "fps: " << ofGetFrameRate();
	ofSetWindowTitle(strm.str());


	if (currentImage->update()){ //if returns true, switch images
		currentImage=currentImage->link;
		currentImage->start();
		ofLogNotice() << "Switched images";
		currentFrame=0;
		//viewpoint.resetTransform(); //or we get a glitch for no apparent reason, or not
		currentImage->update(); 
	} 

	//viewpoint misbehaves the first frame it is moved.

}

//--------------------------------------------------------------	
void ofApp::draw(){
	
	//viewpoint.begin();

	float camera_throw= 0.6667; //the ratio of z distance to x width


	glMatrixMode ( GL_MODELVIEW );
	glLoadIdentity ( );
	gluLookAt( currentImage->getTransform().x,
				currentImage->getTransform().y, //	 i1.linkPos.y+(xform.y*intervalpoint),
				currentImage->getWidth()*camera_throw*currentImage->getScale()		, 
				currentImage->getTransform().x,
				 currentImage->getTransform().y, //	 i1.linkPos.y+(xform.y*intervalpoint),
				0, 
				0,1,0);	

	//if (currentFrame>0) {
		ofBackground(0,0,0);
		currentImage->drawChain();
	//}
	//else {
		//ofSetColor(255,255,255);
		//ofDrawRectangle(-100,-100,200,200);
		//currentImage->link->drawChain(); //attempted hack
	//}

/*
	printf(">>Draw %i %f complete %f,%f at %f from %f,%f,%f\n",
		currentFrame,
		currentImage->transition,
		currentImage->linkPos.x,
		currentImage->linkPos.y,
		currentImage->getScale(),
		currentImage->getTransform().x,
		currentImage->getTransform().y,
		currentImage->getWidth()*camera_throw*currentImage->getScale()
		);
*/
	

/*
	viewpoint.setPosition(currentImage->getTransform().x,
						  currentImage->getTransform().y, //	 i1.linkPos.y+(xform.y*intervalpoint),
					      currentImage->getWidth()*camera_throw*currentImage->getScale());
*/
	//ofCamera DOES NOT WORK, it produces spurious coordinates the first frame it is moved
	

	/*

		
	ofLogNotice() << "Camera at: "<<ofToString(viewpoint.getPosition().x)
				<<","<<ofToString(viewpoint.getPosition().y)
				<<","<<ofToString(viewpoint.getPosition().z);
	*/

	//viewpoint.end();

/*
	if (!(i1.transition<1.0)){
		ofLogNotice() << "Finished ";

		ofBaseApp::exit();
		std::exit(EXIT_FAILURE);
	}
	
	
	so far so good

	now:

	-rotation
	-moving seamlessly between segments - exponential zoom
	-blending movment between segments
	-interface for authoring
	-things to do with it

	
	

	if (currentFrame<2) {
		grab.grabScreen(0, 0 , ofGetWidth(), ofGetHeight());
		char buf[50];
		sprintf(buf,"zeroimg%04i.png",currentFrame);
		grab.save(buf);
	}
	*/

	currentFrame++;
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 

}