I have a Particle struct that I do calculations on:
struct Particle {
Vector3 Pos;
void UpdatePosition();
};
I also have a struct ParticleGroup which consists of two Particle objects. When calling UpdatePositions(), both particle positions are updated.
struct ParticleGroup {
Particle *p1 = NULL;
Particle *p2 = NULL;
ParticleGroup(Particle &p1, Particle &p2);
void UpdatePositions();
};
Now if I create a Particle and a ParticleGroup objects like this:
Particle p1;
Particle p2;
ParticleGroup pGroup(p1, p2);
And then update the position of p1 using Particle::UpdatePosition() method, its new position is going to be reflected in pGroup. And vice versa if I call Particle::UpdatePositions() method.
However if I create an array of Particle objects and an array of ParticleGroup objects using std::vector:
vector<Particle>particles;
vector<ParticleGroup>pGroups;
Now each vector gets their own copy of Particle object and updating the position in one vector will not get reflected in another.
Is there a way to create arrays of these structs and still have the changes in the particle positions reflected?