I have a particle system of 21 boids. They all have different states for when you interact with them. So I basically want that when the user touches one and a menu pops, the others go to a state where no interaction can affect them.
The purpose for this is so that when one boid is selected and a menu pops I don't get to interact with the others while that menu is being displayed.
I tried the following but didn't work:
1 2 3 4 5 6 7
for ( int i = 0; i < families->boidList.size(); i++){
for ( int j = i + 1; j < families->boidList.size(); j++){
if ( families->boidList[i]->boidState == 1 || families->boidList[i]->boidState == 2){
families->boidList[j]->boidState = 0;
}
}
}
I thought that by comparing one in respect to the others and increasing the index j by one will stop from comparing the same boid with itself. It works with some boids but the others seem to remain at zero, even though there's not one boid sith a state of 1 or 2. Some of the boids remain in 0 :(.
I basically need all my particles to be boidState = 5. But that when one is in boidState = 1 || boidState = 2, For the others to be boidState = 0. But once the state of that boid goes back to 5 the others go back to 5 as well. Hope that makes sense.
ok I figured it out! But I wonder if there's an easy way so here what it came down to:
Once again this is what I needed:
I basically need all my particles to be boidState = 5. But that when one is in boidState = 1 || boidState = 2, For the others to be boidState = 0. But once the state of that boid goes back to 5 the others go back to 5 as well. Hope that makes sense.
So the boids or particles are in a class called FamilyController. And from my main controller I get to control my
Here is the code:
vector<bool>::iterator it;
it = find(_tmp->isParticleHovered.begin(), _tmp->isParticleHovered.end(), true);// isParticleHover is a vector of bools inside the FamilyController that keeps track of when a Boid is being hovered.
if (it != _tmp->isParticleHovered.end()){// we look if a particle is being hovered.
l = distance(_tmp->isParticleHovered.begin(), it);// we store the index of the Boid being hovered.
}
//This is where the magic happens
if (_tmp->boidList[l]->boidState == 5 && boidState5) {
resetFamilyBoidState(_tmp, l);// we set the rest of them, which are in state 0 to be 5 again so that they can be choosen again.
boidState1 = true;
boidState2 = true;
boidState5 = false;// we make sure we run the function only once.
}elseif(_tmp->boidList[l]->boidState == 1 && boidState1){
makeBoidStateless(_tmp, l);// this functions loops through all the boids and set their state to 0, we pass "l" which is the one we want to keep so that it skips it inside the function.
boidState2 = true;
boidState5 = true;
boidState1 = false;// we make sure we run the function only once.
}elseif (_tmp->boidList[l]->boidState == 2 && boidState2){
makeBoidStateless(_tmp, l);// this functions loops through all the boids and set their state to 0, we pass "l" which is the one we want to keep so that it skips it.
boidState5 = true;
boidState1 = true;
boidState2 = false;// we make sure we run the function only once.
}
I realized that the problem with the for loop, nested for loop, etc. Is that because is iterative it will keep my states at that number. And states need to be changed. God bless booleans :).
I'm still wondering if there's an easier way to access elements. I'm using c++ 98 BTW.Again, suggestions of other ways to do this, make me curious.