Implement colors for interaction effects.

This commit is contained in:
2018-02-18 18:52:22 +01:00
parent ed5a71fbf1
commit a7ce0bd265
2 changed files with 13 additions and 1 deletions

View File

@@ -14,11 +14,20 @@ ActivityAnimation::ActivityAnimation(const vector<pair<DType, pair<size_t, size_
{
startingPos.reserve(bufferLength);
delta.reserve(bufferLength);
colorBuf.reserve(interactions.size());
for (auto &entry : interactions) {
auto *aPos = &aPositions[3 * entry.second.first];
auto *bPos = &bPositions[3 * entry.second.second];
array<float, 3> color;
if (entry.first > 0) {
color = {0, 1, 0};
} else {
color = {1, 0, 0};
}
colorBuf.push_back(color);
for (auto i : Range(3)) {
startingPos.emplace_back(aPos[i]);
delta.emplace_back(bPos[i] - aPos[i] + (i % 3 ? 0 : xDist));
@@ -34,9 +43,11 @@ void ActivityAnimation::draw(float timeScale)
vertexBuffer[i] = startingPos[i] + timeScale * delta[i];
}
glColor3f(1, 1, 1);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colorBuf.data());
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}

View File

@@ -18,6 +18,7 @@ namespace fmri
private:
std::size_t bufferLength;
std::vector<std::array<float, 3>> colorBuf;
std::vector<float> startingPos;
std::vector<float> delta;
};