2

I'm trying to make an app that does some blob tracking and sends all the data for Unity3D using TUIO cursor messages, just like CCV does. This is what i have regarding the messages ("media" is a button to switch between sending all blob's position/id's or sending the average):

  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);
}

My Unity app dont receive my messages/blobs, so i think they are badly formatted. Can someone tell me what may be wrong?

Rita Maia
  • 89
  • 1
  • 2
  • 11

1 Answers1

0

The first thing to mention is

m.setAddress("/tuio2/2Dcur");

which should be

m.setAddress("/tuio/2Dcur");

The TUIO Standard (1.1 and 1.0) defines 2Dcur as follows:

/tuio/2Dcur set s x y X Y m

In your code you are setting s,x and y and then you add four times 0.0 (addFloatArg(0)) so you get in fact a message like this:

/tuio/2Dcur set s x y 0.0 0.0 0.0 0.0

which is one float too much. In OSC you usually subscribe to a message with full signature. That's why you get no message in your Unity application.

razong
  • 1,269
  • 11
  • 22