summaryrefslogtreecommitdiff
path: root/03_play/src/testApp.cpp
blob: 1688ef39df10ee1706a8e1ebbec483ea3c19283f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup() {

    ofSetLogLevel(OF_LOG_NOTICE);

    verdana.loadFont(ofToDataPath("verdana.ttf"), 10);

    playing=0;
    numDevices=1;

    string filename="TRSS_nesbitt_recordings.xml";

    if( !XML.loadFile(filename) ){
        printf("unable to load recordings, check data/ folder\n");
    }else{
        if(XML.pushTag("TRSS")) {
            int num=XML.getNumTags("rec");
            if(num) {
                for (int i=0;i<num;i++) {
                    record rec;
                    rec.data.push_back(XML.getAttribute("rec","left","",i));
                    rec.data.push_back(XML.getAttribute("rec","right","",i));
                    rec.audio=XML.getAttribute("rec","audio","",i);
                    recs.push_back(rec);
                }
            }
            else printf("no recordings!\n");
        }
    }
    for (int deviceID = 0; deviceID < numDevices; deviceID++){

        //openNIPlayers[deviceID].stop();
        openNIPlayers[deviceID].setup(true);
        openNIPlayers[deviceID].start();
        //openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing][deviceID]));
    }
    soundplayer.setLoop(false);
    startPlayers();

    //ofSetFrameRate(25.0f);
    offset=0.0f;
    drawmovies=false;drawcloud=true;
    frame=0;
}

void testApp::startPlayers(){
    for (int deviceID = 0; deviceID < numDevices; deviceID++){
        //openNIPlayers[deviceID].stop();
        openNIPlayers[deviceID].setup(true);
        usleep(100000);
        openNIPlayers[deviceID].start();
        openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing].data[deviceID]));
        //openNIPlayers[deviceID].setSpeed(0.01f);
        //openNIPlayers[deviceID].setPaused(true);
    
    
        //soundplayer.stop();
        
        //if (recs[playing].audio!=""){
        //    soundplayer.loadSound(recs[playing].audio);
        //    soundplayer.play();
        //    soundplayer.setPosition(offset);
        //}
    }
}

//--------------------------------------------------------------
void testApp::update(){
    for (int deviceID = 0; deviceID < numDevices; deviceID++){
            //openNIPlayers[deviceID].setFrame(frame);
            openNIPlayers[deviceID].update();
    }
}

//--------------------------------------------------------------
void testApp::draw(){
    ofBackground(50, 50, 50);
	ofSetColor(255, 255, 255);

    

    //glEnable(GL_PROGRAM_POINT_SIZE);
    //glEnable(GL_POINT_SMOOTH);
    //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);

    //glPointSize(12.0f);



    for (int deviceID = 0; deviceID < numDevices; deviceID++){

       if (drawmovies) {
            ofTranslate(0, deviceID * 400);
            //openNIPlayers[deviceID].drawDebug();
            openNIPlayers[deviceID].drawDepth(50, 0,520,390);
            openNIPlayers[deviceID].drawImage(600, 0,520,390);
        }

        //construct points
        //glBegin(GL_POINTS);
        //how to find buffer size?
        /*
        XnStatus xn::DepthGenerator::ConvertProjectiveToRealWorld   (   XnUInt32    nCount,
        const XnPoint3D     aProjective[],
        XnPoint3D   aRealWorld[]     
        )  
        */ 

        if (drawcloud) {

            cam.begin();

            ofPushMatrix();
            ofRotate(0,1,0,180);
            ofTranslate(0,0,1500);
            

            
            
            ofDrawAxis(100);

            int count;
            const XnDepthPixel* depthmap=openNIPlayers[deviceID].getDepthGenerator().GetDepthMap();
            int range=2500;

            int dmw=openNIPlayers[deviceID].getWidth();

                for (int i=0;i<openNIPlayers[deviceID].getWidth();i+=2) {

                    glBegin(GL_LINES);

                    for (int j=0;j<openNIPlayers[deviceID].getHeight();j+=2) {



                        ofPoint p= openNIPlayers[deviceID].projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
                        //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
                        
                        if (p.z == 0 || p.z>range) continue;    // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd
                        //ofColor color = kinect->getColorAt(x,y); //userID);
                        //if (col) glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a);
                       // else 


                        glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255);
                        glVertex3f(p.x, p.y, p.z);
                        //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
                    }

                    glEnd();
                }
            

            //export for fast/ switchable playback
            //figure out how to line up (could be one off)
                //export frame and find matching coords
                //manually find positions
                //calculate offset
            //audio sync
            //gui
            //audio analysis
            //sfx for point cloud

            //

            ofPopMatrix();

            cam.end();

            glDisable(GL_PROGRAM_POINT_SIZE);

        }
    }

	ofSetColor(255, 255, 255);
	string msg = "MILLIS: " + ofToString(ofGetElapsedTimeMillis());
    msg += "\nFPS: " + ofToString(ofGetFrameRate());
	msg += "\noffset: "+ofToString(offset);
    verdana.drawString(msg, 10, 10);
}

//--------------------------------------------------------------
void testApp::exit(){
    for (int deviceID = 0; deviceID < numDevices; deviceID++){
        openNIPlayers[deviceID].stop();
    }
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
    bool changed=false;
    switch (key) {
        case ',':
            if (playing==0) playing=recs.size();
            playing--;
            changed=true;
            break;
        case '.':
            playing=(playing+1)%recs.size();
            changed=true;
            break;
        case 'z':
            offset+=.025;
            break;
        case 'x':
            offset-=.025;
            break;
        case 'q':
            drawmovies=!drawmovies;
            break;
        case 'w':
            drawcloud=!drawcloud;
            break;
        case 'a':
            frame--;
            if (frame<0) frame=openNIPlayers[0].getTotalNumFrames()-1;
            break;
        case 's':
            frame=((frame+1)%openNIPlayers[0].getTotalNumFrames());
            break;
    }
    if (changed) startPlayers();

    /* why do this?
    switch (key) {
        case 't':
            for (int deviceID = 0; deviceID < numDevices; deviceID++){
                openNIRecorders[deviceID].toggleRegister();
            }
            break;
        case 'x':
            for (int deviceID = 0; deviceID < numDevices; deviceID++){
                openNIRecorders[deviceID].stop();
            }
            break;
        default:
            break;
    }
    */
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}