Alright so I'm working on a particle physics simulation (namely rain) for my dissertation using OpenGL. Self explanatory I guess.
So I've been working through getting back into C++ after using C# for Unity for quite some time. Everythings pretty much came back to me by now. I've spent a couple of weeks on this system building it up from almost the ground (I used an old OpenGL framework just so I could get the more important things done quickly
)
I have particles rendering and falling based on velocity calculated from deltaTime (time between updates) this didn't take long to get working. However I've come across an issue...
I'm using three STL vectors to store my particles which again I'm happy enough with as they are pretty fast for access speeds. The way that I'm using them is a particle is created and added to the newParticleVector to begin with.
After this is done the second vector renderParVector is suppose to have the elements of newParticleVector added to it in chunks of i. Heres the code as it currently stands:
Now as the elements are added to renderParVector from newParticleVector in sets of i the newParticleVector should clear from the beginning of the vector to what the npvIt was pointing to before it was incremented. (So for the sake of argument the 10th thing it was pointing to is now onpvIt and npvIt has incremented to the next element) This somewhat works until we get to the last i amount left in the newParticleVector which leaves i elements remaining. Now I've tried a couple of changes to the way this bit of code works... But I can't figure out the way to have it so the newParticleVector completely empties. Either I'm stuck on thinking this logic must work this way... Or what I'm trying to do is impossible and shouldn't be done.
Oh also the last vector is just used to store particles that are being flagged for deletion before the next frame update.
Thanks for any help!
So I've been working through getting back into C++ after using C# for Unity for quite some time. Everythings pretty much came back to me by now. I've spent a couple of weeks on this system building it up from almost the ground (I used an old OpenGL framework just so I could get the more important things done quickly

I have particles rendering and falling based on velocity calculated from deltaTime (time between updates) this didn't take long to get working. However I've come across an issue...
I'm using three STL vectors to store my particles which again I'm happy enough with as they are pretty fast for access speeds. The way that I'm using them is a particle is created and added to the newParticleVector to begin with.
After this is done the second vector renderParVector is suppose to have the elements of newParticleVector added to it in chunks of i. Heres the code as it currently stands:
Code:
void Simulation::fillRendVect()
{
std::vector<Particle*>::iterator npvIt;
std::vector<Particle*>::iterator onpvIt;
int i = 0;
npvIt = newParticleVector.begin();
for (npvIt = newParticleVector.begin(); npvIt != newParticleVector.end(); npvIt++)
{
onpvIt = npvIt;
if (i != numParOnScrn)
{
renderParVector.push_back((*npvIt));
i++;
}
else
{
npvIt++;
i = 0;
newParticleVector.erase(newParticleVector.begin(), onpvIt);
return;
}
}
}
Now as the elements are added to renderParVector from newParticleVector in sets of i the newParticleVector should clear from the beginning of the vector to what the npvIt was pointing to before it was incremented. (So for the sake of argument the 10th thing it was pointing to is now onpvIt and npvIt has incremented to the next element) This somewhat works until we get to the last i amount left in the newParticleVector which leaves i elements remaining. Now I've tried a couple of changes to the way this bit of code works... But I can't figure out the way to have it so the newParticleVector completely empties. Either I'm stuck on thinking this logic must work this way... Or what I'm trying to do is impossible and shouldn't be done.
Oh also the last vector is just used to store particles that are being flagged for deletion before the next frame update.
Thanks for any help!