Loads of stuff :) Check description
- Auto camera swap system in place with rotation - Legend added - list and numbers next to graphs - Grid added - Loads added to GUI
This commit is contained in:
@@ -6,7 +6,15 @@ void DataManager::setup()
|
||||
{
|
||||
app = (testApp*)ofGetAppPtr();
|
||||
|
||||
newData.resize(30);
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
DataObject dataObject;
|
||||
dataObject.value = -999;
|
||||
dataObject.min = -999;
|
||||
dataObject.max = -999;
|
||||
dataObject.info = "";
|
||||
newData.push_back(dataObject);
|
||||
}
|
||||
|
||||
setupSpacebrew();
|
||||
|
||||
@@ -41,7 +49,7 @@ void DataManager::update()
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
DataObject dataObject;
|
||||
dataObject.info = "Some text to describe the data\nSome more text\nOne more line";
|
||||
dataObject.info = "";
|
||||
dataObject.value = ofNoise(newData.size() * perlinXScale, (ofGetElapsedTimef() + (i * 756)) * perlinYScale);
|
||||
dataObject.min = 0;
|
||||
dataObject.max = 1;
|
||||
@@ -59,6 +67,24 @@ void DataManager::update()
|
||||
{
|
||||
nextDataSendTime += sendDataSpeed;
|
||||
app->scene.addNewData(newData);
|
||||
|
||||
|
||||
ofstream logFile;
|
||||
logFile.open(ofToDataPath("subscriber_log.txt").c_str());
|
||||
string str;
|
||||
|
||||
for (int i = 0; i < newData.size(); i++)
|
||||
{
|
||||
DataObject data = newData[i];
|
||||
str += ofToString(i) + " = " + data.info + "\n";
|
||||
|
||||
}
|
||||
unsigned char buf = ofToChar(str);
|
||||
// write data to txt file
|
||||
logFile << str[0] << str <<"\n";
|
||||
|
||||
logFile.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +112,7 @@ void DataManager::onMessage( Spacebrew::Message & m )
|
||||
{
|
||||
if (data[i].substr(0, 5) == "info:")
|
||||
{
|
||||
//printf("- - info = %s\n", data[i].substr(5, -1).c_str());
|
||||
//printf("- info = %s\n", data[i].substr(5, -1).c_str());
|
||||
dataObject.info = data[i].substr(5, -1).c_str();
|
||||
}
|
||||
if (data[i].substr(0, 6) == "value:")
|
||||
@@ -111,9 +137,10 @@ void DataManager::onMessage( Spacebrew::Message & m )
|
||||
{
|
||||
if (m.name == "utility_" + ofToString(i))
|
||||
{
|
||||
printf("adding %s to dataObject %i\n", m.name.c_str(), i);
|
||||
//isPublisher0DataReceived = true;
|
||||
newData[i] = dataObject;
|
||||
//printf("- - - adding %s to dataObject %i, info:%s, min:%f \n", m.name.c_str(), i, newData[i].info.c_str(), newData[i].min);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ void GUI::setup()
|
||||
addKeyboardShortcutsGUI();
|
||||
addGraphGlobalGUI();
|
||||
addGraphDesignGUI();
|
||||
addGraphTextGUI();
|
||||
addLegendTextGUI();
|
||||
addGraphSimulationGUI();
|
||||
addCameraGUI();
|
||||
addVariousGUI();
|
||||
|
||||
setGUIColour();
|
||||
@@ -45,6 +48,8 @@ void GUI::addKeyboardShortcutsGUI()
|
||||
gui->addLabel("'p' - TOGGLE PAUSE ANIMATION", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("'f' - TOGGLE FULLSCREEN", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("'c' - CLEAR ALL GRAPH DATA", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("'t' - REDRAW TEXT FBOS", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("'o' - OUTPUT GRAPH DATA TO TXT", OFX_UI_FONT_SMALL);
|
||||
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
@@ -55,17 +60,6 @@ void GUI::addGraphGlobalGUI()
|
||||
{
|
||||
string title = "GRAPH GLOBAL";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
vector<string> graphNames;
|
||||
graphNames.push_back("Bar graph");
|
||||
graphNames.push_back("Solid Body graph");
|
||||
graphNames.push_back("Separate Body graph");
|
||||
|
||||
gui->addRadio("Graph Selection", graphNames, OFX_UI_ORIENTATION_VERTICAL, dim*2, dim*2);
|
||||
|
||||
gui->addSpacer(length, 1);
|
||||
gui->addRangeSlider("Graph X begin/end (percent)", 0, 1, &Graph::minGraphPercent, &Graph::maxGraphPercent, length, dim);
|
||||
|
||||
// gui->addLabel("GRAPH TEXT");
|
||||
//gui->addSpacer(length, 1);
|
||||
//gui->addSlider("Size", 5, 50, &app->scene.graphTextSize, length, dim);
|
||||
@@ -84,14 +78,25 @@ void GUI::addGraphDesignGUI()
|
||||
string title = "GRAPH DESIGN";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addToggle("Toggle Draw Body", &Graph::isDrawBody, toggleDim, toggleDim);
|
||||
gui->addToggle("Toggle Draw Lines", &Graph::isDrawLines, toggleDim, toggleDim);
|
||||
gui->addToggle("Toggle Clamp Y Values", &Graph::isClampYValues, toggleDim, toggleDim);
|
||||
gui->addSlider("Graph Item X Gap", 0.1, 2, &Graph::graphItemXGap, length, dim);
|
||||
gui->addSlider("Line width", 1, 20, &Graph::lineWidth, length, dim);
|
||||
gui->addSlider("Graph z Range", 0, 200, &Graph::zRange, length, dim);
|
||||
gui->addSlider("Graph Width max", 1, 300, &Graph::maxGraphWidth, length, dim);
|
||||
gui->addSlider("Graph Height Max", 0, 100, &Graph::graphHeightMax, length, dim);
|
||||
gui->addSlider("Graph bottom end (percent)", 0, 20, &Graph::graphEndPercent, length, dim);
|
||||
gui->addSlider("Data send speed (seconds)", 0.1, 20, &app->dataManager.sendDataSpeed, length, dim);
|
||||
gui->addSlider("Line Thickness", 1, 20, &Graph::lineThickness, length, dim);
|
||||
|
||||
gui->addLabel("GRID");
|
||||
gui->addSlider("Scale", 1, 200, &app->scene.gridScale, length, dim);
|
||||
gui->addSlider("Ticks", 1, 50, &app->scene.gridTicks, length, dim);
|
||||
gui->addSlider("Grid Red", 0, 255, &app->scene.gridCol[0], length, dim);
|
||||
gui->addSlider("Grid Green", 0, 255, &app->scene.gridCol[1], length, dim);
|
||||
gui->addSlider("Grid Blue", 0, 255, &app->scene.gridCol[2], length, dim);
|
||||
gui->addSlider("Grid Alpha", 0, 255, &app->scene.gridCol[3], length, dim);
|
||||
|
||||
|
||||
|
||||
//gui->addSpacer(length, 1);
|
||||
@@ -105,6 +110,43 @@ void GUI::addGraphDesignGUI()
|
||||
}
|
||||
|
||||
|
||||
void GUI::addGraphTextGUI()
|
||||
{
|
||||
string title = "GRAPH TEXT";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
//gui->addToggle("Toggle Draw Lines", &Graph::isDrawLines, toggleDim, toggleDim);
|
||||
gui->addSlider("Line Width", 10, 150, &Graph::lineLength, length, dim);
|
||||
gui->addSlider("Line Spacing", 10, 50, &Graph::lineSpacing, length, dim);
|
||||
gui->addSlider("Text Size", 10, 100, &Graph::textSize, length, dim);
|
||||
gui->addSlider("Text Fbo Width", 10, 200, &Graph::fboW, length, dim);
|
||||
gui->addSlider("Text Fbo Height", 10, 100, &Graph::fboH, length, dim);
|
||||
gui->addSlider("Text Draw Y", 0, 100, &Graph::textY, length, dim);
|
||||
gui->addSlider("Text X", -200, 200, &Graph::textPnt.x, length, dim);
|
||||
gui->addSlider("Text Y", -200, 200, &Graph::textPnt.y, length, dim);
|
||||
gui->addSlider("Text z Offset", -50, 50, &Graph::graphTextZOffset, length, dim);
|
||||
|
||||
gui->addWidgetDown(new ofxUILabelButton(false, "UPDATE TEXT", OFX_UI_FONT_MEDIUM));
|
||||
|
||||
ofAddListener(gui->newGUIEvent, this, &GUI::graphTextGUIEvent);
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addLegendTextGUI()
|
||||
{
|
||||
string title = "TITLE AND LEGEND TEXT";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addSlider("Size", 10, 100, &app->scene.legendTextSize, length, dim);
|
||||
gui->addSlider("Spacing", 0, 10, &app->scene.legendTextSpacing, length, dim);
|
||||
gui->addSlider("Line Length", 20, 1000, &app->scene.legendTextLineLength, length, dim);
|
||||
gui->addSlider("X", 0, 500, &app->scene.legendTextPoint.x, length, dim);
|
||||
gui->addSlider("Y", 0, 500, &app->scene.legendTextPoint.y, length, dim);
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
void GUI::addGraphSimulationGUI()
|
||||
{
|
||||
string title = "SIMULATION";
|
||||
@@ -119,6 +161,26 @@ void GUI::addGraphSimulationGUI()
|
||||
}
|
||||
|
||||
|
||||
void GUI::addCameraGUI()
|
||||
{
|
||||
string title = "CAMERA";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addToggle("Rotation", &app->scene.isCamRotate, toggleDim, toggleDim);
|
||||
gui->addToggle("Auto Camera Swap", &app->scene.isCamAutoSwap, toggleDim, toggleDim);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
gui->addLabel("CAMERA " + ofToString(i));
|
||||
gui->addSlider("Cam" + ofToString(i) + " Distance", 10, 200, &app->scene.cameras[i].distance, length, dim);
|
||||
gui->addSlider("Cam" + ofToString(i) + " Y", 1, 150, &app->scene.cameras[i].positionVec.y, length, dim);
|
||||
gui->addSlider("Cam" + ofToString(i) + " Direction Point Y", 0, 150, &app->scene.cameras[i].lookAtVec.y, length, dim);
|
||||
gui->addSlider("Cam" + ofToString(i) + " Rotation Speed", -2, 2, &app->scene.cameras[i].rotSpeed, length, dim);
|
||||
gui->addSlider("Cam" + ofToString(i) + " Swap Probablity (per frame)", 0.001, 0.1, &app->scene.cameras[i].swapProbability, length, dim);
|
||||
}
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GUI::addVariousGUI()
|
||||
@@ -142,6 +204,13 @@ void GUI::addVariousGUI()
|
||||
|
||||
|
||||
|
||||
void GUI::graphTextGUIEvent(ofxUIEventArgs &e)
|
||||
{
|
||||
string name = e.widget->getName();
|
||||
|
||||
if (name == "UPDATE TEXT")
|
||||
app->scene.graphManager.updateInfoText();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,10 +22,14 @@ public:
|
||||
void addKeyboardShortcutsGUI();
|
||||
void addGraphGlobalGUI();
|
||||
void addGraphDesignGUI();
|
||||
void addGraphTextGUI();
|
||||
void addLegendTextGUI();
|
||||
void addGraphSimulationGUI();
|
||||
void addCameraGUI();
|
||||
void addVariousGUI();
|
||||
|
||||
void variousGUIEvent(ofxUIEventArgs &e);
|
||||
void graphTextGUIEvent(ofxUIEventArgs &e);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
int main( ){
|
||||
|
||||
ofAppGlutWindow window;
|
||||
//window.setGlutDisplayString("rgba double samples>=4 depth");
|
||||
ofSetupOpenGL(&window, 1400, 1024, OF_WINDOW); // <-------- setup the GL context
|
||||
|
||||
// this kicks off the running of my app
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
// TODO
|
||||
// ====
|
||||
// - Add text planes
|
||||
// - Add animated camera
|
||||
// - Colour range - tweet between 3 points
|
||||
// - Add a minimum time for each angle
|
||||
// - optimise - don't calculate graph point values evey frame
|
||||
// - investigate backward graph animation (use alternating colours)
|
||||
// - Colour range - tween between 2-3 points
|
||||
//
|
||||
//--------------------------------------------------------------
|
||||
void testApp::setup()
|
||||
@@ -20,6 +21,7 @@ void testApp::setup()
|
||||
dataManager.setup();
|
||||
scene.setup();
|
||||
gui.setup();
|
||||
scene.graphManager.updateInfoText();
|
||||
|
||||
isPaused = false;
|
||||
}
|
||||
@@ -55,6 +57,10 @@ void testApp::keyPressed(int key)
|
||||
ofToggleFullscreen();
|
||||
else if (key == 'c')
|
||||
scene.clearGraphData();
|
||||
else if (key == 't')
|
||||
scene.graphManager.updateInfoText();
|
||||
else if (key == 'o')
|
||||
scene.graphManager.outputData();
|
||||
|
||||
scene.keyPressed(key);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
#include "Camera.h"
|
||||
|
||||
void Camera::setup(int _camID)
|
||||
{
|
||||
camID = _camID;
|
||||
lookAtNode.setPosition(0, 0, 0);
|
||||
setDistance(100);
|
||||
}
|
||||
|
||||
|
||||
void Camera::update()
|
||||
{
|
||||
positionVec.x = sin(ofGetElapsedTimef() * rotSpeed) * distance;
|
||||
//positionVec.y = 40;
|
||||
positionVec.z = cos(ofGetElapsedTimef() * rotSpeed) * distance;
|
||||
|
||||
lookAtNode.setPosition(lookAtVec);
|
||||
setPosition(positionVec);
|
||||
lookAt(lookAtNode);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// GUI.h
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
|
||||
class Camera : public ofEasyCam
|
||||
{
|
||||
public:
|
||||
void setup(int _camID);
|
||||
void update();
|
||||
|
||||
int camID;
|
||||
|
||||
ofNode lookAtNode;
|
||||
ofVec3f lookAtVec;
|
||||
|
||||
ofVec3f positionVec;
|
||||
|
||||
float distance;
|
||||
float rotSpeed;
|
||||
float swapProbability;
|
||||
};
|
||||
@@ -11,16 +11,51 @@
|
||||
|
||||
void Scene::setup()
|
||||
{
|
||||
text.loadFont("fonts/Roboto-Regular.ttf", 80);
|
||||
|
||||
graphManager.setup();
|
||||
camera.setDistance(100);
|
||||
text.loadFont("fonts/Roboto-Light.ttf", 8);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Camera camera;
|
||||
camera.setup(i);
|
||||
cameras[i] = camera;
|
||||
}
|
||||
activeCamera = &cameras[0];
|
||||
|
||||
isCamRotate = true;
|
||||
isCamAutoSwap = true;
|
||||
|
||||
setViewport();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Scene::update()
|
||||
{
|
||||
graphManager.update(camera.getPosition());
|
||||
if (isCamAutoSwap)
|
||||
{
|
||||
if (activeCamera->camID == 0)
|
||||
{
|
||||
if (ofRandom(1) < activeCamera->swapProbability)
|
||||
switchCamera();
|
||||
}
|
||||
else if (activeCamera->camID == 1)
|
||||
{
|
||||
if (ofRandom(1) < activeCamera->swapProbability)
|
||||
switchCamera();
|
||||
}
|
||||
else if (activeCamera->camID == 2)
|
||||
{
|
||||
if (ofRandom(1) < activeCamera->swapProbability)
|
||||
switchCamera();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (isCamRotate) cameras[i].update();
|
||||
|
||||
graphManager.update(activeCamera->getPosition());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,18 +63,41 @@ void Scene::draw()
|
||||
{
|
||||
ofBackground(0);
|
||||
|
||||
camera.begin(viewport);
|
||||
activeCamera->begin(viewport);
|
||||
|
||||
ofPushMatrix();
|
||||
ofRotateZ(90);
|
||||
ofSetColor(255, 100);
|
||||
ofDrawGridPlane(60, 10, false);
|
||||
ofSetColor(gridCol[0], gridCol[1], gridCol[2], gridCol[3]);
|
||||
ofDrawGridPlane((int)gridScale, (int)gridTicks, false);
|
||||
ofPopMatrix();
|
||||
|
||||
|
||||
graphManager.draw();
|
||||
|
||||
camera.end();
|
||||
activeCamera->end();
|
||||
|
||||
ofPushStyle();
|
||||
ofSetColor(255, 255);
|
||||
text.setLineSpacing(legendTextSpacing);
|
||||
text.setLineLength(legendTextLineLength);
|
||||
text.setSize(legendTextSize);
|
||||
text.setAlignment(FTGL_ALIGN_LEFT);
|
||||
string str;
|
||||
for (int i = 0; i < graphManager.graphs.size(); i++)
|
||||
{
|
||||
string newStr = ofToString(i) + " - " + graphManager.graphs[i]->info;
|
||||
str += newStr + "\n";
|
||||
//if (ofGetFrameNum() % 30 == 0)
|
||||
// printf("- str:%s\n- - - - - *** - - - - -\n", newStr.c_str());
|
||||
}
|
||||
//if (ofGetFrameNum() % 30 == 0)
|
||||
//{
|
||||
// printf("\n\n\n\n");
|
||||
// printf("str(all):%s\n- - - - - *** - - - - -\n", str.c_str());
|
||||
// printf("\n\n\n\n");
|
||||
//}
|
||||
|
||||
text.drawString(str, legendTextPoint.x, legendTextPoint.y);
|
||||
ofPopStyle();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,21 +112,38 @@ void Scene::setViewport()
|
||||
void Scene::addNewData(vector<DataObject> newData)
|
||||
{
|
||||
graphManager.addNewData(newData);
|
||||
|
||||
//tlStr = newData[0].info + "\n" + ofToString(newData[0].value);
|
||||
//trStr = newData[1].info + "\n" + ofToString(newData[1].value);
|
||||
|
||||
//millisAtLastData = ofGetElapsedTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
void Scene::keyPressed(int key)
|
||||
{
|
||||
|
||||
if (key == '1')
|
||||
activeCamera = &cameras[0];
|
||||
if (key == '2')
|
||||
activeCamera = &cameras[1];
|
||||
if (key == '3')
|
||||
activeCamera = &cameras[2];
|
||||
}
|
||||
|
||||
|
||||
void Scene::clearGraphData()
|
||||
{
|
||||
graphManager.clearGraphData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Scene::switchCamera()
|
||||
{
|
||||
int newCamID;
|
||||
if (activeCamera->camID == 0)
|
||||
newCamID = (ofRandom(1) < 0.5) ? 1 : 2;
|
||||
if (activeCamera->camID == 1)
|
||||
newCamID = (ofRandom(1) < 0.5) ? 0 : 2;
|
||||
if (activeCamera->camID == 2)
|
||||
newCamID = (ofRandom(2) < 0.5) ? 0 : 1;
|
||||
|
||||
printf("************ changing cameras to %i ************** \n", newCamID);
|
||||
|
||||
activeCamera = &cameras[newCamID];
|
||||
}
|
||||
@@ -11,8 +11,9 @@
|
||||
#include "ofMain.h"
|
||||
#include "Graph.h"
|
||||
#include "DataManager.h"
|
||||
#include "ofxFTGL.h"
|
||||
#include "GraphManager.h"
|
||||
#include "ofxFTGL.h"
|
||||
#include "Camera.h"
|
||||
|
||||
class testApp;
|
||||
|
||||
@@ -27,13 +28,27 @@ public:
|
||||
void addNewData(vector<DataObject> newData);
|
||||
void clearGraphData();
|
||||
void keyPressed(int key);
|
||||
|
||||
void switchCamera();
|
||||
|
||||
GraphManager graphManager;
|
||||
|
||||
Camera cameras[3];
|
||||
Camera *activeCamera;
|
||||
ofNode lookAtNode;
|
||||
ofVec3f lookAtVec;
|
||||
|
||||
ofEasyCam camera;
|
||||
ofRectangle viewport;
|
||||
|
||||
ofxFTGLSimpleLayout text;
|
||||
float legendTextSize;
|
||||
float legendTextSpacing;
|
||||
float legendTextLineLength;
|
||||
ofPoint legendTextPoint;
|
||||
|
||||
float gridScale;
|
||||
float gridTicks;
|
||||
float gridCol[4];
|
||||
|
||||
bool isCamRotate;
|
||||
bool isCamAutoSwap;
|
||||
};
|
||||
@@ -6,27 +6,47 @@
|
||||
#include "Graph.h"
|
||||
#include "testApp.h"
|
||||
|
||||
float Graph::minGraphPercent;
|
||||
float Graph::maxGraphPercent;
|
||||
float Graph::maxGraphWidth;
|
||||
bool Graph::isDrawBody;
|
||||
bool Graph::isDrawLines;
|
||||
bool Graph::isClampYValues;
|
||||
float Graph::graphItemXGap;
|
||||
float Graph::lineWidth;
|
||||
float Graph::lineThickness;
|
||||
float Graph::graphHeightMax;
|
||||
float Graph::graphEndPercent;
|
||||
float Graph::zRange;
|
||||
float Graph::graphTextZOffset;
|
||||
|
||||
float Graph::lineLength;
|
||||
float Graph::lineSpacing;
|
||||
float Graph::textSize;
|
||||
float Graph::fboW;
|
||||
float Graph::fboH;
|
||||
float Graph::textY;
|
||||
ofPoint Graph::textPnt;
|
||||
|
||||
Graph::Graph(int _graphID)
|
||||
{
|
||||
app = (testApp*)ofGetAppPtr();
|
||||
graphID = _graphID;
|
||||
|
||||
isInfoTextSet = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Graph::update(ofVec3f activeCamPos)
|
||||
{
|
||||
if (publisher0Data.size() > 0 && publisher0Data.back().info != "" && !isInfoTextSet)
|
||||
{
|
||||
isInfoTextSet = true;
|
||||
drawInfoToFbo();
|
||||
}
|
||||
|
||||
|
||||
ofVec3f camPos = activeCamPos;
|
||||
centre = ofVec3f(0.1, 0.1, ofMap(graphID, 0, 29, -50, 50));
|
||||
centre = ofVec3f(0.1, 0.1, ofMap(graphID, 0, 29, -zRange, zRange));
|
||||
distToCam = sqrt(double(ABS(camPos.x - centre.x) * ABS(camPos.x - centre.x) * ABS(camPos.x - centre.x) +
|
||||
ABS(camPos.y - centre.y) * ABS(camPos.y - centre.y) * ABS(camPos.y - centre.y) +
|
||||
ABS(camPos.z - centre.z) * ABS(camPos.z - centre.z) * ABS(camPos.z - centre.z)));
|
||||
@@ -42,7 +62,15 @@ void Graph::draw()
|
||||
float timePerScreenfull = (float)maxData * app->dataManager.sendDataSpeed;
|
||||
ofDrawBitmapString("Time to fill screen:" + ofToString(timePerScreenfull), 500, 150);
|
||||
}
|
||||
|
||||
drawGraphBody();
|
||||
drawGraphText();
|
||||
}
|
||||
|
||||
|
||||
void Graph::drawGraphBody()
|
||||
{
|
||||
if (!isDrawBody) return;
|
||||
|
||||
if (publisher0Data.size() > 1)
|
||||
{
|
||||
ofMesh body0 = getMesh(publisher0Data, col0);
|
||||
@@ -63,18 +91,16 @@ void Graph::draw()
|
||||
{
|
||||
if (i < publisher0Data.size() - 1)
|
||||
{
|
||||
ofSetLineWidth(lineWidth);
|
||||
poly0.addVertex(ofVec3f(
|
||||
i * graphItemXGap - (maxGraphWidth * 0.5),
|
||||
ofSetLineWidth(lineThickness);
|
||||
ofVec3f vec = ofVec3f(i * graphItemXGap - (maxGraphWidth * 0.5),
|
||||
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax),
|
||||
centre.z));
|
||||
centre.z);
|
||||
|
||||
if (isClampYValues) vec.y = ofClamp(vec.y, outputMin, outputMax);
|
||||
|
||||
poly0.addVertex(vec);
|
||||
}
|
||||
}
|
||||
|
||||
//ofVec3f(
|
||||
// i * graphItemXGap - (maxGraphWidth * 0.5),
|
||||
// ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax),
|
||||
// 0)
|
||||
|
||||
ofVec2f centroid0 = poly0.getCentroid2D();
|
||||
|
||||
@@ -98,6 +124,20 @@ void Graph::draw()
|
||||
}
|
||||
|
||||
|
||||
void Graph::drawGraphText()
|
||||
{
|
||||
ofPushStyle();
|
||||
ofSetColor(255, 255);
|
||||
ofPushMatrix();
|
||||
ofTranslate(textPnt.x, textPnt.y, centre.z + graphTextZOffset);
|
||||
ofRotateX(-90);
|
||||
ofScale(0.1, 0.1);
|
||||
infoTextFbo.draw(0, 0);
|
||||
ofPopMatrix();
|
||||
ofPopStyle();
|
||||
}
|
||||
|
||||
|
||||
ofMesh Graph::getMesh(vector<DataObject> publisherData, float* col)
|
||||
{
|
||||
ofMesh bodyMesh;
|
||||
@@ -109,10 +149,14 @@ ofMesh Graph::getMesh(vector<DataObject> publisherData, float* col)
|
||||
bodyMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
||||
for (int i = 0; i < publisherData.size() - 1; i++)
|
||||
{
|
||||
bodyMesh.addVertex(ofVec3f(
|
||||
ofVec3f vecH = ofVec3f(
|
||||
i * graphItemXGap - (maxGraphWidth * 0.5),
|
||||
ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax),
|
||||
centre.z));
|
||||
centre.z);
|
||||
|
||||
if (isClampYValues) vecH.y = ofClamp(vecH.y, outputMin, outputMax);
|
||||
bodyMesh.addVertex(vecH);
|
||||
|
||||
bodyMesh.addVertex(ofVec3f(
|
||||
i * graphItemXGap - (maxGraphWidth * 0.5),
|
||||
0,
|
||||
@@ -130,15 +174,52 @@ ofMesh Graph::getMesh(vector<DataObject> publisherData, float* col)
|
||||
}
|
||||
|
||||
|
||||
void Graph::createInfoTextFbo()
|
||||
void Graph::setFboSettings()
|
||||
{
|
||||
settings.width = fboW;
|
||||
settings.height = fboH;
|
||||
settings.internalformat = GL_RGBA;
|
||||
infoTextFbo.allocate(settings);
|
||||
}
|
||||
|
||||
|
||||
void Graph::drawInfoToFbo()
|
||||
{
|
||||
string infoText = "";
|
||||
|
||||
if (publisher0Data.size() > 0)
|
||||
{
|
||||
infoText = info;
|
||||
}
|
||||
|
||||
//printf("---- infoText = %s \n", infoText.c_str());
|
||||
|
||||
text->setLineLength(lineLength);
|
||||
text->setLineSpacing(lineSpacing);
|
||||
text->setSize(textSize);
|
||||
text->setAlignment(FTGL_ALIGN_LEFT);
|
||||
|
||||
ofPushStyle();
|
||||
|
||||
infoTextFbo.begin();
|
||||
ofClear(0, 0, 0, 0);
|
||||
ofSetColor(0, 0);
|
||||
ofRect(0, 0, settings.width, settings.height);
|
||||
ofSetColor(255, 255);
|
||||
//ofScale(0.5, 0.5);
|
||||
|
||||
text->drawString(ofToString(graphID), 0, textY);
|
||||
infoTextFbo.end();
|
||||
|
||||
ofPopStyle();
|
||||
}
|
||||
|
||||
|
||||
void Graph::addNewData(DataObject newData)
|
||||
{
|
||||
info = explode("\n", newData.info)[0];
|
||||
publisher0Data.push_back(newData);
|
||||
while (publisher0Data.size() > maxData && publisher0Data.size() > maxData)
|
||||
while (publisher0Data.size() > maxData)
|
||||
publisher0Data.erase(publisher0Data.begin());
|
||||
}
|
||||
|
||||
@@ -146,4 +227,37 @@ void Graph::addNewData(DataObject newData)
|
||||
void Graph::clear()
|
||||
{
|
||||
publisher0Data.clear();
|
||||
setFboSettings();
|
||||
drawInfoToFbo();
|
||||
}
|
||||
|
||||
vector<string> Graph::explode(const string &delimiter, const string &str)
|
||||
{
|
||||
vector<string> arr;
|
||||
|
||||
int strleng = str.length();
|
||||
int delleng = delimiter.length();
|
||||
if (delleng==0)
|
||||
return arr;//no change
|
||||
|
||||
int i=0;
|
||||
int k=0;
|
||||
while( i<strleng )
|
||||
{
|
||||
int j=0;
|
||||
while (i+j<strleng && j<delleng && str[i+j]==delimiter[j])
|
||||
j++;
|
||||
if (j==delleng)//found delimiter
|
||||
{
|
||||
arr.push_back( str.substr(k, i-k) );
|
||||
i+=delleng;
|
||||
k=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
arr.push_back( str.substr(k, i-k) );
|
||||
return arr;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "DataManager.h"
|
||||
#include "ofxFTGL.h"
|
||||
|
||||
class testApp;
|
||||
|
||||
@@ -12,10 +13,14 @@ public:
|
||||
Graph(int _graphID);
|
||||
void update(ofVec3f ativeCamPos);
|
||||
void draw();
|
||||
void drawGraphBody();
|
||||
void drawGraphText();
|
||||
void addNewData(DataObject newData);
|
||||
ofMesh getMesh(vector<DataObject> publisherData, float* col);
|
||||
void createInfoTextFbo();
|
||||
void setFboSettings();
|
||||
void drawInfoToFbo();
|
||||
void clear();
|
||||
vector<string> explode(const string &delimiter, const string &str);
|
||||
|
||||
testApp *app;
|
||||
int graphID;
|
||||
@@ -24,24 +29,28 @@ public:
|
||||
int maxData; // calculated from graphWidth and graphItemXGap
|
||||
|
||||
ofFbo infoTextFbo;
|
||||
ofFbo::Settings settings;
|
||||
ofxFTGLSimpleLayout* text;
|
||||
bool isInfoTextSet;
|
||||
|
||||
static float minGraphPercent;
|
||||
static float maxGraphPercent;
|
||||
static float maxGraphWidth;
|
||||
static bool isDrawBody;
|
||||
static bool isDrawLines;
|
||||
static bool isClampYValues;
|
||||
static float graphItemXGap;
|
||||
static float lineWidth;
|
||||
static float lineThickness;
|
||||
static float graphHeightMax;
|
||||
static float graphEndPercent;
|
||||
static float zRange;
|
||||
static float graphTextZOffset;
|
||||
|
||||
//float minGraphPercent;
|
||||
//float maxGraphPercent;
|
||||
//float maxGraphWidth;
|
||||
//bool isDrawLines;
|
||||
//float graphItemXGap;
|
||||
//float lineWidth;
|
||||
//float graphHeightMax;
|
||||
//float graphEndPercent;
|
||||
static float lineLength;
|
||||
static float lineSpacing;
|
||||
static float textSize;
|
||||
static float fboW;
|
||||
static float fboH;
|
||||
static float textY;
|
||||
static ofPoint textPnt;
|
||||
|
||||
ofPoint currentPub0Point;
|
||||
|
||||
@@ -50,4 +59,7 @@ public:
|
||||
|
||||
float distToCam;
|
||||
ofVec3f centre;
|
||||
|
||||
string info;
|
||||
|
||||
};
|
||||
@@ -3,15 +3,19 @@
|
||||
|
||||
void GraphManager::setup()
|
||||
{
|
||||
text.loadFont("fonts/Roboto-Regular.ttf", 80);
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Graph *graph = new Graph(i);
|
||||
//graph.setup(i);
|
||||
graph->text = &text;
|
||||
graphs.push_back(graph);
|
||||
reorderedGraphs.push_back(graph);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GraphManager::update(ofVec3f ativeCamPos)
|
||||
{
|
||||
for (int i = 0; i < graphs.size(); i++)
|
||||
@@ -20,20 +24,22 @@ void GraphManager::update(ofVec3f ativeCamPos)
|
||||
graph->update(ativeCamPos);
|
||||
}
|
||||
|
||||
std::sort(graphs.begin(), graphs.end(), compareGraphByDistToCam());
|
||||
std::sort(reorderedGraphs.begin(), reorderedGraphs.end(), compareGraphByDistToCam());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GraphManager::draw()
|
||||
{
|
||||
for (int i = 0; i < graphs.size(); i++)
|
||||
{
|
||||
Graph *graph = graphs[i];
|
||||
Graph *graph = reorderedGraphs[i];
|
||||
graph->draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GraphManager::addNewData(vector<DataObject> newData)
|
||||
{
|
||||
for (int i = 0; i < graphs.size(); i++)
|
||||
@@ -52,4 +58,57 @@ void GraphManager::clearGraphData()
|
||||
Graph *graph = graphs[i];
|
||||
graph->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GraphManager::updateInfoText()
|
||||
{
|
||||
for (int i = 0; i < graphs.size(); i++)
|
||||
{
|
||||
Graph *graph = graphs[i];
|
||||
graph->setFboSettings();
|
||||
graph->drawInfoToFbo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GraphManager::outputData()
|
||||
{
|
||||
ofstream logFile;
|
||||
logFile.open(ofToDataPath("graph_log.txt").c_str());
|
||||
//ofstream logFile( ofToDataPath("log.txt").c_str());
|
||||
|
||||
string str;
|
||||
|
||||
for (int i = 0; i < graphs.size(); i++)
|
||||
{
|
||||
Graph *graph = graphs[i];
|
||||
str += graph->publisher0Data[graph->publisher0Data.size() - 1].info + "\n";
|
||||
|
||||
// print values
|
||||
str += "\nVALUES:\n\n";
|
||||
for (int j = 0; j < graph->publisher0Data.size(); j++)
|
||||
str += ofToString(j) + " = " + ofToString(graph->publisher0Data[j].value) + "\n";
|
||||
|
||||
str += "\nMIN\n\n";
|
||||
for (int j = 0; j < graph->publisher0Data.size(); j++)
|
||||
str += ofToString(j) + " = " + ofToString(graph->publisher0Data[j].min) + "\n";
|
||||
|
||||
str += "\nMAX\n\n";
|
||||
for (int j = 0; j < graph->publisher0Data.size(); j++)
|
||||
str += ofToString(j) + " = " + ofToString(graph->publisher0Data[j].max) + "\n";
|
||||
|
||||
|
||||
str += "\n\n\n\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned char buf = ofToChar(str);
|
||||
// write data to txt file
|
||||
logFile << str[0] << str <<"\n";
|
||||
|
||||
logFile.close();
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ofMain.h"
|
||||
#include "DataManager.h"
|
||||
#include "Graph.h"
|
||||
#include "ofxFTGL.h"
|
||||
|
||||
struct compareGraphByDistToCam
|
||||
{
|
||||
@@ -16,6 +17,10 @@ public:
|
||||
void draw();
|
||||
void addNewData(vector<DataObject> newData);
|
||||
void clearGraphData();
|
||||
|
||||
void updateInfoText();
|
||||
void outputData();
|
||||
|
||||
vector<Graph*> graphs;
|
||||
vector<Graph*> reorderedGraphs;
|
||||
ofxFTGLSimpleLayout text;
|
||||
};
|
||||
Reference in New Issue
Block a user