From 084c8a9b85b853fa630d5a102cd102b45d543abf Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 20 Dec 2011 18:31:56 +0000 Subject: building multiple views --- Makefile | 40 ++++++++--------- config.make | 2 +- map4.cbp | 15 +++++++ map4.layout | 17 +++++-- src/keyVar.cpp | 53 ++++++++++++++++++++++ src/keyVar.h | 32 ++++++++++++++ src/testApp.cpp | 129 +++++------------------------------------------------- src/testApp.h | 29 ++++-------- src/viewpoint.cpp | 88 +++++++++++++++++++++++++++++++++++++ src/viewpoint.h | 39 +++++++++++++++++ 10 files changed, 281 insertions(+), 163 deletions(-) create mode 100644 src/keyVar.cpp create mode 100644 src/keyVar.h create mode 100644 src/viewpoint.cpp create mode 100644 src/viewpoint.h diff --git a/Makefile b/Makefile index 2db4a8b..0862bed 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ else endif LIB_STATIC = $(shell ls $(OF_ROOT)/libs/*/lib/$(LIBSPATH)/*.a 2> /dev/null | grep -v openFrameworksCompiled | grep -v Poco) LIB_SHARED = $(shell ls $(OF_ROOT)/libs/*/lib/$(LIBSPATH)/*.so 2> /dev/null | grep -v openFrameworksCompiled | sed "s/.*\\/lib\([^/]*\)\.so/-l\1/") -LIB_STATIC += $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/libPocoNet.a ../../../libs/poco/lib/$(LIBSPATH)/libPocoXML.a ../../../libs/poco/lib/$(LIBSPATH)/libPocoUtil.a ../../../libs/poco/lib/$(LIBSPATH)/libPocoFoundation.a +LIB_STATIC += $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/libPocoNet.a $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/libPocoXML.a $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/libPocoUtil.a $(OF_ROOT)/libs/poco/lib/$(LIBSPATH)/libPocoFoundation.a LIB_PATHS_FLAGS = $(shell ls -d $(OF_ROOT)/libs/*/lib/$(LIBSPATH) | sed "s/\(\.*\)/-L\1/") CFLAGS += -Wall -fexceptions @@ -142,14 +142,14 @@ ifeq ($(findstring addons.make,$(wildcard *.make)),addons.make) else ADDONS = $(shell cat addons.make) endif - + ifneq ($(strip $(ADDONS)),) ADDONS_REL_DIRS = $(addsuffix /src, $(ADDONS)) ADDONS_LIBS_REL_DIRS = $(addsuffix /libs, $(ADDONS)) ADDONS_DIRS = $(addprefix $(OF_ROOT)/addons/, $(ADDONS_REL_DIRS) ) ADDONS_LIBS_DIRS = $(addprefix $(OF_ROOT)/addons/, $(ADDONS_LIBS_REL_DIRS) ) ADDONS_BIN_LIBS_DIRS = $(addsuffix /*/lib/$(LIBSPATH), $(ADDONS_LIBS_DIRS) ) - + ADDONS_INCLUDES = $(ADDONS_DIRS) ADDONS_INCLUDES = $(ADDONS_LIBS_DIRS) ADDONS_INCLUDES += $(shell find $(ADDONS_DIRS) -type d 2> /dev/null) @@ -220,7 +220,7 @@ ifeq ($(ARCH),android) TARGET_LIBS = $(OF_ROOT)/libs/openFrameworksCompiled/lib/$(ARCH)/libopenFrameworks_neon.a USER_LIBS = $(USER_LIBS_NEON) endif - + ifeq ($(findstring TestLink,$(MAKECMDGOALS)),TestLink) TARGET_NAME = Debug TARGET_LIBS = $(OF_ROOT)/libs/openFrameworksCompiled/lib/$(ARCH)/libopenFrameworksDebug.a @@ -323,7 +323,7 @@ $(OBJ_OUTPUT)%.o: $(OF_ROOT)/%.c @echo "compiling addon object for" $< mkdir -p $(@D) $(CC) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o $@ -c $< - + $(OBJ_OUTPUT)%.o: $(OF_ROOT)/%.cc @echo "compiling addon object for" $< mkdir -p $(@D) @@ -333,7 +333,7 @@ $(OBJ_OUTPUT)%.o: $(USER_SOURCE_DIR)/%.c @echo "compiling object for: " $< mkdir -p $(@D) $(CC) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $< - + $(OBJ_OUTPUT)%.o: $(USER_SOURCE_DIR)/%.cc @echo "compiling object for: " $< mkdir -p $(@D) @@ -343,7 +343,7 @@ $(OBJ_OUTPUT)%.o: $(USER_SOURCE_DIR)/%.cpp @echo "compiling object for: " $< mkdir -p $(@D) $(CXX) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $< - + $(TARGET): $(OBJS) $(ADDONS_OBJS) $(USER_OBJS) $(TARGET_LIBS) $(LIB_STATIC) @echo 'linking $(TARGET)' mkdir -p $(@D) @@ -356,7 +356,7 @@ clean: rm -rf $(OBJ_OUTPUT) rm -f $(TARGET) rm -r bin/libs - + $(CLEANTARGET): rm -rf $(OBJ_OUTPUT) rm -f $(TARGET) @@ -371,49 +371,49 @@ CleanAndroid: afterDebugAndroid:$(TARGET) @if [ -d libs/armeabi-v7a ]; then rm -r libs/armeabi-v7a; fi - + @cp $(NDK_ROOT)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver libs/armeabi - + #create gdb.setup for armeabi @echo "set solib-search-path $(PWD)/obj/local/armeabi:$(PWD)/libs/armeabi" > libs/armeabi/gdb.setup @echo "directory $(NDK_ROOT)/platforms/$(NDK_PLATFORM)/arch-arm/usr/include" >> libs/armeabi/gdb.setup @echo "directory $(PWD)/src" >> libs/armeabi/gdb.setup @echo "directory $(NDK_ROOT)/sources/cxx-stl/system" >> libs/armeabi/gdb.setup - @echo "directory $(PWD)/libs/armeabi" >> libs/armeabi/gdb.setup - @echo "" >> libs/armeabi/gdb.setup - + @echo "directory $(PWD)/libs/armeabi" >> libs/armeabi/gdb.setup + @echo "" >> libs/armeabi/gdb.setup + @if [ ! -d jni ]; then mkdir jni; fi @echo "APP_ABI := armeabi" > jni/Application.mk @echo "#LOCAL_MODULE := OFAndroidApp" > jni/Android.mk afterReleaseAndroid:$(TARGET) @if [ -f obj/$(BIN_NAME) ]; then rm obj/$(BIN_NAME); fi - + @cp $(OF_ROOT)/libs/openFrameworksCompiled/project/android/libneondetection.so libs/armeabi-v7a/ @cp $(NDK_ROOT)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver libs/armeabi-v7a - + #create gdb.setup for armeabi-v7a @echo "set solib-search-path $(PWD)/obj/local/armeabi-v7a:$(PWD)/libs/armeabi-v7a" > libs/armeabi-v7a/gdb.setup @echo "directory $(NDK_ROOT)/platforms/$(NDK_PLATFORM)/arch-arm/usr/include" >> libs/armeabi-v7a/gdb.setup @echo "directory $(PWD)/src" >> libs/armeabi-v7a/gdb.setup @echo "directory $(NDK_ROOT)/sources/cxx-stl/system" >> libs/armeabi-v7a/gdb.setup - @echo "directory $(PWD)/libs/armeabi-v7a" >> libs/armeabi-v7a/gdb.setup - @echo "" >> libs/armeabi-v7a/gdb.setup - + @echo "directory $(PWD)/libs/armeabi-v7a" >> libs/armeabi-v7a/gdb.setup + @echo "" >> libs/armeabi-v7a/gdb.setup + @if [ ! -d jni ]; then mkdir jni; fi @echo "APP_ABI := armeabi armeabi-v7a" > jni/Application.mk @echo "#LOCAL_MODULE := OFAndroidApp" > jni/Android.mk RESNAME=$(shell echo $(APPNAME)Resources | tr '[A-Z]' '[a-z]') -AndroidInstall: +AndroidInstall: if [ -d "bin/data" ]; then \ mkdir -p res/raw; \ rm res/raw/$(RESNAME).zip; \ cd bin/data; \ zip -r ../../res/raw/$(RESNAME).zip *; \ cd ../..; \ - fi + fi if [ -f obj/$(BIN_NAME) ]; then rm obj/$(BIN_NAME); fi #touch AndroidManifest.xml $(SDK_ROOT)/tools/android update project --target $(NDK_PLATFORM) --path $(PROJECT_PATH) diff --git a/config.make b/config.make index cc16340..23d8351 100644 --- a/config.make +++ b/config.make @@ -3,7 +3,7 @@ # OF_ROOT allows to move projects outside apps/* just set this variable to the # absoulte path to the OF root folder -OF_ROOT = ../../.. +OF_ROOT = ../of_preRelease_v007_linux/ # USER_CFLAGS allows to pass custom flags to the compiler diff --git a/map4.cbp b/map4.cbp index da37d74..cbf5dd7 100644 --- a/map4.cbp +++ b/map4.cbp @@ -114,15 +114,30 @@ + + + + + + + + + + diff --git a/map4.layout b/map4.layout index 844ee14..aefae28 100644 --- a/map4.layout +++ b/map4.layout @@ -5,15 +5,24 @@ - + - - + + + + + - + + + + + + + diff --git a/src/keyVar.cpp b/src/keyVar.cpp new file mode 100644 index 0000000..ea8b9ff --- /dev/null +++ b/src/keyVar.cpp @@ -0,0 +1,53 @@ +/* + * keyvar.cpp + + generalised cushioned keyboard controller + */ + +#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; + +} +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\n",_key); + } + if (_key==keyDec&&state!=-1) { + state=-1; + timePressed=timeCalc=ofGetElapsedTimef(); + if (DEBUG) printf("pressed %i\n",_key); + } +} +void keyVar::keyReleased(char _key){ + if (_key==keyInc&&state==1) { + state=0; + if (DEBUG) printf("released %i\n",_key); + } + if (_key==keyDec&&state==-1) { + state=0; + if (DEBUG) printf("released %i\n",_key); + } +} +float keyVar::getVal(){ + float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime); + if (state) val+=pow(segment,accel)*speed*state; //(ofGetElapsedTimef()-timeCalc)* + timeCalc=ofGetElapsedTimef(); + return val; +} +float keyVar::getInc(){ + float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime); + return pow(segment,accel)*speed*state; +} diff --git a/src/keyVar.h b/src/keyVar.h new file mode 100644 index 0000000..2187611 --- /dev/null +++ b/src/keyVar.h @@ -0,0 +1,32 @@ +/* + * 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(); + +private: + char keyInc,keyDec; + long timePressed; + long timeCalc; + int state; //up-down-off + float val; + float speed; + float accelTime; + float accel; + + +}; diff --git a/src/testApp.cpp b/src/testApp.cpp index 439f668..581687f 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,4 +1,5 @@ #include "testApp.h" + GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0}; GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 0.5}; @@ -46,30 +47,14 @@ void testApp::setup(){ texture.loadMovie("gradblend01.mov"); texture.play(); - distortFactor=0.0; - - renderFBO.allocate(ofGetWidth(),ofGetHeight(),GL_RGB); - mode=CALIBRATE; - //approx 200 x 108 x 60 - //275:492 - //vfov = sin t/2 = 30/200 = 0.15 - fov=17.25; - aspect=1.79; - near=0; - far=3000; + views=new viewpoint[1]; - cx=0; - cy=0; - cz=-100; - - crx=cry=0; - - ex=0; - ey=0; - ez=0; + //todo: read this from xml + views[0].setup(ofGetWidth(),ofGetHeight(),0,0); + activeView=0; } @@ -93,15 +78,9 @@ void testApp::draw(){ //glEnable(GL_LIGHTING); //ofRectangle vp=ofRectangle(0,0,ofGetWidth(),ofGetHeight()); //camera.setFov(fov); - camera.begin(); - camera.setPosition(cx, cy, cz); - ofRotateY(cry); - ofRotateX(crx); - camera.setFov(fov); - ofVec3f lookAt; - lookAt.set(ex,ey,ez); - camera.lookAt(lookAt); - + views[0].begin(); + + glPushMatrix(); /* @@ -140,8 +119,7 @@ void testApp::draw(){ ofSetColor(255, 255, 255, 255); ofFill(); - //renderFBO.begin(); //render to FOB - ofClear(0,0,0); + switch(mode) { case CALIBRATE: @@ -190,7 +168,7 @@ void testApp::draw(){ break; } glPopMatrix(); - camera.end(); + views[0].end(); @@ -270,70 +248,15 @@ void testApp::draw(){ //-------------------------------------------------------------- void testApp::keyPressed(int key){ + views[activeView].keyPressed(key); switch (key) { - case 'q': - distortFactor-=0.001f; - break; - case 'a': - distortFactor+=0.001f; - break; - case 'w': - fov*=0.99; - break; - case 's': - fov*=1.01; - break; case '1': mode=CALIBRATE; break; case '2': mode=DISPLAY; break; - - //nav stuff - case 'g': - ex+=0.1; - break; - case 'd': - ex-=0.1; - break; - case 'r': - ey+=0.1; - break; - case 'v': - ey-=0.1; - break; - case 'c': - ez+=0.1; - break; - case 't': - ez-=0.1; - break; - - case 'h': - crx+1; - break; - case 'j': - cry-=1; - break; - case 'u': - //rotate camera in Y - break; - case 'n': - //rotate camera in Y - break; - - case 'o': - //dolly IN - break; - case 'l': - //dolly OUT - break; - - - } - printf("fov: %f, mode: %d, distortion: %f\n",fov,mode,distortFactor); } @@ -376,34 +299,4 @@ void testApp::gotMessage(ofMessage msg){ void testApp::dragEvent(ofDragInfo dragInfo){ } -void testApp::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 testApp::unbindTexture(ofBaseHasTexture &t) { - t.getTextureReference().unbind(); - - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); -} -ofPoint testApp::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)); -}; diff --git a/src/testApp.h b/src/testApp.h index fee5517..c8adb7f 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -4,15 +4,15 @@ tjr dec 2011 1- ideal KB interface to move around & calibrate camera 2- automatically save settings, key to reset - -logically + +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 @@ -26,6 +26,8 @@ have to track how many frames each key has been pressed for #include "ofMain.h" #include "ofx3DModelLoader.h" +#include "viewpoint.h" + class testApp : public ofBaseApp{ public: @@ -43,27 +45,14 @@ class testApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); - void bindTexture(ofBaseHasTexture &t); - void unbindTexture(ofBaseHasTexture &t); - - ofPoint distort(ofPoint pt,float d); - ofx3DModelLoader bottle; ofx3DModelLoader board; ofVideoPlayer texture; - float distortFactor; - - ofFbo renderFBO; - - ofCamera camera; - - double fov,aspect,near,far; + viewpoint* views; + int activeView; //receives keypresses - int mode; + int mode; - float cx,cy,cz,ex,ey,ez; - float crx,cry; //camera rotations - }; diff --git a/src/viewpoint.cpp b/src/viewpoint.cpp new file mode 100644 index 0000000..249084f --- /dev/null +++ b/src/viewpoint.cpp @@ -0,0 +1,88 @@ +#include "viewpoint.h" + +void viewpoint::setup(float w, float h, float x, float y) { + window=ofRectangle(w,h,x,y); + distortFactor=0.0; + renderFBO.allocate(window.width,window.height,GL_RGB); + + //todo: load/save from xml + fov=17.25; + aspect=1.79; + near=1; + far=20; + + camera.setParent(target); + camera.setPosition(0,0,200); + + vars=new keyVar[8]; + + //void set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float accelTime); + vars[0].set('w','s',17.25,0.5,2.0,3.0); + vars[1].set('g','d',0.0,0.2,3.0,3.0); + vars[2].set('r','v',0.0,0.2,3.0,3.0); + vars[3].set('t','c',0.0,0.2,3.0,3.0); + vars[4].set('u','n',0.0,1.0,3.0,3.0); + vars[5].set('j','h',0.0,1.0,3.0,3.0); + vars[6].set('o','l',0.0,0.2,3.0,3.0); + vars[7].set('q','a',0,0.1,2.0,3.0); +} +//-------------------------------------------------------------- +void viewpoint::begin(){ + camera.begin(); + camera.setFov(vars[0].getVal()); + target.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal()); + target.rotate(vars[4].getInc(),1,0,0); + target.rotate(vars[5].getInc(),0,1,0); + camera.move(0,0,vars[6].getInc()); + + renderFBO.begin(); + ofClear(0,0,0); +} +//-------------------------------------------------------------- +void viewpoint::end(){ + + renderFBO.end(); + camera.end(); + + glPushMatrix(); + bindTexture(renderFBO); + //draw a grid + //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + ofNoFill(); + + ofSetLineWidth(1.0); + //ofSetColor(I_fade1,I_fade1,I_fade1); + int gridX=50; + int gridY=50; + int xStep=ofGetWidth()/2; + int yStep=ofGetHeight()/2; + ofTranslate(ofGetWidth()/2,ofGetHeight()/2); + + 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)),distortFactor); + p1=distort(ofPoint(j,i),distortFactor); + glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5); + glVertex3f(p0.x*xStep,p0.y*yStep,0); + glTexCoord2f((j+1)*0.5,(i+1)*0.5); + glVertex3f(p1.x*xStep,p1.y*yStep,0); + } + glEnd(); + } + + ofFill(); + glPopMatrix(); + unbindTexture(renderFBO); + +} +//-------------------------------------------------------------- +void viewpoint::keyPressed(int key){ + for (int i=0;i<8;i++) vars[i].keyPressed(key); + } +//-------------------------------------------------------------- +void viewpoint::keyReleased(int key){ + for (int i=0;i<8;i++) vars[i].keyReleased(key); +} diff --git a/src/viewpoint.h b/src/viewpoint.h new file mode 100644 index 0000000..c1a0985 --- /dev/null +++ b/src/viewpoint.h @@ -0,0 +1,39 @@ +/* + * 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(float w, float h, float x, float y); + void begin(); + void end(); + void keyPressed(int key); + void keyReleased(int key); + + private: + + ofRectangle window; + + float distortFactor; + ofFbo renderFBO; + + double fov,aspect,near,far; + + ofCamera camera; + ofNode target; + + keyVar* vars; + +}; -- cgit v1.2.3