我正在尝试制作一个应用程序,它可以做一些斑点跟踪,并使用TUIO cursor消息为Unity3D发送所有数据,就像CCV所做的那样。这是我关于消息的信息("media"是一个按钮,用于在发送所有斑点的位置/id或发送平均值之间切换):
void testApp::blobOn( int x, int y, int id, int order )
{
cout << "blobOn() - id:" << id << " order:" << order << endl;
ofxOscMessage m;
m.setAddress("/tuio2/2Dcur");
m.addStringArg("set");
if(media == false){
m.addIntArg(id);
m.addFloatArg(newX);
m.addFloatArg(newY);
cout << "Posicao x: " << newX << endl;
cout << "Posicao y: " << newY << endl;
}
else{
m.addIntArg(0);
m.addFloatArg(newMediaX);
m.addFloatArg(newMediaY);
}
m.addFloatArg(0);
m.addFloatArg(0);
m.addFloatArg(0);
m.addFloatArg(0);
ofxOscMessage l;
l.setAddress("/tuio/2Dcur");
l.addStringArg("alive");
if (blobList.size() > 0)
{
if(media == false){
for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
l.addIntArg(it -> first);
cout << "it first: " << it -> first << endl;
}
}else{
l.addIntArg(0);
}
}
sender.sendMessage(l);
sender.sendMessage(m);
}
//--------------------------------------------------------------
void testApp::blobMoved( int x, int y, int id, int order)
{
cout << "blobMoved() - id:" << id << " order:" << order << endl;
ofCvTrackedBlob blob_ = blobTracker.getById( id );
ofxOscMessage m;
m.setAddress("/tuio/2Dcur");
m.addStringArg("set");
if(media == false){
m.addIntArg(id);
m.addFloatArg(newX);
m.addFloatArg(newY);
cout << "Posicao x: " << newX << endl;
cout << "Posicao y: " << newY << endl;
}
else{
m.addIntArg(0);
m.addFloatArg(newMediaX);
m.addFloatArg(newMediaY);
}
m.addFloatArg(0);
m.addFloatArg(0);
m.addFloatArg(0);
m.addFloatArg(0);
ofxOscMessage n;
n.setAddress("/tuio/2Dcur");
n.addStringArg("alive");
if (blobList.size() > 0)
{
if(media == false){
for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
n.addIntArg(it -> first);
}
}
else {
n.addIntArg(0);
}
}
sender.sendMessage(n);
sender.sendMessage(m);
}
//--------------------------------------------------------------
void testApp::blobOff( int x, int y, int id, int order )
{
cout << "blobOff() - id:" << id << " order:" << order << endl;
ofxOscMessage m;
m.setAddress("/tuio/2Dcur");
m.addStringArg("alive");
blobList.erase(id);
if (blobList.size() > 0)
{
if(media == false){
for (std::map<int,blob>::iterator it=blobList.begin(); it!=blobList.end(); ++it){
m.addIntArg(it -> first);
}
}
else {
m.addIntArg(0);
}
}
sender.sendMessage(m);
}我的Unity应用程序收不到我的消息/blobs,所以我认为它们的格式不好。有人能告诉我可能出了什么问题吗?
发布于 2015-02-24 22:09:10
首先要提到的是
m.setAddress("/tuio2/2Dcur");
这应该是
m.setAddress("/tuio/2Dcur");TUIO标准(1.1和1.0)对2Dcur的定义如下:
/tuio/2Dcur set s x y X Y m在您的代码中,您设置了s、x和y,然后添加四个0.0 (addFloatArg(0)),因此您实际上得到了如下消息:
/tuio/2Dcur set s x y 0.0 0.0 0.0 0.0这是一个浮点数太多。在OSC中,您通常订阅带有完整签名的消息。这就是为什么你的Unity应用程序中没有消息的原因。
https://stackoverflow.com/questions/22567264
复制相似问题