I have searched the forum, read the doc and tutorial sorry if I missed something.
I am trying to draw a trail behind moving planets. Unfortunately, there is an extraline that should not be there linking the last vertex of my vertexArray and the origin of my window. You can see in the picture I uploaded. I have no vertex(0,0) in my array, and even if I had, I am erasing the last points when my array gets larger then 500 points so at some point, it should be erased. However, the extraline is always there and follows the last vertex of my trail.
//MY TRAIL
if(utility_clock.getElapsedTime().asSeconds() > 0.01){
utility_clock.restart();
Vector2f aVec(myState.x, myState.y);
myTrace.push_back(aVec);
}
while(myTrace.size() > 500){
myTrace.erase(myTrace.begin());
}
VertexArray trace(LinesStrip, myTrace.size());
for(vector<Vector2f>::iterator it = myTrace.begin(); it != myTrace.end(); ++it){
it->x -= offset.x;
it->y -= offset.y;
trace.append(Vertex(*it, Color::White));
}
myWin.draw(trace);
I have tried drawing the exact same thing using indexes like in the tutorial, and it works fine.
int cpt = 0;
for(vector<Vector2f>::iterator it = myTrace.begin(); it != myTrace.end(); ++it){
it->x -= offset.x;
it->y -= offset.y;
trace[cpt] = Vertex(*it, Color::White);
cpt++;
}
What's with the function append? Am I using it wrong? I thought it was similar to a push_back function for vectors.
What do you mean? You can use the sf::Lines primitive directly with sf::VertexArray...
I mean I draw a some lines in Illustrator export it as svg, eps or what ever,
convert it to sf::lines/VertexArray and render it in sfml.
SFML does not support vector graphics. To load such files, you have to find a different library or parse it yourself. There have been some posts in the forum that might help you.
How do you get 1000 vertices into a VertexArray
Read the documentation ::)
Using Libra office Draw app: a line drawn with snap to grid at 10,10 to 20,20
end up exported as svg looking like this I see
<g class="com.sun.star.drawing.LineShape">
<g id="id3">
<path fill="none" stroke="rgb(0,0,0)" d="M 1000,1000 L 2000,2000"/>
And a poly like this:
<g class="com.sun.star.drawing.PolyPolygonShape">
<g id="id3">
<path fill="none" stroke="rgb(52,101,164)" d="M 1000,1000 L 3000,1000 3000,1500 2500,1500 2500,2000 2000,2000 2000,1500 1500,1500 1000,1000 Z"/>
Looks straight forward... ;D