#### Archived

This topic is now archived and is closed to further replies.

# display lists lesson 12

This topic is 5230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi instead of rotating the individual cubes can you just rotate the whole collection of cubes? is this even possible? cheers

##### Share on other sites
yup,

if the rotation function is in the display list.

##### Share on other sites
Or do you mean rotate the collection around one point? Thats possible too.

Just use One rotation function before you draw the cubes. Use gltranslate to specify the point you want to rotate around.

Be sure to use counter rotation and translation function once the cubes are drawn

##### Share on other sites
thanks for your replies i do mean to rotate all the objects about a single fixed point however performing a rotation before the drawing routine doesnt seem to work as glLoadIdentity is called every time a single cube is draw.(doesnt that just reset everything)

ive tried putting glloadidentity outside the drawing loop but strange things happen

can anyone help

##### Share on other sites

To be honest the function of glLoadIndentity is a bit of a mystery to me.

I usually use it a couple of times at the screen initialisation and thats it.

glMatrixMode(GL_PROJECTION);

glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, -100.0, 100);

glMatrixMode(GL_MODELVIEW);

The only other time I find I need to use it is when I switch the matrix mode to GL_TEXTURE.

So I guess my question is what find of strange things happen when you leave glLoadIndentity out?

##### Share on other sites
this is takes directly from lesson 12 in the DrawGLScene function

for (yloop=1;yloop<6;yloop++)
{

for (xloop=0;xloop {
glTranslatef(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.0f);
glRotatef(45.0f-(2.0f*yloop)+xrot,1.0f,0.0f,0.0f);
glRotatef(45.0f+yrot,0.0f,1.0f,0.0f);
glColor3fv(boxcol[yloop-1]);
glCallList(box);
glColor3fv(topcol[yloop-1]);
glCallList(top);
}
}

if you leave gl load identity out nothing seems to get drawn
if you put it in the first loop the left side of the triangular shape gets drawn
if you put it at the beginning of the loop cubes everywhere

im still messing around with the code trying to get the whole object of cubes to rotate about one fixed point however still had no luck. Am i going about this all wrong (quite possible)

cheers

##### Share on other sites
ok, use glloadidentity before the first loop but at the end of the inner loop once the cube is drawn retrace your translation and rotation, like so:_

glTranslatef(-(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f)),-((6.0f-float(yloop))*2.4f)-7.0f,20.0f);
glRotatef(-(45.0f-(2.0f*yloop)+xrot),1.0f,0.0f,0.0f);
glRotatef(-(45.0f+yrot),0.0f,1.0f,0.0f);

This should do what glLoadidentity is being used for in this instance.

##### Share on other sites
its looks good loads of cubes wizzing round but not exactly what i was hoping for. Giving me ideas for intro sequences.

code so far

int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glBindTexture(GL_TEXTURE_2D, texture[0]);

for (yloop=1;yloop<6;yloop++)
{
for (xloop=0;xloop {

glTranslatef(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.0f);
glRotatef(45.0f-(2.0f*yloop)+xrot,1.0f,0.0f,0.0f);
glRotatef(45.0f+yrot,0.0f,1.0f,0.0f);
glColor3fv(boxcol[yloop-1]);
glCallList(box);
glColor3fv(topcol[yloop-1]);
glCallList(top);

glTranslatef(-(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f)),-((6.0f-float(yloop))*2.4f)-7.0f,20.0f);
glRotatef(-(45.0f-(2.0f*yloop)+xrot),1.0f,0.0f,0.0f);
glRotatef(-(45.0f+yrot),0.0f,1.0f,0.0f);
}
}
return TRUE; // Keep Going
}

again i might just b a dumb a and misunderstood your explaination. Its getting closer to the solution( yeah what do i know) but still not rotating the trangular set of cubes about a fixed point

##### Share on other sites
Good glad we are getting closer.

What is it doing wrong/not doing?

Do you perhaps need to move the translation and rotation in to the outer loop?

Yeah I''ve found loadsa nice effects by accident.

##### Share on other sites
the program i posted earlier rotates the first cube fine about the centre of that cube. However in drawing the rest of the cubes is where the problem is as there all over the screen. seemingly to rotate possible about the centre point of the correctly drawn cube. However because there drawn all over the place and not in the trangular structure rotating doesn''t give the desired effect. Im not sure if i have been clear in my explaination of what i want the program to do so i will try again.

i want the program to draw the triangular structure that is created in the default example ofound on the nehe opengl web site lesson 12 - display lists. however instead of rotating all the individual cubes i want it to rotate the whole collection of cubes about 1 single point but to still stay in the triangular structure when rotated about that rotation point.
also ignore the omissions that are on the inner loop(x loop) in the previous post its supposed to read: for (xloop=0;xloop
i have tried putting the code in may places with no luck

hope that helps in understanding my problem, hopefully we might get it cracked soon

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002290
×