summaryrefslogtreecommitdiff
path: root/imgtest/src
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2017-08-27 13:19:47 +0100
committerTim Redfern <tim@getdrop.com>2017-08-27 13:19:47 +0100
commitd8a46a6409286b3834bc609e4f34a09d48a8ae58 (patch)
treeba808c1648c908c5363b762541557ea649b12f27 /imgtest/src
initial commit
Diffstat (limited to 'imgtest/src')
-rw-r--r--imgtest/src/main.cpp23
-rw-r--r--imgtest/src/ofApp.cpp224
-rw-r--r--imgtest/src/ofApp.h171
3 files changed, 418 insertions, 0 deletions
diff --git a/imgtest/src/main.cpp b/imgtest/src/main.cpp
new file mode 100644
index 0000000..6eb1c47
--- /dev/null
+++ b/imgtest/src/main.cpp
@@ -0,0 +1,23 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+//========================================================================
+int main(int argc, char *argv[]){
+ ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofApp *app = new ofApp();
+
+ app->arguments = vector<string>(argv, argv + argc);
+
+ ofRunApp(app); // start the app
+
+
+ //60 deg camera
+ //30 60 90 triangle 3 4 5
+ //512 * 4/3 = 683
+
+}
+ \ No newline at end of file
diff --git a/imgtest/src/ofApp.cpp b/imgtest/src/ofApp.cpp
new file mode 100644
index 0000000..3f33d8d
--- /dev/null
+++ b/imgtest/src/ofApp.cpp
@@ -0,0 +1,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){
+
+}
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;
+
+};