Problems with tutorial lesson 9
First thx to NEHE.
when i modify the following statement
const num=50;
to
const num=1;
and execute tht program.I find a problem,that is :
This single star just move linearly from right side of the screen to the left side of the screen.When it reach the mid of the screen,it just turnback,and loop again and again.
SO,why this single star doesnot spin around the Z axis?
[Edited by - Jeffy_ko on May 9, 2005 11:45:44 PM]
woik hard and have fun.
Works for me.
Might want to look over or post your code for the DrawGLScene function.
Might want to look over or post your code for the DrawGLScene function.
Oooh ,I'm sorry for having made a mistake.It is the LESSON 9 :Moving Bitmaps in 3D space.
The DrawGLScene() function are as followed:(PS:I downloaded this source code from the NEHE Production site.)
The DrawGLScene() function are as followed:(PS:I downloaded this source code from the NEHE Production site.)
[source lang=cpp]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]); // Select Our Texture 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; } } return TRUE; // Everything Went OK}
woik hard and have fun.
Ah, I see what is going on.
The variable *loop* is always 0. So the line
star[loop].angle+=float(loop)/num;
just adds the result of 0/1 to star[loop].angle, so the angle never increases.
Try
star[loop].angle+=float(loop+1)/num;
My *loop* starts with 1, which is why I didn't notice the problem.
The variable *loop* is always 0. So the line
star[loop].angle+=float(loop)/num;
just adds the result of 0/1 to star[loop].angle, so the angle never increases.
Try
star[loop].angle+=float(loop+1)/num;
My *loop* starts with 1, which is why I didn't notice the problem.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement