summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2011-12-20 18:31:56 +0000
committerTim Redfern <tim@eclectronics.org>2011-12-20 18:31:56 +0000
commit084c8a9b85b853fa630d5a102cd102b45d543abf (patch)
tree7268fe74717c5140ca22649b9694e8591276a917 /src
parent5523988d1729fe5c2757e046636d219639ee6724 (diff)
building multiple views
Diffstat (limited to 'src')
-rw-r--r--src/keyVar.cpp53
-rw-r--r--src/keyVar.h32
-rw-r--r--src/testApp.cpp129
-rw-r--r--src/testApp.h29
-rw-r--r--src/viewpoint.cpp88
-rw-r--r--src/viewpoint.h39
6 files changed, 232 insertions, 138 deletions
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;
+
+};