Hi,
I have a class named Spring in a particle system. The constructor looks like:
Spring(Particle& _a, Particle& _b);
And I have a vector of Particles and I use
Spring mySpring = Spring(myParticles.at(j),myParticles.at(j+1));
inside a loop to add a spring force between two particles. Everything works fine so far. However, I want to use a 2d vector of Particles. That is:
Spring mySpring = Spring(myParticles.at(i).at(j),myParticles.at(i).at(j+1));
And I don't get a reference to the particle. In the first example, whenever I change the particle in my spring class, the particle in the vector gets changed. In the second example the changes are only locally. How can I change the particles in the 2D Vector?
EDIT: I try to make some things clear:
I have some particle systems and each of them consists of a number of particles. Each particle should only interact with the other particles that are in the same system as itself. Therefore I have a vector of particle systems with each particle sytem being a vector of particle objects. (That makes the 2d vector). The first dimension (i) is the system, the second (j) the individual particle. The particles in the system interact with each other (collide, avoid, whatever..) and their positions change. And the vector gets "updated". (That is, the reference works).
However, i have a second (1d) vector of spring forces. The spring force too is used to update the positions of the particles. My constructor does the following:
Spring::Spring(Particle& _a, Particle& _b) {
a=&_a;
b=&_b; }
With a and b being Particle*. So i store pointers to two particles in the 2d vector. Another function Spring.doSpring() changes the positions of the particles.
a->pos.x=300;
or
a->velocity+=something..
In the first example I posted I used only one particle system and so there was no need for a 2d vector. And everything works fine. The particles in the vector gets updated. But with the second example my program runs but somehow no matter what the doSpring function does, the particles in the 2d vector don't get updated.