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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Adrisaboss

Pages: [1]
1
In fact I still don't understand something.
From what I understand, you advise me to 2 arrays in my Fenetre class : the VertexArray, which will be displayed by the RenderWindow, and a vector of Particles, where my Particle class would look like :
Code: [Select]
class Particle {
public :
  void update(sf::Vertex &vertex);
  // Constructor etc...
private :
  sf::Vector2f v;
  // All the other members I would need to perform a nice animation...
}

But isn't it sad to be obliged to have 2 arrays ? Plus the correspondence between the Vertex and the Particle is only made by its position in the arrays, like :
Code: [Select]
Fenettre::update() {
  for (int i = 0; i < particles.size(); ++i) {
     particles[i].update(vertexArray[i]);
  }
}

What if I want to make my arrays dynamic ? And this isn't very secure, if vertexArray contains less elements than particles...

2
Graphics / Re: [sf::VertexArray VS std::vector] Strange behaviour
« on: May 13, 2012, 07:11:48 pm »
Thanks for the fast reply !
Consider my problem solved. :D

3
Hi there !

I am testing SFML 2.0 by coding a little particle system. I don't know much about particles but I only use Vertex as points applying them some physics rules, so that's very simple.

Here is the class managing the displaying and updating of the particles on the screen :
Fenetre::Fenetre() {
        m_window = new sf::RenderWindow(sf::VideoMode(WINDOW_W, WINDOW_H, 32), WINDOW_TITLE);
        m_window->setVerticalSyncEnabled(true);
       
        particles.assign(PARTICLES_MAX, Particle());
        vertexArray.setPrimitiveType(sf::Points); // Added recently
       
        m_pause = false;
        m_continue = true;
       
        clock.restart();
}


int Fenetre::exec() {  
        while (m_continue && m_window->isOpen()) {
                handleEvents();

                if (!m_pause)
                        update();
                clock.restart();

                display();
        }
       
        return EXIT_SUCCESS;
}

void Fenetre::update() {
        float dt = clock.getElapsedTime().asSeconds();
       
        vertexArray.clear(); // Added recently
        for (int i = 0; i != particles.size(); ++i) {
                particles[i].update(dt);
                vertexArray.append(particles[i]);  // Added recently
        }
}

void Fenetre::display() {
        m_window->clear();
       
        m_window->draw(vertexArray); // Added recently
        // I used to draw this way before using VertexArray :
        //m_window->draw((sf::Vertex*) &particles[0], (unsigned int) particles.size(), sf::Points);    
       
        m_window->display();
}

The class Particle extends Vertex, adding members like speed to it, and its update() method handles the physics stuff.

At the beggining, I only used std::vector, causing a strange behaviour to my render :
http://www.noelshack.com/2012-19-1336926110-Capture-1.png
As you can see some particles display on the left, falling verticaly, and I couldn't see them when I tried doing cout on my vector.

So I switched to VertexArray, which works fine, even if I implemented it really poorly (des/allocating a 1000 long array at each frame is not a good idea, I know ^^ ).

So my questions are :
- Why do I get this strange behaviour when storing my Particles in a vector ?
- Is there a sweet method to use VertexArray with a better memory management without changing my Particle class or should my Particle take the Vertex as parameter of their update method ?

Thanks a lot !
PS : SFML rules, you developers are geniuses ! ^^

Pages: [1]