diff options
| author | Comment <tim@gray.(none)> | 2014-02-26 10:57:16 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2014-02-26 10:57:16 +0000 |
| commit | 0e436679aa8c09a08e20849f204c969eb2d875b8 (patch) | |
| tree | 2619f53f16c571dc19326d395aa420ceb0a29de7 | |
initial commit
| -rw-r--r-- | basedProject/Makefile | 13 | ||||
| -rw-r--r-- | basedProject/addons.make | 1 | ||||
| -rw-r--r-- | basedProject/bin/data/crosshairs.png | bin | 0 -> 64331 bytes | |||
| -rw-r--r-- | basedProject/bin/data/defaults.xml | 30 | ||||
| -rw-r--r-- | basedProject/bin/data/settings.xml | 12 | ||||
| -rw-r--r-- | basedProject/config.make | 1 | ||||
| -rw-r--r-- | basedProject/src/keyVar.cpp | 63 | ||||
| -rw-r--r-- | basedProject/src/keyVar.h | 36 | ||||
| -rw-r--r-- | basedProject/src/main.cpp | 7 | ||||
| -rw-r--r-- | basedProject/src/mapUtils.cpp | 156 | ||||
| -rw-r--r-- | basedProject/src/mapUtils.h | 20 | ||||
| -rw-r--r-- | basedProject/src/ofApp.cpp | 176 | ||||
| -rw-r--r-- | basedProject/src/ofApp.h | 60 | ||||
| -rw-r--r-- | basedProject/src/viewpoint.cpp | 196 | ||||
| -rw-r--r-- | basedProject/src/viewpoint.h | 66 | ||||
| -rw-r--r-- | crosshairs.svg | 69 | ||||
| -rw-r--r-- | glitcher/Makefile | 13 | ||||
| -rw-r--r-- | glitcher/addons.make | 2 | ||||
| -rw-r--r-- | glitcher/config.make | 1 | ||||
| -rw-r--r-- | glitcher/src/main.cpp | 6 | ||||
| -rw-r--r-- | glitcher/src/ofApp.cpp | 154 | ||||
| -rw-r--r-- | glitcher/src/ofApp.h | 24 |
22 files changed, 1106 insertions, 0 deletions
diff --git a/basedProject/Makefile b/basedProject/Makefile new file mode 100644 index 0000000..7a7fe8b --- /dev/null +++ b/basedProject/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../.. +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/basedProject/addons.make b/basedProject/addons.make new file mode 100644 index 0000000..a66eaad --- /dev/null +++ b/basedProject/addons.make @@ -0,0 +1 @@ +ofxXmlSettings diff --git a/basedProject/bin/data/crosshairs.png b/basedProject/bin/data/crosshairs.png Binary files differnew file mode 100644 index 0000000..e1d2d07 --- /dev/null +++ b/basedProject/bin/data/crosshairs.png diff --git a/basedProject/bin/data/defaults.xml b/basedProject/bin/data/defaults.xml new file mode 100644 index 0000000..e39dc29 --- /dev/null +++ b/basedProject/bin/data/defaults.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<map4> + <view> + <settings x="0.000000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.250000" roll="90.0" targX="0.000000" targY="112.000000" targZ="0.000000" lat="0.000000" lng="0.000000" dolly="500.000000" /> + </view> + <view> + <settings x="0.500000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.250000" roll="90.0" targX="0.000000" targY="112.000000" targZ="0.000000" lat="0.000000" lng="0.000000" dolly="500.000000" /> + </view> + <clip> + <settings file="glow_bars.mov"/> + </clip> + <clip> + <settings file="glow_cracks.mov"/> + </clip> + <clip> + <settings file="shift over.mov"/> + </clip> + <clip> + <settings file="tiger_squares.mov"/> + </clip> + <clip> + <settings file="MadMapper_update.mov"/> + </clip> + <clip> + <settings file="label_animation.mov"/> + </clip> + <clip> + <settings file="label_animation_2.mov"/> + </clip> +</map4> diff --git a/basedProject/bin/data/settings.xml b/basedProject/bin/data/settings.xml new file mode 100644 index 0000000..2a6191e --- /dev/null +++ b/basedProject/bin/data/settings.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<map4> + <view> + <settings x="0.000000" y="0.000000" w="0.333300" h="1.000000" distort="0.000000" fov="17.250000" roll="180.000000" targX="49.487381" targY="32.594791" targZ="0.000000" lat="27.951185" lng="-385.289185" dolly="1557.915527" /> + </view> + <view> + <settings x="0.333300" y="0.000000" w="0.333300" h="1.000000" distort="0.000000" fov="17.250000" roll="180.000000" targX="49.487965" targY="32.594845" targZ="0.000000" lat="31.675091" lng="-717.290039" dolly="1557.917236" /> + </view> + <view> + <settings x="0.666600" y="0.000000" w="0.333300" h="1.000000" distort="0.000000" fov="17.250000" roll="180.000000" targX="49.488358" targY="32.594955" targZ="0.000000" lat="27.952063" lng="-267.794952" dolly="1557.917969" /> + </view> +</map4> diff --git a/basedProject/config.make b/basedProject/config.make new file mode 100644 index 0000000..98bb09c --- /dev/null +++ b/basedProject/config.make @@ -0,0 +1 @@ +OF_ROOT=../../openFrameworks diff --git a/basedProject/src/keyVar.cpp b/basedProject/src/keyVar.cpp new file mode 100644 index 0000000..1bf562a --- /dev/null +++ b/basedProject/src/keyVar.cpp @@ -0,0 +1,63 @@ +/* + * keyvar.cpp + + generalised cushioned keyboard controller + //todo time based rather than onoff to get around keyrepeat issue + */ + +#include "keyVar.h" +#define DEBUG 0 + +void keyVar::set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float _accelTime){ + keyInc=_keyInc; + keyDec=_keyDec; + val=_val; //initial value + speed=_speed; + accel=_accel; + accelTime=_accelTime; + state=0; + timePressed=timeCalc=0; + inc=0; + +} +void keyVar::keyPressed(char _key){ + //need to deal with key repeat: OSX anyway + if (_key==keyInc&&state!=1) { + state=1; + timePressed=timeCalc=ofGetElapsedTimef(); + if (DEBUG) printf("pressed %i:%i\n",_key,ofGetElapsedTimeMillis()); + } + if (_key==keyDec&&state!=-1) { + state=-1; + timePressed=timeCalc=ofGetElapsedTimef(); + if (DEBUG) printf("pressed %i:%i\n",_key,ofGetElapsedTimeMillis()); + } +} +void keyVar::keyReleased(char _key){ + if (_key==keyInc&&state==1) { + state=0; + if (DEBUG) printf("released %i:%i\n",_key,ofGetElapsedTimeMillis()); + } + if (_key==keyDec&&state==-1) { + state=0; + if (DEBUG) printf("released %i:%i\n",_key,ofGetElapsedTimeMillis()); + } +} +float keyVar::getVal(){ + float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime); + //if (state) + val+=pow(segment,accel)*speed*state; //(ofGetElapsedTimef()-timeCalc)* + inc=pow(segment,accel)*speed*state; + timeCalc=ofGetElapsedTimef(); + return val; +} +float keyVar::readVal(){ + return val; +} +float keyVar::getInc(){ + float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime); + return pow(segment,accel)*speed*state; +} +void keyVar::setVal(float _val){ + val=_val; +} diff --git a/basedProject/src/keyVar.h b/basedProject/src/keyVar.h new file mode 100644 index 0000000..043a963 --- /dev/null +++ b/basedProject/src/keyVar.h @@ -0,0 +1,36 @@ +/* + * keyvar.h + * 3dnav + * + * Created by Tim Redfern on 15/12/2011. + * Copyright 2011 __MyCompanyName__. All rights reserved. + * + */ + +#include "ofMain.h" + +class keyVar{ + + public: + void set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float accelTime); + void keyPressed(char _key); + void keyReleased(char _key); + float getVal(); + float getInc(); + void setVal(float _val); + + float readVal(); + float inc; //for syncing + +private: + char keyInc,keyDec; + long timePressed; + long timeCalc; + int state; //up-down-off + float val; + float speed; + float accelTime; + float accel; + + +}; diff --git a/basedProject/src/main.cpp b/basedProject/src/main.cpp new file mode 100644 index 0000000..6fe0e3d --- /dev/null +++ b/basedProject/src/main.cpp @@ -0,0 +1,7 @@ +#include "ofApp.h" + +int main() { + ofSetupOpenGL(4080,768, OF_WINDOW); + //ofSetupOpenGL(1536,288, OF_WINDOW); + ofRunApp(new ofApp()); +} diff --git a/basedProject/src/mapUtils.cpp b/basedProject/src/mapUtils.cpp new file mode 100644 index 0000000..d250c98 --- /dev/null +++ b/basedProject/src/mapUtils.cpp @@ -0,0 +1,156 @@ +/* + * mapUtils.h + * + * Created by Tim Redfern on 20/12/2011. + * global utils for projection mapping + * + */ + +#include "ofMain.h" + +//texture binding with normalised coords +void bindTexture(ofBaseHasTexture &t) { + ofTexture &tex = t.getTextureReference(); + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTexture(ofBaseHasTexture &t) { + t.getTextureReference().unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} +void bindTex(ofTexture &tex) { + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTex(ofTexture &tex) { + tex.unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} +ofPoint distort(ofPoint pt,float d){ + //normalised coords -1..1, d + float r=pow(pow(pow(pt.x,2.0f)+pow(pt.y,2.0f),0.5f),1.0f+d); + float a=atan2f(pt.x,pt.y); + return ofPoint(r*sin(a),r*cos(a)); +}; + +void drawBox(float size) { + // this func just draws a perfectly normal box with some texture coordinates + glBegin(GL_QUADS); + // Front Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, size); // Top Left Of The Texture and Quad + // Back Face + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, -size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, -size); // Bottom Left Of The Texture and Quad + // Top Face + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // Top Right Of The Texture and Quad + // Bottom Face + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, -size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, -size, -size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Right Of The Texture and Quad + // Right face + glTexCoord2f(1.0f, 0.0f); glVertex3f( size, -size, -size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f( size, size, -size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f( size, size, size); // Top Left Of The Texture and Quad + glTexCoord2f(0.0f, 0.0f); glVertex3f( size, -size, size); // Bottom Left Of The Texture and Quad + // Left Face + glTexCoord2f(0.0f, 0.0f); glVertex3f(-size, -size, -size); // Bottom Left Of The Texture and Quad + glTexCoord2f(1.0f, 0.0f); glVertex3f(-size, -size, size); // Bottom Right Of The Texture and Quad + glTexCoord2f(1.0f, 1.0f); glVertex3f(-size, size, size); // Top Right Of The Texture and Quad + glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // Top Left Of The Texture and Quad + glEnd(); +} +void drawBoard(float x,float y,float z) { + glPushMatrix(); + glTranslated(x,y,z); + glBegin(GL_QUADS); + int cx,cz; + for (int i=0;i<8;i++) { + for (int j=0;j<4;j++) { + cx=((i%2)*16)+(j*32)-56; + cz=(i*16)-56; + if ((i==7)&&(j==3)) { //draw special square + glVertex3f(cx+8, 0, cz-8); + glVertex3f(cx+8, 0, cz+8); + glVertex3f(cx+4, 0, cz+4); + glVertex3f(cx+4, 0, cz-4); + + glVertex3f(cx+4, 0, cz+4); + glVertex3f(cx+8, 0, cz+8); + glVertex3f(cx-8, 0, cz+8); + glVertex3f(cx-4, 0, cz+4); + + glVertex3f(cx-4, 0, cz-4); + glVertex3f(cx-4, 0, cz+4); + glVertex3f(cx-8, 0, cz+8); + glVertex3f(cx-8, 0, cz-8); + + glVertex3f(cx+8, 0, cz-8); + glVertex3f(cx+4, 0, cz-4); + glVertex3f(cx-4, 0, cz-4); + glVertex3f(cx-8, 0, cz-8); + } + else { + glVertex3f(cx+8, 0, cz-8); + glVertex3f(cx+8, 0, cz+8); + glVertex3f(cx-8, 0, cz+8); + glVertex3f(cx-8, 0, cz-8); + } + } + } + glEnd(); + glPopMatrix(); +} +void drawCylinder(float r,float h,float x,float y,float z) { + glPushMatrix(); + glTranslated(x,y,z); + glBegin(GL_QUADS); + float step=TWO_PI/50.0; + float txstep=1.0/50.0; + for (float i=0,j=0;i<=TWO_PI;i+=step,j+=txstep) { + glTexCoord2f(j,0); glVertex3f(cos(i)*r, 0, sin(i)*r); + glTexCoord2f(j,1); glVertex3f(cos(i)*r, -h, sin(i)*r); + glTexCoord2f(j+txstep,1); glVertex3f(cos(i+step)*r, -h, sin(i+step)*r); + glTexCoord2f(j+txstep,0); glVertex3f(cos(i+step)*r, 0, sin(i+step)*r); + } + glEnd(); + glPopMatrix(); +}
\ No newline at end of file diff --git a/basedProject/src/mapUtils.h b/basedProject/src/mapUtils.h new file mode 100644 index 0000000..c362e66 --- /dev/null +++ b/basedProject/src/mapUtils.h @@ -0,0 +1,20 @@ +/* + * mapUtils.h + * + * Created by Tim Redfern on 20/12/2011. + * global utils for projection mapping + * + */ +#pragma once + +#include "ofMain.h" + +void bindTexture(ofBaseHasTexture &t); +void unbindTexture(ofBaseHasTexture &t); +void bindTex(ofTexture &tex); +void unbindTex(ofTexture &tex); +ofPoint distort(ofPoint pt,float d); +void drawBox(float size); +void drawBoard(float x,float y,float z); +void drawCylinder(float r,float h,float x,float y,float z); + diff --git a/basedProject/src/ofApp.cpp b/basedProject/src/ofApp.cpp new file mode 100644 index 0000000..0dc6b46 --- /dev/null +++ b/basedProject/src/ofApp.cpp @@ -0,0 +1,176 @@ +#include "ofApp.h" +//-------------------------------------------------------------- +ofApp::~ofApp(){ + saveSettings("settings.xml"); +} + +//-------------------------------------------------------------- +void ofApp::setup() { + loadSettings("settings.xml"); + + ofBackground(0,0,0); + + ///ofSetVerticalSync(true); + + //some model / light stuff + glEnable (GL_DEPTH_TEST); + glShadeModel (GL_SMOOTH); + glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable (GL_COLOR_MATERIAL); + + ofDisableLighting(); + ofSetGlobalAmbientColor(ofColor(255,255,255)); + + fullscreen=false; + activeView=0; + + xhair.loadImage("crosshairs.png"); +} + +//-------------------------------------------------------------- +void ofApp::update() { + ofSetWindowTitle(ofToString(ofGetFrameRate())); +} + +//-------------------------------------------------------------- +void ofApp::draw() { + + for (int i=0;i<views.size();i++) { + views[i].setLight(); + } + for (int i=0;i<views.size();i++) { + //views[i].begin2d(); + views[i].begin(); + //ofFill(); + //ofEnableAlphaBlending(); + ofSetColor(0, 0, 255, 255); + ofDrawSphere(0,0,0,145); + ofSetColor(0, 255, 0, 255); + ofDrawSphere(200,0,230,75); + ofSetColor(255, 0,0, 255); + ofDrawSphere(-60,-190,280,47.5); + ofSetColor(255, 255,255, 255); + //xhair.draw(0,0,views[i].getWidth(),views[i].getHeight()); + + //views[i].end2d(); + views[i].end(); + } +} + +//-------------------------------------------------------------- +void ofApp::exit() { + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + if (activeView<0) for (int i=0;i<views.size();i++) views[i].keyPressed(key); + else if (activeView<views.size()) views[activeView].keyPressed(key); + switch (key) { + case ' ': + fullscreen=!fullscreen; + ofSetFullscreen(fullscreen); + break; + case '8': + //mode=CALIBRATE; + break; + case '9': + //mode=DISPLAY; + break; + case '0': + //mode=GRAB; + break; + case '1': + activeView=-1; + break; + case '2': + activeView=0; + break; + case '3': + activeView=1; + break; + case '4': + activeView=2; + break; + case 'p': + saveSettings("settings.xml"); + break; + case 'z': + loadSettings("defaults.xml"); + break; + case ',': + case '<': + //prevMovie(); + break; + case '.': + case '>': + //nextMovie(); + break; + case '/': + //light=!light; + //printf(light?"LIGHT ON\n":"LIGHT OFF\n"); + break; + } +} + +void ofApp::keyReleased(int key){ + if (activeView<0) for (int i=0;i<views.size();i++) views[i].keyReleased(key); + else if (activeView<views.size()) views[activeView].keyReleased(key); +} + +void ofApp::loadSettings(string filename){ + //viewport settings are float/ normalised to 0..1 + if( !XML.loadFile(filename) ){ + printf("unable to load %s check data/ folder\n",filename.c_str()); + }else{ + if(XML.pushTag("map4")) { + int numViews=XML.getNumTags("view"); + if(numViews) { + views.resize(numViews); + for (int i=0;i<numViews;i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + map<string,string>settings; + for (int k=0;k<keys.size();k++) { + settings[keys[k]]=XML.getAttribute("settings",keys[k],"none",0); + } + views[i].setup(settings); + XML.popTag(); + } + } + XML.popTag(); + } + printf("loaded settings: %i views\n",views.size()); + } + + //numViews=2; + //views[0].setup(ofGetScreenWidth()/2,ofGetScreenHeight(),0,0); + //views[1].setup(ofGetScreenWidth()/2,ofGetScreenHeight(),ofGetScreenWidth()/2,0); + //activeView=0; +} +//-------------------------------------------------------------- +void ofApp::saveSettings(string filename){ + //either re-navigate the whole thing OR + //save the number to the vp OR + //send a pointer to the vp + + //renavigate? easiest way to get the settings back out + if(XML.pushTag("map4")) { + for (int i=0;i<views.size();i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + for (int k=0;k<keys.size();k++) { + XML.setAttribute("settings", keys[k], views[i].getSetting(keys[k]),0); + } + XML.popTag(); + } + XML.popTag(); + } + XML.saveFile(filename); + printf("saved %s\n",filename.c_str()); +} + +//-------------------------------------------------------------- + diff --git a/basedProject/src/ofApp.h b/basedProject/src/ofApp.h new file mode 100644 index 0000000..7090ab6 --- /dev/null +++ b/basedProject/src/ofApp.h @@ -0,0 +1,60 @@ +/* +projection calibration interface +tjr dec 2011 + +1- ideal KB interface to move around & calibrate camera +2- automatically save settings, key to reset + +logically + -rotate cam frame of reference + -move cam xyz WRT frame of reference + -don't do lookat + +speed interface detects each key on-off & applies key acceleration +have to track how many frames each key has been pressed for + +1- this is a case for a class +2- can key presses overlap? +3- class deals with keys in pairs as you can't move something simultaneously in 2 dirs +*/ + +#pragma once + +#define CALIBRATE 1 +#define DISPLAY 2 +#define GRAB 3 +#define NOTHING 4 + + +#include "ofMain.h" +#include "ofEvents.h" +#include "ofxXmlSettings.h" +//#include "ofx3DModelLoader.h" + +#include "mapUtils.h" +#include "viewpoint.h" + + +class ofApp : public ofBaseApp{ + + public: + ~ofApp(); + void setup(); + void update(); + void draw(); + void exit(); + + void loadSettings(string filename); + void saveSettings(string filename); + void keyPressed (int key); + void keyReleased(int key); + + ofxXmlSettings XML; + + vector<viewpoint> views; + int activeView; + bool fullscreen; + + ofImage xhair; + +}; diff --git a/basedProject/src/viewpoint.cpp b/basedProject/src/viewpoint.cpp new file mode 100644 index 0000000..85a3bf5 --- /dev/null +++ b/basedProject/src/viewpoint.cpp @@ -0,0 +1,196 @@ +#include "viewpoint.h" +#define DEBUG 0 + +void viewpoint::setup(map<string,string>&settings){ + //setup(float w, float h, float x, float y) { + x=ofToFloat(settings["x"]); + y=ofToFloat(settings["y"]); + w=ofToFloat(settings["w"]); + h=ofToFloat(settings["h"]); + if (DEBUG) printf("window: %f,%f %fx%f \n",ofGetWidth()*x,ofGetHeight()*y,ofGetWidth()*w,ofGetHeight()*h); + window=ofRectangle(ofGetWidth()*x,ofGetHeight()*y,ofGetWidth()*w,ofGetHeight()*h); + distortFactor=ofToFloat(settings["distort"]); + renderFBO.allocate(window.width,window.height,GL_RGB); + + //todo: load/save from xml + fov=17.25; + aspect=1.79; + near=1; + far=20; + + vars=new keyVar[9]; + + vars[0].set('w','s',ofToFloat(settings["fov"]),0.2,1.0,3.0); + vars[1].set('g','d',ofToFloat(settings["targX"]),1,1.0,3.0); + vars[2].set('r','v',ofToFloat(settings["targY"]),1,1.0,3.0); + vars[3].set('t','c',ofToFloat(settings["targZ"]),1,1.0,3.0); + vars[4].set('u','n',ofToFloat(settings["lat"]),1,1.0,3.0); + vars[5].set('j','h',ofToFloat(settings["lng"]),1,1.0,3.0); + vars[6].set(',','m',ofToFloat(settings["roll"]),1,1.0,3.0); + vars[7].set('o','l',ofToFloat(settings["dolly"]),1,1.0,3.0); + vars[8].set('q','a',ofToFloat(settings["distort"]),.00001,1.0,3.0); + + //light.enable(); + //light.setDirectional(); + + vertigo=false; +} +double viewpoint::getSetting(const string& setting){ + if (setting=="x") return x; + if (setting=="y") return y; + if (setting=="w") return w; + if (setting=="h") return h; + if (setting=="fov") return vars[0].getVal(); + if (setting=="targX") return vars[1].getVal(); + if (setting=="targY") return vars[2].getVal(); + if (setting=="targZ") return vars[3].getVal(); + if (setting=="lat") return vars[4].getVal(); + if (setting=="lng") return vars[5].getVal(); + if (setting=="roll") return vars[6].getVal(); + if (setting=="dolly") return vars[7].getVal(); + if (setting=="distort") return vars[8].getVal(); + return 0.0; +} +//-------------------------------------------------------------- +void viewpoint::setLight(){ + + ofNode c=ofNode(); + ofNode t=ofNode(); + t.setParent(c); + t.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal()); + //make target controls relative to rotation + c.rotate(vars[5].getVal(), ofVec3f(0, 1, 0)); + + target.setPosition(t.getGlobalPosition()); + //camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[7].getVal(), target); + camera.setFov(vars[0].getVal()); + if (vertigo) { + //distance=width/(2 tan (fov *0.5) + //multiply distance by ratio of tans of fov before and after + vars[7].setVal((tan((vars[0].readVal()-vars[0].inc)*PI*0.0027777)*vars[7].readVal())/tan(vars[0].readVal()*PI*0.0027777)); + } + + + + ofVec3f p(0, 0, vars[7].getVal()); + //p.rotate(ofClamp(vars[2].getVal(), -89, 89), ofVec3f(1, 0, 0)); + p.rotate(vars[4].getVal(), ofVec3f(1, 0, 0)); + p.rotate(vars[5].getVal(), ofVec3f(0, 1, 0)); + p += target.getPosition(); + camera.setPosition(p); + + camera.lookAt(target,ofVec3f(0,1,0).rotate(vars[6].getVal(),ofVec3f(0,0,1)).rotate(vars[5].getVal(),ofVec3f(0,1,0))); + //light.setPosition(camera.getGlobalPosition()); + +} +void viewpoint::setDefaults(){ + vars[0].setVal(17.25); + vars[1].setVal(0.0); + vars[2].setVal(112.0); + vars[3].setVal(0.0); + vars[4].setVal(0.0); + vars[5].setVal(0.0); + vars[6].setVal(0.0); + vars[7].setVal(1000.0); + vars[8].setVal(0.0); +} +//-------------------------------------------------------------- +void viewpoint::begin(){ + renderFBO.begin(); + ofClear(0,0,0); + + camera.begin(); +} +void viewpoint::begin2d(){ + renderFBO.begin(); + ofClear(0,0,0); + +} +void viewpoint::end2d(){ + renderFBO.end(); + renderFBO.draw(getX(),getY()); +} +//-------------------------------------------------------------- +void viewpoint::end(bool showStats){ + + camera.end(); + renderFBO.end(); + + ofPushMatrix(); + + bindTexture(renderFBO); + ofNoFill(); + ofSetLineWidth(1.0); + //ofSetColor(I_fade1,I_fade1,I_fade1); + int gridX=50; + int gridY=50; + int xStep=window.width/2; + int yStep=window.height/2; + ofTranslate(window.x+xStep,window.y+yStep); + + //todo: distort texcoords instead of vertex coords + for (float i = -1; i < 1.001; i+=(2.0f/gridY)){ + glBegin(GL_QUAD_STRIP); + ofPoint p0; + ofPoint p1; + for (float j = -1; j < 1.001; j+=(2.0f/gridX)){ + p0=distort(ofPoint(j,i-(2.0f/gridY)),vars[8].getVal()); + p1=distort(ofPoint(j,i),vars[8].getVal()); + glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5); + glVertex3f(p0.x*xStep,p0.y*yStep,-0.1); + glTexCoord2f((j+1)*0.5,(i+1)*0.5); + glVertex3f(p1.x*xStep,p1.y*yStep,-0.1); + } + glEnd(); + } + + ofFill(); + unbindTexture(renderFBO); + ofPopMatrix(); + + if (showStats) { + ofSetHexColor(0xFFFFFF); + //ofDrawBitmapString("camera: "+ofToString(camera.getX(), 2)+","+ofToString(camera.getY(), 2)+","+ofToString(camera.getZ(), 2)+" "+ofToString(vars[5].getVal())+"deg", window.x+10, window.y+window.height-30); + //ofDrawBitmapString("light: "+ofToString(light.getX(), 2)+","+ofToString(light.getY(), 2)+","+ofToString(light.getZ(), 2), window.x+10, window.y+window.height-18); + ofDrawBitmapString("fov: "+ofToString(vars[0].readVal(), 2)+" distance: "+ofToString(vars[7].readVal(), 2)+" distortion: "+ofToString(vars[8].readVal()), window.x+10, window.y+window.height-18); + } +} +//-------------------------------------------------------------- +void viewpoint::keyPressed(int key){ + for (int i=0;i<8;i++) vars[i].keyPressed(key); + if (DEBUG) printf("fov: %f distort: %f\n",vars[0].getVal(),vars[7].getVal()); + if (key=='!') setDefaults(); + switch(key) { + //'vertigo effect' always affects ALL VIEWPOINTS + //distance=width/(2 tan (fov *0.5) + // a way to 'back door' the variables? + // a new class that represents 2 linked variables? + case 'i': + vertigo=true; + //keyPressed('o'); + keyPressed('s'); + break; + case 'k': + vertigo=true; + //keyPressed('l'); + keyPressed('w'); + break; + } +} +//-------------------------------------------------------------- +void viewpoint::keyReleased(int key){ + for (int i=0;i<8;i++) vars[i].keyReleased(key); + switch (key) { + //'vertigo effect' always affects ALL VIEWPOINTS + case 'i': + vertigo=false; + //keyReleased('o'); + keyReleased('s'); + break; + case 'k': + vertigo=false; + //keyReleased('l'); + keyReleased('w'); + break; + } +} diff --git a/basedProject/src/viewpoint.h b/basedProject/src/viewpoint.h new file mode 100644 index 0000000..94e5fd1 --- /dev/null +++ b/basedProject/src/viewpoint.h @@ -0,0 +1,66 @@ +/* + * viewpoint.h + * 3dnav + * + * Created by Tim Redfern on 20/12/2011. + * one projector's viewpoint + * + */ + +#include "ofMain.h" +#include "mapUtils.h" +#include "keyVar.h" + +class viewpoint { + + public: + + void setup(map<string,string>&settings); + double getSetting(const string& setting); + + void begin(); + void end(bool showStats=false); + + void begin2d(); + void end2d(); + + void setDefaults(); + + void keyPressed(int key); + void keyReleased(int key); + void setLight(); + + ofFbo renderFBO; + + float distortFactor; + + bool vertigo; + + float getWidth(){ return ofGetWidth()*w; }; + float getHeight(){ return ofGetHeight()*h; }; + float getX(){ return ofGetWidth()*x; }; + float getY(){ return ofGetHeight()*y; }; + + + private: + + ofRectangle window; + + double fov,aspect,near,far; + + ofCamera camera; + ofNode target; + + keyVar* vars; + + //int lightNum; + //GLfloat lightColour[]; + + //GLfloat* getLightPosition; + + //ofLight light; + + float x,y,w,h; + + +}; diff --git a/crosshairs.svg b/crosshairs.svg new file mode 100644 index 0000000..982a5a4 --- /dev/null +++ b/crosshairs.svg @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="1280" + height="768" + id="svg2"> + <defs + id="defs4" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + transform="translate(0,-284.36218)" + id="layer1"> + <rect + width="1282.7645" + height="769.15314" + x="0" + y="284.36218" + id="rect2985" + style="fill:#000000;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.10320663px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="m 640.59869,-1.9158092 0,780.6922392" + transform="translate(0,284.36218)" + id="path3757" + style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="M -7.1842844,383.64079 1285.9869,382.44341" + transform="translate(0,284.36218)" + id="path3759" + style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 1024.9579,383.64078 a 384.35922,384.35922 0 1 1 -768.71843,0 384.35922,384.35922 0 1 1 768.71843,0 z" + transform="translate(0,284.36218)" + id="path3765" + style="fill:none;stroke:#ffffff;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 1024.9579,383.64078 a 384.35922,384.35922 0 1 1 -768.71843,0 384.35922,384.35922 0 1 1 768.71843,0 z" + transform="matrix(0.5,0,0,0.5,320.29934,474.9852)" + id="path3765-1" + style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 1024.9579,383.64078 a 384.35922,384.35922 0 1 1 -768.71843,0 384.35922,384.35922 0 1 1 768.71843,0 z" + transform="matrix(0.25,0,0,0.25,480.44901,570.89539)" + id="path3765-1-7" + style="fill:none;stroke:#ffffff;stroke-width:6;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 1024.9579,383.64078 a 384.35922,384.35922 0 1 1 -768.71843,0 384.35922,384.35922 0 1 1 768.71843,0 z" + transform="matrix(0.125,0,0,0.125,560.52385,618.85049)" + id="path3765-1-7-3" + style="fill:none;stroke:#ffffff;stroke-width:10;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + </g> +</svg> diff --git a/glitcher/Makefile b/glitcher/Makefile new file mode 100644 index 0000000..7a7fe8b --- /dev/null +++ b/glitcher/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../.. +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/glitcher/addons.make b/glitcher/addons.make new file mode 100644 index 0000000..ab4486b --- /dev/null +++ b/glitcher/addons.make @@ -0,0 +1,2 @@ +ofxKinect +ofxOpenCv diff --git a/glitcher/config.make b/glitcher/config.make new file mode 100644 index 0000000..98bb09c --- /dev/null +++ b/glitcher/config.make @@ -0,0 +1 @@ +OF_ROOT=../../openFrameworks diff --git a/glitcher/src/main.cpp b/glitcher/src/main.cpp new file mode 100644 index 0000000..d134fc9 --- /dev/null +++ b/glitcher/src/main.cpp @@ -0,0 +1,6 @@ +#include "ofApp.h" + +int main() { + ofSetupOpenGL(1024, 768, OF_WINDOW); + ofRunApp(new ofApp()); +} diff --git a/glitcher/src/ofApp.cpp b/glitcher/src/ofApp.cpp new file mode 100644 index 0000000..6055485 --- /dev/null +++ b/glitcher/src/ofApp.cpp @@ -0,0 +1,154 @@ +#include "ofApp.h" + + +//-------------------------------------------------------------- +void ofApp::setup() { + ofSetLogLevel(OF_LOG_WARNING); + + ofSetFrameRate(60); + + buffer.allocate(ofGetWidth(),ofGetHeight()); + renderFBO.allocate(ofGetWidth(),ofGetHeight(),GL_RGB); + //buffer.clear(); +} + +//-------------------------------------------------------------- +void ofApp::update() { + ofSetWindowTitle(ofToString(ofGetFrameRate())); +} + +//-------------------------------------------------------------- +void ofApp::draw() { + + //rough out how it could be possible to perform an avs style glitch transform + //within a drawing + //drawing- to an fbo + //distorting- from an opencv texture + //how to get from an fbo to an opencv texture + ofSetColor(255, 255, 255); + + renderFBO.begin(); + buffer.draw(0,0); + + + ofNoFill(); + ofTranslate(ofGetWidth()/2,ofGetHeight()/2); + ofRect(-20,-20,40,40); + renderFBO.end(); + renderFBO.readToPixels(buffer.getPixelsRef()); + buffer.flagImageChanged(); + + cv::Mat buf = buffer.getCvImage(); + cv::Mat dstbuf; + + //create low res remap target + + cv::Mat dstX(32,24,CV_32FC1); + cv::Mat dstY(32,24,CV_32FC1); + cv::Mat srcX(32,24,CV_32FC1); + cv::Mat srcY(32,24,CV_32FC1); + + float xFactor=ofGetWidth()/dstX.rows; + float yFactor=ofGetHeight()/dstX.cols; + for (int i=0;i<dstX.cols;i++){ + for (int j=0;j<dstX.rows;j++){ + dstX.at<double>(i,j)=i*xFactor; + dstY.at<double>(i,j)=j*yFactor; + } + } + + //transform the low res matrix + float tX=0; //fraction of image + float tY=0; //fraction of image + float oX=0; //fraction of image + float oY=0; //fraction of image + float s=0.99; + float r=0.0; + + cv::Point2f srcTri[3], dstTri[3]; + cv::Mat rot_mat(2,3,CV_32FC1); + cv::Mat trans_mat(2,3,CV_32FC1); + cv::Mat out_mat(3,3,CV_32FC1); + + // Compute matrix by creating triangle and transforming + srcTri[0].x=0; + srcTri[0].y=0; + srcTri[1].x=dstX.rows-1; + srcTri[1].y=0; + srcTri[2].x=0; + srcTri[2].y=dstX.cols-1; + for (int i=0;i<3;i++){ + dstTri[i].x=srcTri[i].x+(tX*dstX.cols); + dstTri[i].y=srcTri[i].y+(tY*dstX.cols); //use cols for equiv coords + //rotate and scale around centre + //transform to centre + dstTri[i].x-=(oX*dstX.cols); + dstTri[i].y-=(oY*dstX.cols); + + dstTri[i].x*=s; + dstTri[i].y*=s; + + double dx=(dstTri[i].x*cos(r))-(dstTri[i].y*sin(r)); + double dy=(dstTri[i].x*sin(r))+(dstTri[i].y*cos(r)); + + dstTri[i].x=dx; + dstTri[i].y=dy; + + //transform back + dstTri[i].x+=(oX*dstX.cols); + dstTri[i].y+=(oY*dstX.cols); + } + trans_mat=getAffineTransform( srcTri, dstTri ); + warpAffine( srcX, dstX, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); + warpAffine( srcY, dstY, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); + + cv::Mat scaledstX; + cv::Mat scaledstY; + + cv::resize(dstX,scaledstX, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); + cv::resize(dstY,scaledstY, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); + + cv::remap(buf,dstbuf,scaledstX,scaledstY, cv::INTER_LINEAR, cv::BORDER_WRAP, cv::Scalar(0,0, 0) ); + IplImage *tmp = new IplImage(dstbuf); + + buffer=tmp; + delete tmp; + + renderFBO.draw(0,0); //eventually textured into a viewport + +} + + + +//-------------------------------------------------------------- +void ofApp::exit() { + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed (int key) { + switch (key) { + + case OF_KEY_UP: + break; + + case OF_KEY_DOWN: + break; + } +} + +//-------------------------------------------------------------- +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::windowResized(int w, int h) +{} diff --git a/glitcher/src/ofApp.h b/glitcher/src/ofApp.h new file mode 100644 index 0000000..fd72e87 --- /dev/null +++ b/glitcher/src/ofApp.h @@ -0,0 +1,24 @@ +#pragma once + +#include "ofMain.h" +#include "ofxOpenCv.h" + + +class ofApp : public ofBaseApp { +public: + + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed(int key); + 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 windowResized(int w, int h); + + ofxCvColorImage buffer; + + ofFbo renderFBO; +}; |
