Advertisement

problems with the rotations on lesson 9

Started by March 20, 2003 11:07 PM
4 comments, last by guskt 21 years, 11 months ago
glRotatef(tilt,1.0f,0.0f,0.0f); glRotatef(star[loop].angle,0.0f,1.0f,0.0f); I can´t understand why cancel these rotations in reverse order before drawing the star? are they going to make effect on the current star, or just on the stars that are already on the screen? GuSkT!
GuSkT!


I have exactly the same question... I mean if you cancel the glRotatef() and glTranslatef() before drawing the star how does the star end up following the first definitions. I know it works correctly because I commented out these lines and saw the results but why wouldn''t you reorient the star right after you draw it so its there to reorient(this just seems more intuitive to me, but I know it doesn''t give the desired effect).

And why this method...first you tilt the whole coord system so z points down...y at you and x perpendicular to that. Then rotate around the y axis placing the stars on the x axis. Couldn''t you just rotate around the z axis and still place the stars on the x axis?

Im sure there is a good explanation...I just don''t have it!
Advertisement
just take the second rotation out and you''ll see what happens
you won''t see the stars!... you''ll only line, becase the texture was drawn facing somewhere else, not the user
that''s why you have to rotate back, to draw the texture facing the user
just take the second rotation out and you''ll see what happens
you won''t see the stars!... you''ll only see lines, becase the texture was drawn facing somewhere else, not the user
that''s why you have to rotate back, to draw the texture facing the user
quote:
I commented out these lines and saw the results


please:
quote:
if you cancel the glRotatef() and glTranslatef() before drawing the star how does the star end up following the first definitions



[edited by - dnagcat on March 24, 2003 3:30:00 PM]
I don''t know if your question has been answered but I''m going to add my $0.02 for better or for worse... the basic concept is fairly simple... imagine you have a drawing pen so what ever you draw you draw at the pen location. So we use glTranslate to move the pen in a 3d space and glRotate to change how the polygons are oriented at that location. When you call glLoadIdentity() that removes all editing of the pen... sets it back to then origin. The tricky part is understanding the rotation which i think the actualy question is about (i know I''m a bit long winded) The rotations are extreemely important when it comes to order. Any glTranslate calls you make after a glRotate call are also rotated... so if you rotate 90 around the z and then translate up the y it actually looks like you translate up the x. The reason they undo the rotation in lesson 9 is for this reason...

glRotatef(star[loop].angle,0.0f,1.0f,0.0f);
glTranslatef(star[loop].dist,0.0f,0.0f);

the whole idea for the is to rotate to the stars angle and then translate the distance from the center of the screen. Since we rotated first we move that distance in the direction of the angle we originally rotated.

glRotatef(-star[loop].angle,0.0f,1.0f,0.0f); //*this line
glRotatef(-tilt,1.0f,0.0f,0.0f);

we do this to undo the rotation of the star. when we rotated and translated out we leave our star rotated. since we dont want to draw the star partially rotated we have to undo the rotating we originally did to set the star upright again. For a more visual example comment out this line* of code and run you program with out any blending (quads with stars) and you''ll see why we need to upright our stars again.

for no blending change your blend function to...

glBlendFunc(GL_ONE,GL_ZERO);

Hope my long winded explination helps...
I'm don't know much but I can try to help... just email me at... Shadow_0f_Light@Yahoo.com(the '0' in 'Of' is a zero :P)

This topic is closed to new replies.

Advertisement