Lesson 9 - Moving bitmaps/textures in space

Started by
-1 comments, last by zippo 23 years, 11 months ago
Alright, this is a general question, but stems from the example used in Lesson 9 of the NeHe tutorials. In it, it discusses how to move texture mapped polys in space. From what I read, it sounds like it rotates the scene, then moves the poly down the axis, then rotates it back, creating the effect of moving it through space. This is a big generalization, as I''m really not too sure on how it''s exactly done. I mean, I understand the code, for the most part, but just don''t seem to be clicking with what''s happening. Below is the bulk of the code from lesson 9 that performs this... for (loop=0; loop<num; loop++) // Loop Through All The Stars { glLoadIdentity(); // Reset The View Before We Draw Each Star glTranslatef(0.0f,0.0f,zoom); // Zoom Into The Screen (Using The Value In ''zoom'') glRotatef(tilt,1.0f,0.0f,0.0f); // Tilt The View (Using The Value In ''tilt'') glRotatef(star[loop].angle,0.0f,1.0f,0.0f); // Rotate To The Current Stars Angle glTranslatef(star[loop].dist,0.0f,0.0f); // Move Forward On The X Plane glRotatef(-star[loop].angle,0.0f,1.0f,0.0f); // Cancel The Current Stars Angle glRotatef(-tilt,1.0f,0.0f,0.0f); // Cancel The Screen Tilt if (twinkle) { glColor4ub(star[(num-loop)-1].r,star[(num-loop)-1].g,star[(num-loop)-1].b,255); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); } glRotatef(spin,0.0f,0.0f,1.0f); glColor4ub(star[loop].r,star[loop].g,star[loop].b,255); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); spin+=0.01f; star[loop].angle+=float(loop)/num; star[loop].dist-=0.01f; if (star[loop].dist<0.0f) { star[loop].dist+=5.0f; star[loop].r=rand()%256; star[loop].g=rand()%256; star[loop].b=rand()%256; } ...That''s the bulk of the DrawGLScene function. I understand a lot of what''s going on, but the lines that have me particularly puzzled are... glTranslatef(0.0f,0.0f,zoom); // Zoom Into The Screen (Using The Value In ''zoom'') glRotatef(tilt,1.0f,0.0f,0.0f); // Tilt The View (Using The Value In ''tilt'') glRotatef(star[loop].angle,0.0f,1.0f,0.0f); // Rotate To The Current Stars Angle glTranslatef(star[loop].dist,0.0f,0.0f); // Move Forward On The X Plane glRotatef(-star[loop].angle,0.0f,1.0f,0.0f); // Cancel The Current Stars Angle glRotatef(-tilt,1.0f,0.0f,0.0f); // Cancel The Screen Tilt ...I''ve looked through this a few times but still just don''t know everything that''s going on here. Probably just because there are things that glRotatef does that I''m not aware of, or at least am not thinking of. So, if anyone has lesson 9 off-hand, or you''re familiar with this, I''d appreciate the clarity on this issue. I read the documentation in the tutorial about what it''s doing, but am just missing something here. Thanks! zippo

This topic is closed to new replies.

Advertisement