麻烦各位大神啦,小弟实在是焦头烂额了。先说说目的:读取鼠标所在位置(屏幕坐标),将该坐标用TUIO协议发出去,但是Vinjn大神的TuioGateway接收后崩溃了。BSQSimulator接收后鼠标停在屏幕左上角不动,拉也拉不回来,小弟先在此谢谢啦。
#include "ofxOscSender.h"
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <string>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "Winmm.lib")
#define ADDRESS "127.0.0.1"
#define PORT 3333
using namespace osc;
class OSCApp
{
public:
OSCApp()
{
frameSeq = 0;
}
~OSCApp()
{
}
void connectSocket(std::string ip_address, int port)
{
tuioSender.setup(ip_address, port);
printf("Socket Initialized : %s Port : %i\n\n", ip_address.c_str(), port);
frameSeq = 0;
}
void frame()
{
ofxOscBundle bundle;
ofxOscMessage alive;
{
alive.setAddress("/tuio/2Dcur");
alive.addStringArg("alive");
}
ofxOscMessage fseq;
{
fseq.setAddress( "/tuio/2Dcur" );
fseq.addStringArg( "fseq" );
fseq.addIntArg(frameSeq);
}
POINT pt;
GetCursorPos(&pt); //获得当前鼠标坐标
int i;
i = frameSeq/50;
ofxOscMessage m;
m.setAddress( "/tuio/2Dcur" );
m.addStringArg("set");
m.addIntArg(i); // id
m.addFloatArg(pt.x/1366.0f); // x
m.addFloatArg(pt.y/768.0f); // y
// TOTO
m.addFloatArg(0); // dX
m.addFloatArg(0); // dY
m.addFloatArg(0.0f); // maccel
bundle.addMessage(m);
alive.addIntArg(i); // add blob to list of ALL active IDs
bundle.addMessage(alive);
bundle.addMessage(fseq);
tuioSender.sendBundle(bundle);
Sleep(20);
frameSeq ++;
if(frameSeq>65530)
frameSeq = 0;
}
private:
ofxOscSender tuioSender;
int frameSeq;
};
int main()
{
OSCApp app;
std::string ip_address = ADDRESS;
int port = PORT;
app.connectSocket(ip_address, port);
cvNamedWindow("touch",CV_WINDOW_AUTOSIZE );
int key;
while(1)
{
key=cvWaitKey(1);
if(key==27) break;
app.frame();
Sleep(10);
}
cvDestroyWindow("touch");
return 0;
}