DomainFlag - 1 month ago 10

C++ Question

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

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?

Answer

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);
```