PDA

View Full Version : Post-order multiplication question

05-22-2008, 06:40 PM
Hey all,

I'm stuck. I'm trying to draw a pyramid of cubes, 6 rows high, and each row is five cubes deep. I've got an inner loop that succesfully makes a line of 5 cubes along the z-axis but now trying to get 6 rows of these. I've got an algorithm down but I'm not sure about the order of multiplication here since I have inner body loops. For example, if I have:

glPushMatrix();
glTranslatef(0.0, 20.0, 0.0);
for (row = 0; row < 6; row++) // draw 6 rows
{
glTranslatef(0.0, -4.0, 0.0);
[...]

Which translation matrix would be multiplied first?

Here's the code:

GLint row = 1;
GLint i = 0;
glPushMatrix();
glTranslatef(0.0, 20.0, 0.0);
for (row = 0; row < 6; row++) // draw 6 rows
{
glTranslatef(0.0, -4.0, 0.0);
GLint j = 0;
while (j < row + 1)
{
glTranslatef(4.0, 0.0, 0.0);
for (i = 0; i < 5; i++) // draws 5 cubes along z
{
glPushMatrix();
[...]
glPopMatrix();
}
j++;
}
}
glPopMatrix();

The inner loop is working fine and I seem to be getting the 6 rows only the rows are scattered and not in the pyramid shape I'm going for...