Skip to content

Instantly share code, notes, and snippets.

@Joeppie
Forked from kylemcdonald/CameraSphere.cpp
Created January 31, 2018 15:41
Show Gist options
  • Save Joeppie/084ed75e6c20db1a383494d02eb289dd to your computer and use it in GitHub Desktop.
Save Joeppie/084ed75e6c20db1a383494d02eb289dd to your computer and use it in GitHub Desktop.

Revisions

  1. @kylemcdonald kylemcdonald created this gist Oct 30, 2017.
    69 changes: 69 additions & 0 deletions CameraSphere.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    #include "ofMain.h"

    class ofApp : public ofBaseApp {
    public:
    ofImage img;
    ofEasyCam cam;
    ofSpherePrimitive sphere;
    float zoom = 0.5;
    float xoff = 0;
    float yoff = 0;

    void setup() {
    sphere.set(1000, 128);
    img.load("pano.jpg");
    }
    void update() {
    ofTextureData& tdata = img.getTexture().getTextureData();
    bool normalized = (tdata.textureTarget == GL_TEXTURE_RECTANGLE_ARB);
    float w = tdata.tex_t * (1/zoom);
    float h = tdata.tex_u * (1/zoom);
    if(w > 2 * h) {
    h = w / 2;
    } else {
    w = h * 2;
    }
    float x = (xoff * w + tdata.tex_t - w) / 2;
    float y = (yoff * h + tdata.tex_u - h) / 2;
    sphere.mapTexCoords(x, y, x+w, y+h);
    }
    void draw() {
    ofEnableDepthTest();
    cam.begin();
    img.getTexture().bind();
    sphere.draw();
    img.getTexture().unbind();
    cam.end();
    }
    void keyPressed(int key) {
    if(key == '=') {
    cam.setFov(cam.getFov() - 1);
    }
    if(key == '-') {
    cam.setFov(cam.getFov() + 1);
    }
    if(key == '[') {
    zoom *= .99;
    }
    if(key == ']') {
    zoom /= .99;
    }
    if(key == OF_KEY_LEFT) {
    xoff -= 0.01;
    }
    if(key == OF_KEY_RIGHT) {
    xoff += 0.01;
    }
    if(key == OF_KEY_UP) {
    yoff -= 0.01;
    }
    if(key == OF_KEY_DOWN) {
    yoff += 0.01;
    }
    }
    };

    int main() {
    ofSetupOpenGL(1280, 720, OF_WINDOW);
    ofRunApp(new ofApp());
    }