summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2011-12-19 18:10:17 +0000
committerTim Redfern <tim@eclectronics.org>2011-12-19 18:10:17 +0000
commit7ed42bc033eacecf45affab4f811b1e9febb7950 (patch)
tree7caf96345831c3fcc088c27c1e55b6679b5b7bd0
parentf6f57d4d831814abd1e697801688962ef3445022 (diff)
sliders workingHEADmaster
-rw-r--r--3dnav.cbp3
-rw-r--r--3dnav.layout21
-rw-r--r--src/keyVar.cpp24
-rw-r--r--src/keyVar.h11
-rw-r--r--src/main.cpp9
-rw-r--r--src/testApp.cpp149
6 files changed, 76 insertions, 141 deletions
diff --git a/3dnav.cbp b/3dnav.cbp
index a152d3b..aec4e04 100644
--- a/3dnav.cbp
+++ b/3dnav.cbp
@@ -111,6 +111,9 @@
<Unit filename="../../../addons/ofxXmlSettings/src/ofxXmlSettings.h">
<Option virtualFolder="addons/ofxXmlSettings/src" />
</Unit>
+ <Unit filename="Makefile">
+ <Option virtualFolder="build config/" />
+ </Unit>
<Unit filename="config.make">
<Option virtualFolder="build config" />
</Unit>
diff --git a/3dnav.layout b/3dnav.layout
index 1a85030..4eb3bdd 100644
--- a/3dnav.layout
+++ b/3dnav.layout
@@ -4,14 +4,23 @@
<File name="../../../addons/ofx3DModelLoader/src/3DS/model3DS.h" open="0" top="0" tabpos="0">
<Cursor position="136" topLine="0" />
</File>
- <File name="config.make" open="1" top="0" tabpos="5">
- <Cursor position="168" topLine="0" />
+ <File name="Makefile" open="0" top="0" tabpos="0">
+ <Cursor position="4795" topLine="93" />
</File>
- <File name="src/main.cpp" open="1" top="1" tabpos="3">
- <Cursor position="516" topLine="0" />
+ <File name="config.make" open="0" top="0" tabpos="5">
+ <Cursor position="477" topLine="0" />
</File>
- <File name="src/testApp.cpp" open="1" top="0" tabpos="2">
- <Cursor position="813" topLine="0" />
+ <File name="src/keyVar.cpp" open="1" top="0" tabpos="5">
+ <Cursor position="1243" topLine="17" />
+ </File>
+ <File name="src/keyVar.h" open="1" top="0" tabpos="4">
+ <Cursor position="376" topLine="0" />
+ </File>
+ <File name="src/main.cpp" open="1" top="0" tabpos="3">
+ <Cursor position="766" topLine="0" />
+ </File>
+ <File name="src/testApp.cpp" open="1" top="1" tabpos="2">
+ <Cursor position="911" topLine="0" />
</File>
<File name="src/testApp.h" open="1" top="0" tabpos="1">
<Cursor position="698" topLine="4" />
diff --git a/src/keyVar.cpp b/src/keyVar.cpp
index ca64b7f..ea8b9ff 100644
--- a/src/keyVar.cpp
+++ b/src/keyVar.cpp
@@ -1,10 +1,11 @@
/*
* keyvar.cpp
-
- generalised cushioned keyboard controller
+
+ 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;
@@ -15,33 +16,38 @@ void keyVar::set(char _keyInc,char _keyDec,float _val,float _speed,float _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();
- printf("pressed %i\n",_key);
+ if (DEBUG) printf("pressed %i\n",_key);
}
if (_key==keyDec&&state!=-1) {
state=-1;
timePressed=timeCalc=ofGetElapsedTimef();
- printf("pressed %i\n",_key);
+ if (DEBUG) printf("pressed %i\n",_key);
}
}
void keyVar::keyReleased(char _key){
if (_key==keyInc&&state==1) {
state=0;
- printf("released %i\n",_key);
+ if (DEBUG) printf("released %i\n",_key);
}
if (_key==keyDec&&state==-1) {
state=0;
- printf("released %i\n",_key);
+ if (DEBUG) printf("released %i\n",_key);
}
}
float keyVar::getVal(){
- float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime);
- if (state) val+=pow(segment,accel)*(ofGetElapsedTimef()-timeCalc)*speed*state;
+ float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime);
+ if (state) val+=pow(segment,accel)*speed*state; //(ofGetElapsedTimef()-timeCalc)*
timeCalc=ofGetElapsedTimef();
return val;
-} \ No newline at end of file
+}
+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
index 2717011..2187611 100644
--- a/src/keyVar.h
+++ b/src/keyVar.h
@@ -10,13 +10,14 @@
#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;
@@ -24,6 +25,8 @@ private:
int state; //up-down-off
float val;
float speed;
- float accel;
float accelTime;
-}; \ No newline at end of file
+ float accel;
+
+
+};
diff --git a/src/main.cpp b/src/main.cpp
index 0cd85f7..5c102f0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,6 +2,9 @@
#include "testApp.h"
#include "ofAppGlutWindow.h"
+//linux includes
+#include <GL/glut.h>
+
// Includes for Mac OSX
/*
#include <GLUT/glut.h>
@@ -22,12 +25,12 @@ int main( ){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 600,600, OF_WINDOW); // <-------- setup the GL context
- //glutIgnoreKeyRepeat(1);
- //printf("key repeat ignore: %i\n",glutDeviceGet(GLUT_DEVICE_IGNORE_KEY_REPEAT));
+ glutIgnoreKeyRepeat(1); //only works on linux?
+ printf("key repeat ignore: %i\n",glutDeviceGet(GLUT_DEVICE_IGNORE_KEY_REPEAT));
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
- window.setFrameRate(200.0f);
+ //window.setFrameRate(200.0f);
ofRunApp( new testApp());
}
diff --git a/src/testApp.cpp b/src/testApp.cpp
index 8e1bb77..65b637f 100644
--- a/src/testApp.cpp
+++ b/src/testApp.cpp
@@ -26,62 +26,18 @@ void testApp::setup(){
camera.setParent(target);
camera.setPosition(0,0,200);
-
- vars=new keyVar[9];
-
- vars[0].set('w','s',17.25,1.0,1.0,2.0);
-
- /*
-
-case 'w':
- fov*=0.99;
- break;
-case 's':
- fov*=1.01;
- break;
-
- //nav stuff
-case 'g':
- target.move(1,0,0);
- break;
-case 'd':
- target.move(-1,0,0);
- break;
-case 'r':
- target.move(0,1,0);
- break;
-case 'v':
- target.move(0,-1,0);
- break;
-case 'c':
- target.move(0,0,1);
- break;
-case 't':
- target.move(0,0,-1);
- break;
-
-case 'h':
- target.rotate(1,0,1,0);
- break;
-case 'j':
- target.rotate(-1,0,1,0);
- break;
-case 'u':
- target.rotate(1,1,0,0);
- break;
-case 'n':
- target.rotate(-1,1,0,0);
- break;
-
-case 'o':
- camera.move(0,0,1);
- break;
-case 'l':
- camera.move(0,0,-1);
- break;
-
- */
-
+
+ vars=new keyVar[7];
+
+ //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);
+
}
//--------------------------------------------------------------
@@ -107,11 +63,14 @@ void testApp::draw(){
glMatrixMode(GL_MODELVIEW);
// glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
*/
-
+
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());
+
ofBackground(0);
ofSetColor(255,0,0);
@@ -264,77 +223,29 @@ void testApp::draw(){
//renderFBO.getTextureReference().unbind();
unbindTexture(renderFBO);
- ofSetHexColor(0x000000);
+ // add polygons here
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+ */
+
+ ofSetHexColor(0xFFFFFF);
ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
+ //ofDrawBitmapString("segmentpow: "+ofToString(pow(vars[0].segment,vars[0].accel), 2), 10, 25);
+
+
+
- // add polygons here
- //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- */
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
- vars[0].keyPressed(key);
- switch (key) {
- /*
- case 'w':
- fov*=0.99;
- break;
- case 's':
- fov*=1.01;
- break;
- */
-
- //nav stuff
- case 'g':
- target.move(1,0,0);
- break;
- case 'd':
- target.move(-1,0,0);
- break;
- case 'r':
- target.move(0,1,0);
- break;
- case 'v':
- target.move(0,-1,0);
- break;
- case 'c':
- target.move(0,0,1);
- break;
- case 't':
- target.move(0,0,-1);
- break;
-
- case 'h':
- target.rotate(1,0,1,0);
- break;
- case 'j':
- target.rotate(-1,0,1,0);
- break;
- case 'u':
- target.rotate(1,1,0,0);
- break;
- case 'n':
- target.rotate(-1,1,0,0);
- break;
-
- case 'o':
- camera.move(0,0,1);
- break;
- case 'l':
- camera.move(0,0,-1);
- break;
- }
- //printf("xyx: %f,%f,%f rxry: %f,%f fov: %f\n",cx,cy,cz,crx,cry,fov);
-
-}
+ for (int i=0;i<7;i++) vars[i].keyPressed(key);
+ }
//--------------------------------------------------------------
void testApp::keyReleased(int key){
- //printf("released %i\n",key);
- vars[0].keyReleased(key);
+ for (int i=0;i<7;i++) vars[i].keyReleased(key);
}
//--------------------------------------------------------------