void CBodyBasics::StartOSC() { // UDP stuff // RECEIVER recvsock.bindTo(RECVPORT); if (!recvsock.isOk()) { std::string s = "Error opening port " + std::to_string(RECVPORT) + ": " + recvsock.errorMessage() + "\n"; printFucker(s); } else { std::string s = "Server started, will listen to packets on port " + std::to_string(RECVPORT) + "\n"; printFucker(s); } // INITAL SENDER //sock.connectTo("localhost", 8000); clients[0].address = "localhost"; clients[0].socket.connectTo("localhost", SENDPORT); clients[0].active = true; Message msg; PacketWriter pw; msg.init("/connected"); pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); clients[0].socket.sendPacket(pw.packetData(), pw.packetSize()); }
void CBodyBasics::TransmitBody(INT64 nTime, int nBodyCount, IBody** ppBodies) { // UDP Message msg; PacketWriter pw; bool ok; HRESULT hr; for (int cptr = 0; cptr < clients.size(); cptr++) { if (clients[cptr].active == 1) { //printFucker("sending to client " + clients[cptr].address + ": " + std::to_string(nBodyCount) + " bodies!\n"); // SEND FRAME START OVER UDP msg.init("/beginFrame"); msg.pushInt32(nBodyCount); pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); ok = clients[cptr].socket.sendPacket(pw.packetData(), pw.packetSize()); for (int i = 0; i < nBodyCount; ++i) { IBody* pBody = ppBodies[i]; if (pBody) { BOOLEAN bTracked = false; hr = pBody->get_IsTracked(&bTracked); if (SUCCEEDED(hr) && bTracked) { Joint joints[JointType_Count]; D2D1_POINT_2F jointPoints[JointType_Count]; HandState leftHandState = HandState_Unknown; HandState rightHandState = HandState_Unknown; pBody->get_HandLeftState(&leftHandState); pBody->get_HandRightState(&rightHandState); hr = pBody->GetJoints(_countof(joints), joints); if (SUCCEEDED(hr)) { msg.init("/beginBody"); msg.pushInt32(i); pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); ok = clients[cptr].socket.sendPacket(pw.packetData(), pw.packetSize()); for (int j = 0; j < _countof(joints); ++j) { // /kinect body joint x y z msg.init("/bodyJoint"); msg.pushInt32(i); msg.pushInt32(j); // body relative - joints[1] is spineMid which maps to Torso in OpenNI msg.pushFloat(joints[j].Position.X - joints[1].Position.X); msg.pushFloat(joints[j].Position.Y - joints[1].Position.Y); msg.pushFloat(joints[j].Position.Z - joints[1].Position.Z); // send message pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); ok = clients[cptr].socket.sendPacket(pw.packetData(), pw.packetSize()); } msg.init("/endBody"); msg.pushInt32(i); pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); ok = clients[cptr].socket.sendPacket(pw.packetData(), pw.packetSize()); } } } } // SEND FRAME END OVER UDP msg.init("/endFrame"); pw.init(); pw.startBundle().startBundle().addMessage(msg).endBundle().endBundle(); ok = clients[cptr].socket.sendPacket(pw.packetData(), pw.packetSize()); } } }