Mercurial > hg > mtri-kinectui
changeset 4:c843a959013f tip
Now using OSC bundles;
some reorganisation and const-ification of code.
author | samer |
---|---|
date | Tue, 28 Feb 2012 11:36:30 +0000 |
parents | f3a1dc7d3596 |
children | |
files | grouptrack2.xcodeproj/samer.mode1v3 grouptrack2.xcodeproj/samer.pbxuser release/TriangleTracker-bin.tar.gz src/testApp.cpp src/testApp.h |
diffstat | 5 files changed, 210 insertions(+), 169 deletions(-) [+] |
line wrap: on
line diff
--- a/grouptrack2.xcodeproj/samer.mode1v3 Fri Feb 24 19:02:07 2012 +0000 +++ b/grouptrack2.xcodeproj/samer.mode1v3 Tue Feb 28 11:36:30 2012 +0000 @@ -279,7 +279,7 @@ </array> </array> <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key> - <string>{{0, 0}, {186, 815}}</string> + <string>{{0, 0}, {186, 680}}</string> </dict> <key>PBXTopSmartGroupGIDs</key> <array/> @@ -291,14 +291,14 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 0}, {203, 833}}</string> + <string>{{0, 0}, {203, 698}}</string> <key>GroupTreeTableConfiguration</key> <array> <string>MainColumn</string> <real>186</real> </array> <key>RubberWindowFrame</key> - <string>161 890 1046 874 0 800 1280 1024 </string> + <string>103 35 1046 739 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXSmartGroupTreeModule</string> @@ -328,13 +328,14 @@ <key>_historyCapacity</key> <integer>0</integer> <key>bookmark</key> - <string>31BC1D8514F716A800A2BDCD</string> + <string>3173910A14FCF2D30035A86C</string> <key>history</key> <array> <string>31605DB414F6EE8B0047CE1E</string> - <string>31605DB514F6EE8B0047CE1E</string> <string>3160608D14F70DCC0047CE1E</string> - <string>31510F4914F712E7005E7F5F</string> + <string>3173909514FCDECC0035A86C</string> + <string>3173910614FCF2B90035A86C</string> + <string>3173910714FCF2B90035A86C</string> </array> </dict> <key>SplitCount</key> @@ -346,14 +347,14 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 0}, {838, 828}}</string> + <string>{{0, 0}, {838, 693}}</string> <key>RubberWindowFrame</key> - <string>161 890 1046 874 0 800 1280 1024 </string> + <string>103 35 1046 739 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXNavigatorGroup</string> <key>Proportion</key> - <string>828pt</string> + <string>693pt</string> </dict> <dict> <key>ContentConfiguration</key> @@ -368,7 +369,7 @@ <key>Frame</key> <string>{{0, 833}, {838, 0}}</string> <key>RubberWindowFrame</key> - <string>161 890 1046 874 0 800 1280 1024 </string> + <string>103 35 1046 739 0 0 1280 778 </string> </dict> <key>Module</key> <string>XCDetailModule</string> @@ -392,9 +393,9 @@ </array> <key>TableOfContents</key> <array> - <string>31BC1D8214F7168200A2BDCD</string> + <string>3173907D14FCDBF00035A86C</string> <string>1CE0B1FE06471DED0097A5F4</string> - <string>31BC1D8314F7168200A2BDCD</string> + <string>3173907E14FCDBF00035A86C</string> <string>1CE0B20306471E060097A5F4</string> <string>1CE0B20506471E060097A5F4</string> </array> @@ -532,15 +533,16 @@ <integer>5</integer> <key>WindowOrderList</key> <array> - <string>31BC1D8D14F716A800A2BDCD</string> - <string>31BC1D8E14F716A800A2BDCD</string> + <string>317390A114FCDECC0035A86C</string> + <string>317390A214FCDECC0035A86C</string> + <string>1CD10A99069EF8BA00B06720</string> + <string>1C530D57069F1CE1000CFCEE</string> + <string>3121663E14F6DE5800456939</string> <string>1C78EAAD065D492600B07095</string> - <string>1CD10A99069EF8BA00B06720</string> - <string>3121663E14F6DE5800456939</string> <string>/usr/local/src/OpenFrameworks/of_preRelease_v007_osx/apps/examples/mtri-kinectui/grouptrack2.xcodeproj</string> </array> <key>WindowString</key> - <string>161 890 1046 874 0 800 1280 1024 </string> + <string>103 35 1046 739 0 0 1280 778 </string> <key>WindowToolsV3</key> <array> <dict> @@ -561,23 +563,25 @@ <key>PBXProjectModuleGUID</key> <string>1CD0528F0623707200166675</string> <key>PBXProjectModuleLabel</key> - <string></string> + <string>testApp.cpp</string> <key>StatusBarVisibility</key> <true/> </dict> <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 0}, {733, 0}}</string> + <string>{{0, 0}, {733, 167}}</string> <key>RubberWindowFrame</key> - <string>433 1158 733 603 0 800 1280 1024 </string> + <string>433 154 733 603 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXNavigatorGroup</string> <key>Proportion</key> - <string>0pt</string> + <string>167pt</string> </dict> <dict> + <key>BecomeActive</key> + <true/> <key>ContentConfiguration</key> <dict> <key>PBXProjectModuleGUID</key> @@ -592,14 +596,14 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 5}, {733, 557}}</string> + <string>{{0, 172}, {733, 390}}</string> <key>RubberWindowFrame</key> - <string>433 1158 733 603 0 800 1280 1024 </string> + <string>433 154 733 603 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXBuildResultsModule</string> <key>Proportion</key> - <string>557pt</string> + <string>390pt</string> </dict> </array> <key>Proportion</key> @@ -617,7 +621,7 @@ <key>TableOfContents</key> <array> <string>3121663E14F6DE5800456939</string> - <string>31BC1D8414F7168200A2BDCD</string> + <string>3173907F14FCDBF00035A86C</string> <string>1CD0528F0623707200166675</string> <string>XCMainBuildResultsModuleGUID</string> </array> @@ -626,7 +630,7 @@ <key>WindowContentMinSize</key> <string>486 300</string> <key>WindowString</key> - <string>433 1158 733 603 0 800 1280 1024 </string> + <string>433 154 733 603 0 0 1280 778 </string> <key>WindowToolGUID</key> <string>3121663E14F6DE5800456939</string> <key>WindowToolIsVisible</key> @@ -661,8 +665,8 @@ <string>yes</string> <key>sizes</key> <array> - <string>{{0, 0}, {316, 201}}</string> - <string>{{316, 0}, {378, 201}}</string> + <string>{{0, 0}, {316, 202}}</string> + <string>{{316, 0}, {378, 202}}</string> </array> </dict> <key>VerticalSplitView</key> @@ -677,8 +681,8 @@ <string>yes</string> <key>sizes</key> <array> - <string>{{0, 0}, {694, 201}}</string> - <string>{{0, 201}, {694, 180}}</string> + <string>{{0, 0}, {694, 202}}</string> + <string>{{0, 202}, {694, 179}}</string> </array> </dict> </dict> @@ -711,7 +715,7 @@ <real>148</real> </array> <key>Frame</key> - <string>{{316, 0}, {378, 201}}</string> + <string>{{316, 0}, {378, 202}}</string> <key>RubberWindowFrame</key> <string>262 333 694 422 0 0 1280 778 </string> </dict> @@ -739,13 +743,13 @@ <key>TableOfContents</key> <array> <string>1CD10A99069EF8BA00B06720</string> - <string>31BC1D8614F716A800A2BDCD</string> + <string>3173909914FCDECC0035A86C</string> <string>1C162984064C10D400B95A72</string> - <string>31BC1D8714F716A800A2BDCD</string> - <string>31BC1D8814F716A800A2BDCD</string> - <string>31BC1D8914F716A800A2BDCD</string> - <string>31BC1D8A14F716A800A2BDCD</string> - <string>31BC1D8B14F716A800A2BDCD</string> + <string>3173909A14FCDECC0035A86C</string> + <string>3173909B14FCDECC0035A86C</string> + <string>3173909C14FCDECC0035A86C</string> + <string>3173909D14FCDECC0035A86C</string> + <string>3173909E14FCDECC0035A86C</string> </array> <key>ToolbarConfiguration</key> <string>xcode.toolbar.config.debugV3</string> @@ -757,8 +761,12 @@ <false/> </dict> <dict> + <key>FirstTimeWindowDisplayed</key> + <false/> <key>Identifier</key> <string>windowTool.find</string> + <key>IsVertical</key> + <true/> <key>Layout</key> <array> <dict> @@ -773,26 +781,16 @@ <key>PBXProjectModuleGUID</key> <string>1CDD528C0622207200134675</string> <key>PBXProjectModuleLabel</key> - <string><No Editor></string> - <key>PBXSplitModuleInNavigatorKey</key> - <dict> - <key>Split0</key> - <dict> - <key>PBXProjectModuleGUID</key> - <string>1CD0528D0623707200166675</string> - </dict> - <key>SplitCount</key> - <string>1</string> - </dict> + <string>ofxOscBundle.h</string> <key>StatusBarVisibility</key> - <integer>1</integer> + <true/> </dict> <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 0}, {781, 167}}</string> + <string>{{0, 0}, {781, 212}}</string> <key>RubberWindowFrame</key> - <string>62 385 781 470 0 0 1440 878 </string> + <string>182 285 781 470 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXNavigatorGroup</string> @@ -801,11 +799,11 @@ </dict> </array> <key>Proportion</key> - <string>50%</string> + <string>212pt</string> </dict> <dict> <key>BecomeActive</key> - <integer>1</integer> + <true/> <key>ContentConfiguration</key> <dict> <key>PBXProjectModuleGUID</key> @@ -816,18 +814,18 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{8, 0}, {773, 254}}</string> + <string>{{0, 217}, {781, 212}}</string> <key>RubberWindowFrame</key> - <string>62 385 781 470 0 0 1440 878 </string> + <string>182 285 781 470 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXProjectFindModule</string> <key>Proportion</key> - <string>50%</string> + <string>212pt</string> </dict> </array> <key>Proportion</key> - <string>428pt</string> + <string>429pt</string> </dict> </array> <key>Name</key> @@ -837,23 +835,21 @@ <string>PBXProjectFindModule</string> </array> <key>StatusbarIsVisible</key> - <integer>1</integer> + <true/> <key>TableOfContents</key> <array> <string>1C530D57069F1CE1000CFCEE</string> - <string>1C530D58069F1CE1000CFCEE</string> - <string>1C530D59069F1CE1000CFCEE</string> + <string>3173908314FCDC110035A86C</string> + <string>3173908414FCDC110035A86C</string> <string>1CDD528C0622207200134675</string> - <string>1C530D5A069F1CE1000CFCEE</string> - <string>1CE0B1FE06471DED0097A5F4</string> <string>1CD0528E0623707200166675</string> </array> <key>WindowString</key> - <string>62 385 781 470 0 0 1440 878 </string> + <string>182 285 781 470 0 0 1280 778 </string> <key>WindowToolGUID</key> <string>1C530D57069F1CE1000CFCEE</string> <key>WindowToolIsVisible</key> - <integer>0</integer> + <false/> </dict> <dict> <key>Identifier</key> @@ -872,6 +868,8 @@ <key>Dock</key> <array> <dict> + <key>BecomeActive</key> + <true/> <key>ContentConfiguration</key> <dict> <key>PBXProjectModuleGUID</key> @@ -884,7 +882,7 @@ <key>Frame</key> <string>{{0, 0}, {682, 311}}</string> <key>RubberWindowFrame</key> - <string>649 426 682 352 0 0 1280 778 </string> + <string>597 425 682 352 0 0 1280 778 </string> </dict> <key>Module</key> <string>PBXDebugCLIModule</string> @@ -907,17 +905,17 @@ <key>TableOfContents</key> <array> <string>1C78EAAD065D492600B07095</string> - <string>31BC1D8C14F716A800A2BDCD</string> + <string>3173909F14FCDECC0035A86C</string> <string>1C78EAAC065D492600B07095</string> </array> <key>ToolbarConfiguration</key> <string>xcode.toolbar.config.consoleV3</string> <key>WindowString</key> - <string>649 426 682 352 0 0 1280 778 </string> + <string>597 425 682 352 0 0 1280 778 </string> <key>WindowToolGUID</key> <string>1C78EAAD065D492600B07095</string> <key>WindowToolIsVisible</key> - <false/> + <true/> </dict> <dict> <key>Identifier</key>
--- a/grouptrack2.xcodeproj/samer.pbxuser Fri Feb 24 19:02:07 2012 +0000 +++ b/grouptrack2.xcodeproj/samer.pbxuser Tue Feb 28 11:36:30 2012 +0000 @@ -7,7 +7,7 @@ argumentStrings = ( ); autoAttachOnCrash = 1; - breakpointsEnabled = 0; + breakpointsEnabled = 1; configStateDict = { }; customDataFormattersEnabled = 1; @@ -46,15 +46,12 @@ isa = PBXCodeSenseManager; indexTemplatePath = ""; }; - 31510F4914F712E7005E7F5F /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; - name = "testApp.cpp: 117"; - rLen = 0; - rLoc = 2967; - rType = 0; - vrLen = 2033; - vrLoc = 2547; + 3121668614F6E91A00456939 /* ofxOscBundle.h */ = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {720, 845}}"; + sepNavSelRange = "{0, 0}"; + sepNavVisRange = "{0, 667}"; + }; }; 31605DB414F6EE8B0047CE1E /* PBXTextBookmark */ = { isa = PBXTextBookmark; @@ -66,16 +63,6 @@ vrLen = 325; vrLoc = 0; }; - 31605DB514F6EE8B0047CE1E /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; - name = "testApp.h: 16"; - rLen = 0; - rLoc = 218; - rType = 0; - vrLen = 1146; - vrLoc = 0; - }; 31605F7D14F7043A0047CE1E /* ofxOpenNIContext.cpp */ = { uiCtxt = { sepNavIntBoundsRect = "{{0, 0}, {777, 3471}}"; @@ -93,15 +80,45 @@ vrLen = 1708; vrLoc = 0; }; - 31BC1D8514F716A800A2BDCD /* PBXTextBookmark */ = { + 3173909514FCDECC0035A86C /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 3121668614F6E91A00456939 /* ofxOscBundle.h */; + name = "ofxOscBundle.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 1675; + vrLoc = 803; + }; + 3173910614FCF2B90035A86C /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1F0A3A1BDC003C02F2 /* testApp.h */; + name = "testApp.h: 45"; + rLen = 0; + rLoc = 935; + rType = 0; + vrLen = 1113; + vrLoc = 242; + }; + 3173910714FCF2B90035A86C /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; - name = "testApp.cpp: 117"; + name = "testApp.cpp: 85"; rLen = 0; - rLoc = 2967; + rLoc = 2144; rType = 0; - vrLen = 2033; - vrLoc = 2547; + vrLen = 1365; + vrLoc = 1253; + }; + 3173910A14FCF2D30035A86C /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; + name = "testApp.cpp: 124"; + rLen = 0; + rLoc = 3106; + rType = 0; + vrLen = 1406; + vrLoc = 2673; }; E4B69B4C0A3A1720003C02F2 /* Project object */ = { activeBuildConfigurationName = Release; @@ -110,6 +127,8 @@ addToTargets = ( E4B69B5A0A3A1756003C02F2 /* TriangleTracker */, ); + breakpoints = ( + ); codeSenseManager = 3121663814F6DE1700456939 /* Code sense */; executables = ( 3121663314F6DDF900456939 /* TriangleTracker */, @@ -137,15 +156,16 @@ PBXFileDataSource_Target_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 351737468; - PBXWorkspaceStateSaveDate = 351737468; + PBXPerProjectTemplateStateSaveDate = 352115674; + PBXWorkspaceStateSaveDate = 352115674; }; perUserProjectItems = { - 31510F4914F712E7005E7F5F /* PBXTextBookmark */ = 31510F4914F712E7005E7F5F /* PBXTextBookmark */; 31605DB414F6EE8B0047CE1E /* PBXTextBookmark */ = 31605DB414F6EE8B0047CE1E /* PBXTextBookmark */; - 31605DB514F6EE8B0047CE1E /* PBXTextBookmark */ = 31605DB514F6EE8B0047CE1E /* PBXTextBookmark */; 3160608D14F70DCC0047CE1E /* PBXTextBookmark */ = 3160608D14F70DCC0047CE1E /* PBXTextBookmark */; - 31BC1D8514F716A800A2BDCD /* PBXTextBookmark */ = 31BC1D8514F716A800A2BDCD /* PBXTextBookmark */; + 3173909514FCDECC0035A86C /* PBXTextBookmark */ = 3173909514FCDECC0035A86C /* PBXTextBookmark */; + 3173910614FCF2B90035A86C /* PBXTextBookmark */ = 3173910614FCF2B90035A86C /* PBXTextBookmark */; + 3173910714FCF2B90035A86C /* PBXTextBookmark */ = 3173910714FCF2B90035A86C /* PBXTextBookmark */; + 3173910A14FCF2D30035A86C /* PBXTextBookmark */ = 3173910A14FCF2D30035A86C /* PBXTextBookmark */; }; sourceControlManager = 3121663714F6DE1700456939 /* Source Control */; userBuildSettings = { @@ -166,16 +186,16 @@ }; E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {777, 4433}}"; - sepNavSelRange = "{2967, 0}"; - sepNavVisRange = "{2547, 2033}"; + sepNavIntBoundsRect = "{{0, 0}, {712, 4680}}"; + sepNavSelRange = "{7406, 0}"; + sepNavVisRange = "{7256, 392}"; }; }; E4B69E1F0A3A1BDC003C02F2 /* testApp.h */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {777, 806}}"; - sepNavSelRange = "{218, 0}"; - sepNavVisRange = "{0, 1146}"; + sepNavIntBoundsRect = "{{0, 0}, {777, 845}}"; + sepNavSelRange = "{935, 0}"; + sepNavVisRange = "{242, 1113}"; }; }; }
--- a/src/testApp.cpp Fri Feb 24 19:02:07 2012 +0000 +++ b/src/testApp.cpp Tue Feb 28 11:36:30 2012 +0000 @@ -17,21 +17,34 @@ // Callback: A user was found void XN_CALLBACK_TYPE NewUserDetected(UserGenerator& rGenerator,XnUserID nID ,void* pCookie) { printf("New User %d\n", nID); - send_osc_i(((testApp*)pCookie)->sender),"/birth",nID); } // Callback: An existing user was lost void XN_CALLBACK_TYPE UserLostDetected(UserGenerator& rGenerator ,XnUserID nID ,void* pCookie) { printf("Lost user %d\n", nID); - send_osc_i(((testApp*)pCookie)->sender),"/death",nID); } */ -static void inline send_osc_i(ofxOscSender& sender, const char *path, int arg) { - ofxOscMessage msg; - msg.setAddress(path); - msg.addIntArg(arg); +static inline ofxOscMessage msg(const char *path, int arg) { + ofxOscMessage m; + m.setAddress(path); + m.addIntArg(arg); + return m; +} + +static inline ofxOscBundle& operator<<(ofxOscBundle &bundle, ofxOscMessage msg) { + bundle.addMessage(msg); + return bundle; +} + +static inline ofxOscSender& operator<<(ofxOscSender &sender, ofxOscMessage msg) { sender.sendMessage(msg); + return sender; +} + +static inline ofxOscSender& operator<<(ofxOscSender &sender, ofxOscBundle bundle) { + sender.sendBundle(bundle); + return sender; } static inline void check_rc(XnStatus rc, const char *tag){ @@ -55,11 +68,11 @@ int X, Y, Z; inline void set(int x, int y, int z) { X=x; Y=y; Z=z; } inline void add(int x, int y, int z) { X+=x; Y+=y; Z+=z; } - inline void div(float d, XnVector3D *p) { p->X=X/d; p->Y=Y/d; p->Z=Z/d; } - inline void cpy(XnVector3D *p) { p->X=X; p->Y=Y; p->Z=Z; } + inline void div(float d, XnVector3D *p) const { p->X=X/d; p->Y=Y/d; p->Z=Z/d; } + inline void cpy(XnVector3D *p) const { p->X=X; p->Y=Y; p->Z=Z; } }; -static void project_into_plane(XnPlane3D& plane, XnVector3D& r, XnVector3D *q) { +static void project_into_plane(const XnPlane3D& plane, const XnVector3D& r, XnVector3D *q) { float l = (r.X-plane.ptPoint.X)*plane.vNormal.X + (r.Y-plane.ptPoint.Y)*plane.vNormal.Y + (r.Z-plane.ptPoint.Z)*plane.vNormal.Z; @@ -69,6 +82,7 @@ q->Z = r.Z - l*plane.vNormal.Z; } + class UserStats { public: struct int3d left, right, top, bottom, sum; @@ -82,8 +96,8 @@ numPixels=0; } - inline int area() { return numPixels; } - inline void centroid(XnVector3D *p) { sum.div(numPixels,p); } + inline int area() const { return numPixels; } + inline void centroid(XnVector3D *p) const { sum.div(numPixels,p); } inline void accum(int x, int y, int z) { if (x<left.X) left.set(x,y,z); if (x>right.X) right.set(x,y,z); @@ -107,7 +121,7 @@ printf("OSC target: %s:%d.\n",host,port); printf("Will run at %d frames per second.\n",FPS); sender.setup(host, port); - draw_image=2; + draw_image=1; } static XnMapOutputMode fps_map_mode(int fps) { @@ -174,6 +188,7 @@ // get pixels for all users, for each compute centroid and bounding rectangle { UserStats stats[MAX_USERS]; + ofxOscBundle bundle; userGenerator.GetUserPixels(0, sceneMetaData); // 0 for all users unsigned short *userRawPixels = (unsigned short*)sceneMetaData.Data(); @@ -200,80 +215,87 @@ } for (int id0=0; id0<MAX_USERS; id0++) { - if (stats[id0].area()>0) { + int area=stats[id0].area(); + if (area>0) { // user present + XnVector3D proj; // projective coors of centroid + + update_user(stats[id0], &users[id0], &proj); // sets proj if (!users[id0].present) { - send_osc_i(sender,"/birth",id0+1); - send_osc_i(sender,"/randinit",id0+1); - send_osc_i(sender,"/start",id0+1); users[id0].present=true; + bundle << msg("/birth",id0+1); + bundle << msg("/randinit",id0+1); + if (got_floor) { + bundle << track(id0+1,users[id0],proj,area); + } + bundle << msg("/start",id0+1); + } else { + if (got_floor) { + bundle << track(id0+1,users[id0],proj,area); + } } - update_user(id0+1,stats[id0],&users[id0]); - } else { + } else { // user vanished, send death if (users[id0].present) { - send_osc_i(sender,"/death",id0+1); users[id0].present=false; + printf("death\n"); + bundle << msg("/death",id0+1); } } } - + + if (bundle.getMessageCount()>0) sender << bundle; } if (draw_image) { userImage.setFromPixels(imagePixels, IMGWIDTH, IMGHEIGHT, OF_IMAGE_GRAYSCALE); } } -void testApp::update_user(int id, UserStats& stats, UserData *user) { - XnVector3D proj[3], real[3]; - int *coors=user->plot_coors; +void testApp::update_user(const UserStats& stats, UserData *user, XnVector3D *proj) { + int *coors=user->plot_coors; - stats.centroid(&proj[0]); // centroid in device coordinate - stats.left.cpy(&proj[1]); // left edge in device coordinates - stats.right.cpy(&proj[2]); // right edge in device coordinates + stats.centroid(proj); // centroid in device coordinate // save values required for drawing later - coors[0]=floor(proj[0].X); - coors[1]=floor(proj[0].Y); - coors[2]=floor(proj[0].Z); + coors[0]=floor(proj->X); + coors[1]=floor(proj->Y); + coors[2]=floor(proj->Z); coors[3]=stats.left.X; coors[4]=stats.right.X; coors[5]=stats.top.Y; coors[6]=stats.bottom.Y; +} + +ofxOscMessage testApp::track(int id, const UserData& user, const XnVector3D& proj, int area) const { + ofxOscMessage m; + XnVector3D real, on_floor; + const int *coors=user.plot_coors; - if (got_floor) { - ofxOscMessage m; - XnVector3D on_floor; - - // convert to camera-centric world coordinates - depthGenerator.ConvertProjectiveToRealWorld(3,proj,real); - - // projection of centroid onto floor... - project_into_plane(floor_pie,real[0],&on_floor); - - // ...relative to projection of camera on floor - on_floor.X -= floor_offset.X; - on_floor.Y -= floor_offset.Y; - on_floor.Z -= floor_offset.Z; - - m.setAddress("/track"); - m.addIntArg(id); - - m.addFloatArg(on_floor.X); - // m.addFloatArg(on_floor.Y); // not interesting - m.addFloatArg(on_floor.Z); - - { // distances to edges of bounding box - // corrected for perspective - float z=coors[2]; // depth - m.addIntArg(z*(coors[0]-coors[3])); - m.addIntArg(z*(coors[4]-coors[0])); - m.addIntArg(z*(coors[1]-coors[5])); - m.addIntArg(z*(coors[6]-coors[1])); - // area, corrected for perspective - m.addIntArg(z*sqrt(stats.area())); - } - - sender.sendMessage(m); + // convert to camera-centric world coordinates + depthGenerator.ConvertProjectiveToRealWorld(1,&proj,&real); + + // projection of centroid onto floor... + project_into_plane(floor_pie,real,&on_floor); + + // ...relative to projection of camera on floor + on_floor.X -= floor_offset.X; + on_floor.Y -= floor_offset.Y; + on_floor.Z -= floor_offset.Z; + + m.setAddress("/track"); + m.addIntArg(id); + m.addFloatArg(on_floor.X); + m.addFloatArg(on_floor.Z); + + { // distances to edges of bounding box + // corrected for perspective + float z=coors[2]; // depth + m.addIntArg(z*(coors[0]-coors[3])); + m.addIntArg(z*(coors[4]-coors[0])); + m.addIntArg(z*(coors[1]-coors[5])); + m.addIntArg(z*(coors[6]-coors[1])); + // area, corrected for perspective + m.addIntArg(z*sqrt(area)); } + return m; } //--------------------------------------------------------------
--- a/src/testApp.h Fri Feb 24 19:02:07 2012 +0000 +++ b/src/testApp.h Tue Feb 28 11:36:30 2012 +0000 @@ -22,7 +22,7 @@ SceneAnalyzer sceneAnalyzer; SceneMetaData sceneMetaData; XnDepthPixel max_depth; - XnUInt64 timestamp; + XnUInt64 timestamp; XnPlane3D floor_pie; ofImage userImage; ofTrueTypeFont font; @@ -41,7 +41,8 @@ UserData users[MAX_USERS]; - void update_user(int id, UserStats& stats, UserData *user); + static void update_user(const UserStats& stats, UserData *user, XnVector3D *proj); + ofxOscMessage track(int id, const UserData &user, const XnVector3D &proj, int area) const; public: testApp(const char *host, int port, int fps);