Skip to content

Commit

Permalink
Added map position message to overhead client
Browse files Browse the repository at this point in the history
  • Loading branch information
samluescher committed Sep 17, 2012
1 parent 8f7ee9c commit a6cf3f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/testApp.h
Expand Up @@ -16,10 +16,13 @@
#include "MapFeature.h"
#include "ofxJSONElement.h"
#include "ReliefClientBase.h"
#include "ofxOsc.h"

#include "ofPinchGestureRecognizer.h"
#include "ofxUI.h"

#define OVERHEAD_HOST "18.85.58.59"

class testApp : public ReliefClientBase{

public:
Expand Down Expand Up @@ -99,6 +102,6 @@ class testApp : public ReliefClientBase{
ofxUICanvas *calibrationGUI, *layersGUI;
void guiEvent(ofxUIEventArgs &e);


ofxOscSender overheadSender;
};

38 changes: 31 additions & 7 deletions src/testApp.mm
Expand Up @@ -61,7 +61,13 @@ void copyImageWithScaledColors(ofImage &from, ofImage &to, float alphaScale, flo


//--------------------------------------------------------------
void testApp::setup() {
void testApp::setup()
{
#ifdef OVERHEAD_HOST
overheadSender.setup(OVERHEAD_HOST, RELIEF_PORT);
ofLog() << "Setting up overhead sender: " << OVERHEAD_HOST;
#endif

#if (USE_QCAR)
ofLog() << "Initializing QCAR";
[ofxQCAR_Utils getInstance].targetType = TYPE_FRAMEMARKERS;
Expand Down Expand Up @@ -112,9 +118,9 @@ void copyImageWithScaledColors(ofImage &from, ofImage &to, float alphaScale, flo

numLoading = 0;
ofRegisterURLNotification(this);
//loadFeaturesFromURL("http://map.safecast.org/api/mappoints/4ff47bc60aea6a01ec00000f?b=&"+ofToString(terrainSW.x)+"b="+ofToString(terrainSW.y)+"&b="+ofToString(terrainNE.x)+"&b="+ofToString(terrainNE.y)+"&z=8");
loadFeaturesFromURL("http://map.safecast.org/api/mappoints/4ff47bc60aea6a01ec00000f?b=&"+ofToString(terrainSW.x)+"b="+ofToString(terrainSW.y)+"&b="+ofToString(terrainNE.x)+"&b="+ofToString(terrainNE.y)+"&z=8");

loadFeaturesFromFile("json/safecast.8.json");
//loadFeaturesFromFile("json/safecast.8.json");
//loadFeaturesFromFile("json/earthquakes.json");

calibrationMode = drawDebugEnabled = false;
Expand Down Expand Up @@ -524,11 +530,11 @@ void copyImageWithScaledColors(ofImage &from, ofImage &to, float alphaScale, flo

int sendMapWidth = normalizedReliefSize.x * sendMapFrom.width;
int sendMapHeight = normalizedReliefSize.y * sendMapFrom.height;
if (sendMap.width != sendMapWidth || sendMap.height != sendMapHeight) {
//if (sendMap.width != sendMapWidth || sendMap.height != sendMapHeight) {
sendMap.allocate(sendMapWidth, sendMapHeight, OF_IMAGE_COLOR);
terrainCrop.allocate(normalizedReliefSize.x * terrainTex.width, normalizedReliefSize.y * terrainTex.height, OF_IMAGE_COLOR);
featureMapCrop.allocate(normalizedReliefSize.x * featureMap.width, normalizedReliefSize.y * featureMap.height, OF_IMAGE_COLOR_ALPHA);
}
//}

sendMap.cropFrom(sendMapFrom, -sendMap.width / 2 + normalizedMapCenter.x * sendMapFrom.width, -sendMap.height / 2 + normalizedMapCenter.y * sendMapFrom.height, sendMap.width, sendMap.height);
terrainCrop.cropFrom(terrainTex, -terrainCrop.width / 2 + normalizedMapCenter.x * terrainTex.width, -terrainCrop.height / 2 + normalizedMapCenter.y * terrainTex.height, terrainCrop.width, terrainCrop.height);
Expand Down Expand Up @@ -567,13 +573,30 @@ void copyImageWithScaledColors(ofImage &from, ofImage &to, float alphaScale, flo
if (reliefSendMode != RELIEF_SEND_OFF) {
// reliefMessageSend(message);
}

#ifdef OVERHEAD_HOST
ofxOscMessage m;
m.setAddress("/map/position");
m.addFloatArg(mapCenter.x);
m.addFloatArg(mapCenter.y);
m.addFloatArg(terrainUnitToCameraUnit);
overheadSender.sendMessage(m);
#endif
}


void testApp::reliefMessageReceived(ofxOscMessage m) {
ofLog() << "reliefMessageReceived from " << m.getRemoteIp() << ": " << m.getAddress();
void testApp::reliefMessageReceived(ofxOscMessage m)
{
ofxUIToggle *indicator = (ofxUIToggle *)calibrationGUI->getWidget("RECEIVING");
indicator->setValue(!indicator->getValue());

if (m.getAddress() == "/map/position") {
ofLog() << "reliefMessageReceived from " << m.getRemoteIp() << ": " << m.getAddress();
mapCenter.x = m.getArgAsFloat(0);
mapCenter.y = m.getArgAsFloat(1);
ofLog() << "position: " << mapCenter;
updateVisibleMap();
}
}


Expand Down Expand Up @@ -704,6 +727,7 @@ void copyImageWithScaledColors(ofImage &from, ofImage &to, float alphaScale, flo
}
featureMap.reloadTexture();
featureHeightMap.reloadTexture();
updateVisibleMap();
} else {
cout << "Error parsing JSON";
}
Expand Down

0 comments on commit a6cf3f1

Please sign in to comment.