DomainFlag - 7 months ago 32
C++ Question

# Iterating through table in c++?

I have a table with structures containing polygon structure, each containing a table with ~ 100 complex numbers.

initPoly1(T[0]);
...
initPoly4(T[3]);

What I am doing is interpolating each polygon with the other using dt(wich goes between 0..1 and when it reaches 1 it starts once again with 0), so I am using the procedure to do interpolation and show the result(morphing effect):

animer(T[indice], T[indice+1], dt);

What I am stuck is I want to create a cycle/interation, like so
T[0], T[1] ... T[1], T[2] ... T[2], T[3], and then T[3], T[0] and on and on.

Is there any way besides what I did using 2 variables x and y:

if(dt == 1.0)
{
x++;
t++;
if(t==4)
{
t=0;
}
else if(x==4)
{
x=0;
}
}
animer(T[x], T[t], dt);

Because it slows my program so much, that the animation looks disturbing(but it works), any idea to improve?

you can use sum MODULE

if(dt == 1.0)
{
x = (x+1)%4;
t= (t+1)%4;
}
animer(T[x], T[t], dt);

or more simple

if(dt == 1.0)
{
x = (x+1)%4;
}
animer(T[x], T[(x+1)%4], dt);
Source (Stackoverflow)