@AceSlowman wrote:
I was trying to come to an efficient method for animating movement along a line segment. In update, there is always a "lead" vertex, and using another for loop, a length of vertices behind that lead are colored with a decreasing alpha value, making it appear to have a trail behind it.
int leadVertex = fmodf(ofGetElapsedTimef()*speed,150); for(int i=0; i<150; i++){ connections.setColor(i,ofColor(ofColor(255),0)); } //as we count to the 50 trailing vertices, the number for the alpha value decreases for(int i=0, cc=50; i<50; i++,cc--){ connections.setColor(leadVertex-i,ofColor(ofColor(255),ofMap(cc,0,50,0,255))); }
And here is the update method in this larger project:
void oscThread::update() { float time = ofGetElapsedTimef()/speed; int leadVertex = fmodf(ofGetElapsedTimef()*cSpeed,res); for (int x=0;x<res;x++){ ofVec3f oscTemp = this->getMesh().getVertex(x); float p = x; float oscillation = amp * sin(2 * pi * f * time + p)/20; oscTemp.rotate(x/f,ofVec3f(1,0,0)); this->getMesh().setVertex(x,oscTemp); this->getMesh().setColor(x,ofColor(ofColor(255),0)); } for(int i=0, tAlpha=100; i<100; i++,tAlpha--){ this->getMesh().setColor(leadVertex-i,ofColor(ofColor(255),ofMap(tAlpha,0,50,0,255))); } }
What I believe is going on is while trying to select the previous 100 vertices behind the leadVertex, it points to vertices that are not there (until of course leadVertex-i actually exists). Does anyone have some tips on how to assure those actually exist? Or make leadVertex-i never go below 0? Thank you.
ofApp.h
http://pastebin.com/D3D1LLbbofApp.cpp
http://pastebin.com/BD0zMyvL
Posts: 8
Participants: 2