We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › optimizing lots of iterations
Page Index Toggle Pages: 1
optimizing lots of iterations (Read 1120 times)
optimizing lots of iterations
Aug 27th, 2009, 10:38am
 
Hello, i made a program that make lots of iterations, one iteration for each object in my program, the thing is that i need to put one iteration after iteration to make it work, so if i have  40 objets that means i need to have 40 blocks of iterations and thats very big!!!! , my question is , how can i just make one iteration that make the same as putting one block after other? is it possible?

here is the code for 3 objects:



Code:


for (int i = 0; i< 1; i++){
//object one
gl.glPushMatrix();
palabras[i].traslada();
palabras[i].rota();
model.render(0, palabras[i].numPoints);
gl.glPopMatrix();
}

}

for (int i = 1; i< 2; i++){
//object two
gl.glPushMatrix();
palabras[i].traslada();
palabras[i].rota();
model.render(palabras[1].numPoints, palabras[1].numPoints + palabras[2].numPoints);
gl.glPopMatrix();
}


for (int i = 2; i< 3; i++){
//object three
gl.glPushMatrix();
palabras[i].traslada();
palabras[i].rota();
model.render(palabras[2].numPoints, palabras[2].numPoints + palabras[3].numPoints);
gl.glPopMatrix();
}
Re: optimizing lots of iterations
Reply #1 - Aug 27th, 2009, 11:38am
 
The loops in your code aren't really loops, since they only span one value of "i."  You need to combine them into one loop that runs from 0 to 40, or whatever -- you can use values like [i+1], that should be all you need to tie it together.

for (int i=0;i<40;i++){
 //  do stuff with palabras[i] and palabras[i+1]
}

you may need exceptions for your first and last case, or a constrain() inside your brackets, to keep from exceeding your array length...

--Ben
Re: optimizing lots of iterations
Reply #2 - Aug 27th, 2009, 2:58pm
 
hi i make this code, but how can i draw the first and the last objects?

thanks

Code:

for (int i=0;i<numero_objetos - 1;i++){
gl.glPushMatrix();
palabras[i].traslada();
palabras[i].rota();
model.render(palabras[i].numPoints, palabras[i].numPoints + palabras[constrain( i + 1, 0, numero_objetos - 1) ].numPoints);
gl.glPopMatrix();

}

Re: optimizing lots of iterations
Reply #3 - Aug 27th, 2009, 3:02pm
 
If your render() script depends on referencing another object, and you can't just link the last one to the first one, then I don't know a super-elegant way.  You'll probably have to either draw them outside of your loop, or include an if statement, basically:

if (this is the first or last object) render it in a special way;

--Ben
Re: optimizing lots of iterations
Reply #4 - Aug 28th, 2009, 1:06am
 
It seems to me that you ARE drawing the first object. just not the last object.

Your initial example for 3 objects referenced "palabras[3].numPoints", which doesn't exist if palabras only has 3 elements (in which case the index can only be 0, 1 or 2, not 3).

Why does the render function need the number of points of the next object? Does it internally reference the palabras array?

int intendedObjectIndex = 40; // the 41st object...
int legalObjectIndex = intendedObjectIndex % numberArrayElements;
Re: optimizing lots of iterations
Reply #5 - Aug 28th, 2009, 2:22pm
 
hi , thats because im using glmodel from glgraphics and i can  pass the coordinates or vertices of the model to render , doing something like this:

model.render(0, 4); i can render the vertices  0 to 4 from the model , and then model.render(4, 8) ; i can render 4 to 8 vertices from the same model , so in that way i can selectively choose diferent vertices from my array to render so i can apply diferent gl transformation functions to the same model, separating the vertices.

hope that make sense

bye
Page Index Toggle Pages: 1