Click to See Complete Forum and Search --> : for loops


joeybird
March 5th, 2005, 07:36 AM
hi i wish to create a for loop, with this code information, does anyone know how to do this, i want to colour in certain triangles along a triangle polymesh, i want them to be different colours but they must not repeat a colour.

here is the code from CGPolymesh.cpp

for ((faceIndex!=-1) && m->C[faceIndex].r!=(1.0))
{
//makes a length of red terrain
m -> C [faceIndex].r =(1.0);
m -> C [faceIndex].g =(0.0);
m -> C [faceIndex].b =(0.0);
m -> C [faceIndex].a =(1.0);

faceIndex = nextFace(m, faceIndex, edgeIndex);

//makes a length of red and white triagle strips terrain
m -> C [faceIndex].r =(6.0);
m -> C [faceIndex].g =(6.0);
m -> C [faceIndex].b =(6.0);
m -> C [faceIndex].a =(6.0);

faceIndex = nextFace(m, faceIndex, edgeIndex);
}

in main.cpp the beginning triangle specifed is

faceStrip(&myTerrain, 8, 2);




what am i doing wrong ? am i doing the

for(initialisations;condition;loopincrementation)
statement;

correct?

thanx

joeybird

NoHero
March 5th, 2005, 09:11 AM
If you create for loop where you only use the expression you must write:


for ( ; (faceIndex!=-1) && m->C[faceIndex].r!=(1.0) ; )


To indicate that the first and the last part are not used. But why a for loop? A while loop would be better for this circumstance.

joeybird
March 7th, 2005, 03:36 AM
ok if i place a while loop in this function, instead of a for loop, when colouring different coloured triangles along a triangle polymesh how can i colour each one seperately, and not stop one colour being repeated?

here is the code im using in a previous function to call a triangle face

int myFace1, myFace2;

myFace1 = m -> E [myEdge]. f1;
myFace2 = m -> E [myEdge]. f2;

thanks jo