Hello, I am currently trying to draw paths with XY data from MaxMSP via UDP. I am receiving the UDP messages and I'm able to Print them in the Visual studio console. When I try to use them as XY data it will not draw my path, But when I use the Mouse data it does? Any Idea where my code is lacking sense?
Header File:
pragma once
include "ofMain.h"
include "ofxNetwork.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofxUDPManager udpConnection;
vector<ofPolyline> polylines;
};
CPP FILE:
include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
//we run at 60 fps!
ofSetVerticalSync(true);
ofSetFrameRate(60);
//create the socket and bind to port 11999
udpConnection.Create();
udpConnection.Bind(7400);
udpConnection.SetNonBlocking(true);
ofSetBackgroundAuto(false);
ofBackground(0);
}
//--------------------------------------------------------------
void ofApp::update(){
char udpMessage[100000];
udpConnection.Receive(udpMessage,100000);
string message=udpMessage;
if(message!=""){
float x,y;
ofPolyline polyline;
polylines.push_back(polyline);
vector<string> strPoints = ofSplitString(message,"[/p]");
for(unsigned int i=0;i<strPoints.size();i++){
vector<string> point = ofSplitString(strPoints[i],"|");
if( point.size() == 2 ){
x=atof(point[0].c_str());
y=atof(point[1].c_str());
polylines[polylines.size() - 1].addVertex(ofPoint(x, y));
cout << "X: " << x << " Y: " << y << endl;
}
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
for (int i = 0; i < polylines.size(); i++)
{
polylines[i].draw();
}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}