diff options
Diffstat (limited to 'liveengine/src/viewport.cpp')
| -rwxr-xr-x | liveengine/src/viewport.cpp | 156 |
1 files changed, 114 insertions, 42 deletions
diff --git a/liveengine/src/viewport.cpp b/liveengine/src/viewport.cpp index fab77ce..35a4036 100755 --- a/liveengine/src/viewport.cpp +++ b/liveengine/src/viewport.cpp @@ -1,4 +1,5 @@ -#include "viewport.h"
+#include "viewport.h" +#define DEBUG 0
//texture binding with normalised coords
void bindTexture(ofBaseHasTexture &t) {
@@ -74,9 +75,9 @@ void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) { }
void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift){
-
-
-
+
+
+
// test screen shape
/*
ofSetColor(255,0,0);
@@ -86,7 +87,7 @@ void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,pla ofRect(0,h/2,w/2,h/2);
ofRect(w/2,0,w/2,h/2);
*/
-
+
rb1.begin();
//can be done with texture offset?
@@ -95,7 +96,7 @@ void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,pla while (startx>0) startx-=(w*fscale);
int starty=((h-(h*fscale))/2)+yshift;
while (starty>0) starty-=(h*fscale);
-
+
for (int i=startx;i<w*2;i+=(w*fscale)) {
for (int j=starty;j<h*2;j+=(h*fscale)) {
rb2.draw(i,j,w*fscale,h*fscale);
@@ -138,7 +139,7 @@ void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,pla ofSetColor(255,255,255);
rb1.draw(0,0);
rb2.end();
-
+
ofPushMatrix();
ofTranslate(x+(w/2),y+(h/2));
ofRotate(r);
@@ -146,9 +147,9 @@ void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,pla ofTranslate(ox,oy);
rb2.draw(0,0);
-
+
ofPopStyle();
-
+
ofPopMatrix();
}
@@ -169,15 +170,61 @@ mappedviewport::mappedviewport(int _w,int _h,int _x,int _y,float _r,int _ox,int }
void mappedviewport::setUG(ofxUserGenerator *_rUser){
rUser=_rUser;
+} +void viewport::setcam(map<string,string>&settings){ + + 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); +} +double viewport::getSetting(const string& setting){ + 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 viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift){
- //printf("draw mapped%s\n",ofGetFrameNum());
- rb1.begin();
+ + 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()); + 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))); + + rb1.begin(); + + camera.begin(); +
int startx=((w-(w*fscale))/2)+xshift;
while (startx>0) startx-=(w*fscale);
int starty=((h-(h*fscale))/2)+yshift;
while (starty>0) starty-=(h*fscale);
-
+
for (int i=startx;i<w*2;i+=(w*fscale)) {
for (int j=starty;j<h*2;j+=(h*fscale)) {
rb2.draw(i,j,w*fscale,h*fscale);
@@ -212,10 +259,12 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, }
break;
}
- }
+ } + + camera.end();
rb1.end();
-
+
rb2.begin();
ofSetColor(255,255,255);
rb1.draw(0,0);
@@ -225,22 +274,22 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, ofSetColor(255,255,255);
ofBackground(0,0,0);
//rb1.draw(0,0);
-
+
//map onto kinect skeleton
bindTexture(rb1);
-
+
glPushMatrix();
glScalef(ofGetWidth()/640.0f,ofGetHeight()/480.0f, 1);
for (int i=0;i<rUser->getNumberOfTrackedUsers();i++){
ofxTrackedUser* u=(rUser->getTrackedUser(i+1));
-
+
//if (u->skeletonTracking) {
if (u->neck.found) {
// u->debugDraw();
//ofxTrackedUser* u=
//printf("%i\n",(int)recordUser.getTrackedUser(i)->id);
//printf("tracking\n");
-
+
/*
glBegin(GL_QUADS);
glVertex3i(u->hip.position[0].X, u->hip.position[0].Y,u->hip.position[0].Z);
@@ -249,7 +298,7 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, glVertex3i(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y, u->left_shoulder.position[1].Z);
glEnd();
*/
-
+
/*
glBegin(GL_QUADS);
glVertex3i(u->hip.position[0].X, u->hip.position[0].Y,0);
@@ -258,40 +307,40 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, glVertex3i(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y,0);
glEnd();
*/
-
+
float ratio=16.0f/9.0f;
float heightratio=0.8f;
float widthratio=0.8f;
-
+
float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip width x
float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); //hip width y
-
+
float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips
float cy=(float)(u->hip.position[0].Y)+(ay*0.5f);
-
+
float hx=(((float)(u->left_shoulder.position[0].X))-cx); //height of torso
float hy=(((float)(u->left_shoulder.position[0].Y))-cy);
-
+
float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom
- float p1y=cy+(hy*(1.0f-heightratio)*0.5f);
-
+ float p1y=cy+(hy*(1.0f-heightratio)*0.5f);
+
float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top
float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f)));
-
+
ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio),0);
ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio),0);
ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio),0);
ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio),0);
-
-
+
+
/*
ofVec3f c1=ofVec3f(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y,0);
ofVec3f c2=ofVec3f(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,0);
ofVec3f c3=ofVec3f(u->hip.position[1].X, u->hip.position[1].Y,0);
ofVec3f c4=ofVec3f(u->hip.position[0].X, u->hip.position[0].Y,0);
*/
-
-
+
+
/*
glBegin(GL_QUADS);
glVertex3i(u->hip.position[1].X, u->hip.position[1].Y,0);
@@ -300,8 +349,8 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, glVertex3i(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,0);
glEnd();
*/
-
-
+
+
ofMesh targ;
targ.addVertex(c1);
targ.addTexCoord(ofVec2f(0,0));
@@ -316,22 +365,22 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, targ.addVertex(c4);
targ.addTexCoord(ofVec2f(1,1));
targ.draw();
-
-
-
+
+
+
//ofLine(u->left_shoulder.position[1].X,u->left_shoulder.position[1].Y,u->left_shoulder.position[1].Z,u->right_shoulder.position[1].X,u->right_shoulder.position[1].Y,u->right_shoulder.position[1].Z);
ofLine(u->right_shoulder.position[1].X,u->right_shoulder.position[1].Y,u->right_shoulder.position[1].Z,u->right_lower_torso.position[1].X,u->right_lower_torso.position[1].Y,u->right_lower_torso.position[1].Z);
ofLine(u->right_lower_torso.position[1].X,u->right_lower_torso.position[1].Y,u->right_lower_torso.position[1].Z,u->left_lower_torso.position[1].X,u->left_lower_torso.position[1].Y,u->left_lower_torso.position[1].Z);
ofLine(u->left_lower_torso.position[1].X,u->left_lower_torso.position[1].Y,u->left_lower_torso.position[1].Z,u->left_shoulder.position[1].X,u->left_shoulder.position[1].Y,u->left_shoulder.position[1].Z);
-
+
}
}
glPopMatrix();
unbindTexture(rb1);
-
-
+
+
rb3.end();
-
+
ofPushMatrix();
ofTranslate(x+(w/2),y+(h/2));
ofRotate(r);
@@ -339,9 +388,32 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, ofTranslate(ox,oy);
rb3.draw(0,0);
-
+
ofPopStyle();
-
+
ofPopMatrix();
+} +//-------------------------------------------------------------- +void viewport::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 viewport::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(); +} +//-------------------------------------------------------------- +void viewport::keyReleased(int key){ + for (int i=0;i<8;i++) vars[i].keyReleased(key); }
|
