void Level::load(World &world) const { fs::DataFile df(datafile()); tinyxml2::XMLDocument doc; { fs::DataStream ds(df, "terrain.xml"); string xmlstr = string( (std::istreambuf_iterator<char>(ds)), std::istreambuf_iterator<char>()); int error = doc.Parse(xmlstr.c_str()); if(error != tinyxml2::XML_NO_ERROR) throw LevelException(doc.GetErrorStr1()); } const XMLElement *root = doc.RootElement(); setWorldBounds(root, world); const XMLElement *el = root->FirstChildElement(); while(el) { if(strcmp(el->Name(), "zones")==0) loadZones(el, world); else if(strcmp(el->Name(), "static")==0) loadStatic(el, world); else if(strcmp(el->Name(), "solid")==0) loadSolid(el, world); else { #ifndef NDEBUG cerr << "Warning: Unknown level file element: " << el->Name() << endl; #endif } el = el->NextSiblingElement(); } }
//-------------------------------------------------------------- void testApp::setup() { ofSetLogLevel(OF_LOG_VERBOSE); ofEnableAlphaBlending(); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofTrueTypeFont::setGlobalDpi(72); font.loadFont("GUI/dinnextroundedltprolight.ttf", 28, true, true); // enable depth->rgb image calibration kinect.setRegistration(true); //kinect.init(); //kinect.init(true); // shows infrared instead of RGB video image kinect.init(false, false); // disable video image (faster fps) kinect.open(); angle=kinect.getCurrentCameraTiltAngle(); //kinect.setCameraTiltAngle(angle); //ofSleepMillis(1000); kinect.enableDepthNearValueWhite(true); ofAddListener(blob2DTracker.blobAdded, this, &testApp::blob2DAdded); ofAddListener(blob2DTracker.blobMoved, this, &testApp::blob2DMoved); ofAddListener(blob2DTracker.blobDeleted, this, &testApp::blob2DDeleted); blobFinder.init(&kinect, true); // standarized coordinate system: z in the direction of gravity blobFinder.setResolution(BF_LOW_RES); blobFinder.setRotation( ofVec3f( angle, 0, 0) ); blobFinder.setTranslation(ofVec3f(0,0,0)); blobFinder.setScale(ofVec3f(0.001, 0.001, 0.001)); // mm to meters // bind our kinect to the blob finder // in order to do this we need to declare in testApp.h: class testApp : public ofBaseApp, public ofxKinectBlobListener blobTracker.setListener( this ); blobImage.allocate(kinect.width, kinect.height, OF_IMAGE_GRAYSCALE); background.allocate(kinect.width, kinect.height, OF_IMAGE_GRAYSCALE); backgroundTex.allocate(kinect.width, kinect.height);//,OF_IMAGE_GRAYSCALE); inPainter.setup(kinect.width, kinect.height); tmpMapMask = new unsigned char[kinect.width*kinect.height]; tmpZonesMask = new unsigned char[kinect.width*kinect.height]; nearThreshold=10000.; farThreshold=10000.; diffThreshold=100.; maxBlobs = 10; minBlobPoints=250; maxBlobPoints=1000000; // NOTE: measurement units in meters!!! minBlobVol = 0.02f; maxBlobVol = 2.0f; damping=10.; mass=1.; K=30.; /*zonesCols=3; zonesRows=3; zonesColSpacing=20; zonesRowSpacing=20;*/ dilate=10; erode=10; getPitchAndRoll=false; pitch=0.; roll=0.; mapPoint=0; mapFbo.allocate(kinect.width,kinect.height); mapPixels.allocate(kinect.width,kinect.height,OF_IMAGE_GRAYSCALE); mapMask.allocate(kinect.width, kinect.height); zonesDistance=10.; zonesFbo.allocate(kinect.width,kinect.height); gui = new ofxUISuperCanvas("kinectMap", OFX_UI_FONT_MEDIUM); gui->addSpacer(); gui->addTextArea("CONTROL", "Control de parametros de kinectMap"); gui->addSpacer(); gui->addSlider("angle", -30, 30, &angle); gui->addLabelToggle("learnBackground", &learnBackground); gui->addSlider("backFrames", 0.0, BACKGROUND_FRAMES, &backFrames); gui->addSpacer(); gui->addSlider("maxBlobs", 0, 20, &maxBlobs); gui->addSlider("min blob points", 0, 2000, &minBlobPoints); gui->addSlider("min blob vol", 0.0, 0.2, &minBlobVol); gui->addSlider("max blob vol", 1., 10., &maxBlobVol); gui->addSpacer(); gui->addRangeSlider("near and far threshold", 0., 5000., &nearThreshold,&farThreshold); gui->addSlider("diff threshold", 0., 1000., &diffThreshold); gui->addSpacer(); gui->addSlider("person damping", 0., 10., &damping); gui->addSlider("person mass", 1., 10., &mass); gui->addSlider("person K", 1., 30., &K); gui->addSpacer(); gui->addLabelToggle("get pitch and roll",&getPitchAndRoll); gui->addSlider("pitch", -180., 180., &pitch); gui->addSlider("roll", -180., 180., &roll); gui->addSpacer(); gui->addLabelToggle("mapOpen", &mapOpen); gui->addSpacer(); gui->addLabelButton("zonesNew", &zonesNew); gui->addLabelButton("zonesClear", &zonesClear); gui->addSpacer(); gui->addSlider("dilate", 0, 20, &dilate); gui->addSlider("erode", 0, 20, &erode); gui->autoSizeToFitWidgets(); ofAddListener(gui->newGUIEvent,this,&testApp::guiEvent); if(ofFile::doesFileExist("GUI/guiSettings.xml")) gui->loadSettings("GUI/guiSettings.xml"); loadMap(); loadZones(); sender.setup(IP,PORT); mapOpen=false; zonesNew=false; zonesClear=false; rotation.makeRotationMatrix(-90-pitch,ofVec3f(1,0,0),0,ofVec3f(0,1,0),-roll,ofVec3f(0,0,1)); learnBackground = true; backFrames=0.; ofSetFrameRate(60); }