Added animation system to utility
Still not the smoothest as the data arrives at odd times. Might be a little unnecessary as the increase is so small
This commit is contained in:
@@ -16,7 +16,7 @@ void DataManager::setup()
|
||||
newData.push_back(dataObject);
|
||||
}
|
||||
|
||||
subscriberDevName = "";
|
||||
subscriberDevName = ""; // dev2
|
||||
setupSpacebrew();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void DataManager::setupSpacebrew()
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
spacebrew.addSubscribe("utility_" + subscriberDevName + ofToString(i), Spacebrew::TYPE_STRING);
|
||||
spacebrew.addSubscribe("utility" + subscriberDevName + "_" + ofToString(i), Spacebrew::TYPE_STRING);
|
||||
}
|
||||
spacebrew.connect(host, name, description);
|
||||
|
||||
@@ -132,6 +132,7 @@ void DataManager::onMessage( Spacebrew::Message & m )
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
//printf("m.nme:%s, compare:%s \n", m.name.c_str(), ("utility" + subscriberDevName + "_" + ofToString(i)).c_str());
|
||||
if (m.name == "utility" + subscriberDevName + "_" + ofToString(i))
|
||||
{
|
||||
//isPublisher0DataReceived = true;
|
||||
|
||||
@@ -20,6 +20,7 @@ void GUI::setup()
|
||||
addKeyboardShortcutsGUI();
|
||||
addGraphGlobalGUI();
|
||||
addGraphDesignGUI();
|
||||
addGraphColourGUI();
|
||||
addGraphTextGUI();
|
||||
addLegendTextGUI();
|
||||
addGraphSimulationGUI();
|
||||
@@ -80,6 +81,7 @@ void GUI::addGraphDesignGUI()
|
||||
string title = "GRAPH DESIGN";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addToggle("Toggle Graph animation", &Graph::isAnimating, toggleDim, toggleDim);
|
||||
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);
|
||||
@@ -98,7 +100,15 @@ void GUI::addGraphDesignGUI()
|
||||
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);
|
||||
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
void GUI::addGraphColourGUI()
|
||||
{
|
||||
string title = "GRAPH COLOUR";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addLabel("COLOUR");
|
||||
gui->addSlider("Front red", 0, 255, &Graph::colFront[0], length, dim);
|
||||
gui->addSlider("Front green", 0, 255, &Graph::colFront[1], length, dim);
|
||||
@@ -109,11 +119,9 @@ void GUI::addGraphDesignGUI()
|
||||
gui->addSlider("Back blue", 0, 255, &Graph::colBack[2], length, dim);
|
||||
gui->addSlider("Back alpha", 0, 255, &Graph::colBack[3], length, dim);
|
||||
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addGraphTextGUI()
|
||||
{
|
||||
string title = "GRAPH TEXT";
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
void addKeyboardShortcutsGUI();
|
||||
void addGraphGlobalGUI();
|
||||
void addGraphDesignGUI();
|
||||
void addGraphColourGUI();
|
||||
void addGraphTextGUI();
|
||||
void addLegendTextGUI();
|
||||
void addGraphSimulationGUI();
|
||||
|
||||
@@ -26,6 +26,8 @@ float Graph::fboH;
|
||||
float Graph::textY;
|
||||
ofPoint Graph::textPnt;
|
||||
|
||||
bool Graph::isAnimating;
|
||||
|
||||
Graph::Graph(int _graphID)
|
||||
{
|
||||
app = (testApp*)ofGetAppPtr();
|
||||
@@ -33,6 +35,9 @@ Graph::Graph(int _graphID)
|
||||
|
||||
isInfoTextSet = false;
|
||||
graphMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
||||
|
||||
millisSinceLastPoint = 0;
|
||||
isAnimating = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +53,26 @@ void Graph::update(ofVec3f activeCamPos)
|
||||
|
||||
if (hasColorChanged())
|
||||
updateColours();
|
||||
|
||||
if (isAnimating)
|
||||
{
|
||||
if (graphMesh.getVertices().size() >= 4)
|
||||
{
|
||||
|
||||
float normalisedTimeInc = ofMap(ofGetElapsedTimeMillis(), millisSinceLastPoint, millisSinceLastPoint + millisGap, 0, 1);
|
||||
|
||||
if (normalisedTimeInc > 0 && normalisedTimeInc < 1)
|
||||
{
|
||||
ofVec3f lastButOneTopVec = graphMesh.getVertices()[graphMesh.getVertices().size() - 4];
|
||||
ofVec3f lastVecTopVec = graphMesh.getVertices()[graphMesh.getVertices().size() - 2];
|
||||
|
||||
lastVecTopVec = lastButOneTopVec.getInterpolated(lastVecTarget, normalisedTimeInc);
|
||||
graphMesh.setVertex(graphMesh.getVertices().size() - 2, lastVecTopVec);
|
||||
graphMesh.setVertex(graphMesh.getVertices().size() - 1, ofVec3f(lastVecTopVec.x, 0, lastVecTopVec.z));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ofVec3f camPos = activeCamPos;
|
||||
centre = ofVec3f(0.1, 0.1, ofMap(graphID, 0, 29, -zRange, zRange));
|
||||
@@ -141,6 +166,9 @@ void Graph::drawInfoToFbo()
|
||||
|
||||
void Graph::addNewData(DataObject newData)
|
||||
{
|
||||
millisGap = ofGetElapsedTimeMillis() - millisSinceLastPoint;
|
||||
millisSinceLastPoint = ofGetElapsedTimeMillis();
|
||||
|
||||
info = explode("\n", newData.info)[0];
|
||||
|
||||
float xOffset = 0;
|
||||
@@ -171,7 +199,21 @@ void Graph::addNewData(DataObject newData)
|
||||
|
||||
ofVec3f vertexTop = ofVec3f(xTop, yTop, centre.z);
|
||||
ofVec3f vertexBottom = ofVec3f(xTop, 0, centre.z);
|
||||
|
||||
|
||||
|
||||
if (isAnimating)
|
||||
{
|
||||
ofVec3f temp = vertexTop;
|
||||
|
||||
if (graphMesh.getVertices().size() > 0)
|
||||
{
|
||||
graphMesh.setVertex(graphMesh.getVertices().size() - 2, lastVecTarget);
|
||||
graphMesh.setVertex(graphMesh.getVertices().size() - 1, ofVec3f(lastVecTarget.x, 0, lastVecTarget.z));
|
||||
|
||||
vertexTop = graphMesh.getVertices().back() - 1;
|
||||
}
|
||||
lastVecTarget = temp;
|
||||
}
|
||||
graphMesh.addVertex(vertexTop);
|
||||
graphMesh.addVertex(vertexBottom);
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
static float fboH;
|
||||
static float textY;
|
||||
static ofPoint textPnt;
|
||||
static bool isAnimating;
|
||||
|
||||
float col0[4];
|
||||
|
||||
@@ -68,4 +69,9 @@ public:
|
||||
float currentValue;
|
||||
float currentMin;
|
||||
float currentMax;
|
||||
|
||||
|
||||
float millisSinceLastPoint;
|
||||
float millisGap;
|
||||
ofVec3f lastVecTarget;
|
||||
};
|
||||
Reference in New Issue
Block a user