Archived

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

display lists lesson 12

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
yup,

if the rotation function is in the display list.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites
Right I''ve found me password.

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);
glLoadIdentity();

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

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);

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 this post


Link to post
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 {
glLoadIdentity(); // Reset The View
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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]);

glLoadIdentity();

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
right this lot should work use up and down arrows to rotate.

glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glRotatef(45.0f-(2.0f*yloop)+xrot,0.0f,0.0f,1.0f);

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);
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);
}
}
return TRUE;

Share this post


Link to post
Share on other sites
this is the whole draw scene function im using below

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
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glRotatef(45.0f-(2.0f*yloop)+xrot,0.0f,0.0f,1.0f);

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

for (xloop=0 ;xloop; xloop++)
{
glTranslatef(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.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);
}
}
return TRUE; // Keep Going
}

this now draws nothing to the screen ( or at least i cannnot see it) ive tried it with and without the glclear at the top, no luck . i just cut and paste the previous suggestion again i might of cut and paste wrong. have you tried using this code in lesson 12? it might help clear up what ive poorly explained

cheers

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
new to this arent you


for (xloop=0;xloop<yloop;xloop++)

is the correct inner loop

Share this post


Link to post
Share on other sites
yeah i am new to opengl programming, have only been doing it in my spare time for about 3 months, but have been doing c programming for about 3 years as part of my uni course.

the inner loop is taken directly from lesson 12 so i assume its correct. This draws the triangular shape of cubes. Have you looked at the lesson 12 demo? If you do im sure it wil help in finding a solution to this problem

cheers

Share this post


Link to post
Share on other sites
list of current code, other code wasn''t working as i had yloop variable outside of the y loop(i think). this was previously suggested to me i simply cut and paste the code without looking at it.
current code below draws one cube in the right place and it moves left, right,up and down the screen. rotation point is wrong and draw sequence not quite right. I can see another cube drawn however this is small and in the distance.

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]);
glLoadIdentity();
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);

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


}
}
return TRUE; // Keep Going
}

Share this post


Link to post
Share on other sites