Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: vertexArray.append()  (Read 4314 times)

0 Members and 1 Guest are viewing this topic.

gremio

  • Newbie
  • *
  • Posts: 9
    • View Profile
vertexArray.append()
« on: November 15, 2014, 07:30:32 pm »
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.
« Last Edit: November 15, 2014, 07:38:43 pm by gremio »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: vertexArray.append()
« Reply #1 on: November 15, 2014, 07:40:28 pm »
Make sure you consult the documentation for the things you use, in your case the VertexArray constructor. I don't think you want an initial number of vertices (which are default-constructed with position (0,0)).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gremio

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: vertexArray.append()
« Reply #2 on: November 15, 2014, 07:46:44 pm »
Got it!

Rasmussen

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: vertexArray.append()
« Reply #3 on: November 17, 2014, 09:24:42 pm »
Has anyone made a converter or utility so vector lines from a drawing program can be displayed with a vertexArray ?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: vertexArray.append()
« Reply #4 on: November 17, 2014, 11:48:35 pm »
What do you mean? You can use the sf::Lines primitive directly with sf::VertexArray...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Rasmussen

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: vertexArray.append()
« Reply #5 on: November 18, 2014, 09:18:12 pm »
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.

How do you get 1000 vertices into a VertexArray


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: vertexArray.append()
« Reply #6 on: November 18, 2014, 09:30:30 pm »
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 ::)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Rasmussen

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: vertexArray.append()
« Reply #7 on: November 18, 2014, 10:20:37 pm »
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