• Advertisement

Archived

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

cube spins, but looks like it spins, then stops for a sec, then spins, then stops,etc

This topic is 5487 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

the cube is spinning, but it''s like not spinnig fluidly to put it one way. Does anyone know why this is happening? Here is the code #include <windows.h> #include <gl/glut.h> void display(void); void ChangeSize(GLsizei w, GLsizei h); double rot = 0.0f; int main(int argc, char** argv) { glutInit (&argc, argv) ; glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ; glutInitWindowSize (800, 600) ; glutInitWindowPosition (100, 100) ; glutCreateWindow ("First Chapter - Opening an OpenGL Window") ; glClearColor(0.0f,0.0f,0.0f,1.0f); glEnable(GL_DEPTH_TEST); glutDisplayFunc(display); glutReshapeFunc(ChangeSize); glutMainLoop(); return 0 ; } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Done Drawing The Quad glTranslatef(0.0f,0.0f,-10.0f); if(rot == 360.0) rot = 0.0; glRotatef(rot,1.0,1.0,1.0); glBegin(GL_QUADS); //top glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(1.0f,0.0f,-1.0f); glColor3f(1.0f,1.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); //bottom glColor3f(0.0f,1.0f,0.0f); glVertex3f(0.0f,-1.0f,0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.0f,-1.0f,-1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(1.0f,-1.0f,-1.0f); glColor3f(0.0f,1.0f,1.0f); glVertex3f(1.0f,-1.0f,0.0f); //front glColor3f(0.0f,0.0f,1.0f); glVertex3f(0.0f,0.0f,0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,-1.0f,0.0f); glColor3f(1.0f,0.0f,1.0f); glVertex3f(0.0f,-1.0f,0.0f); //back glColor3f(1.0f,1.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glColor3f(1.0f,0.0f,1.0f); glVertex3f(1.0f,0.0f,-1.0f); glColor3f(0.0f,1.0f,1.0f); glVertex3f(1.0f,-1.0f,-1.0f); glColor3f(1.0f,1.0f,1.0f); glVertex3f(0.0f,-1.0f,-1.0f); //left glColor3f(1.0f,0.0f,1.0f); glVertex3f(0.0f,0.0f,0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glColor3f(1.0f,1.0f,0.0f); glVertex3f(0.0f,-1.0f,-1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(0.0f,-1.0f,0.0f); //right glColor3f(0.0f,1.0f,1.0f); glVertex3f(1.0f,0.0f,0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,-1.0f); glColor3f(1.0f,0.0f,1.0f); glVertex3f(1.0f,-1.0f,-1.0f); glColor3f(1.0f,1.0f,0.0f); glVertex3f(1.0f,-1.0f,0.0f); glEnd(); rot+=0.2f; glutSwapBuffers(); glutPostRedisplay(); } void ChangeSize(GLsizei w, GLsizei h) { if (h==0) // Prevent A Divide By Zero By { h=1; // Making Height Equal One } glViewport(0, 0, w, h); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window // (Field of view, aspect ratio, near, far) gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,200.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix }

Share this post


Link to post
Share on other sites
Advertisement
Try using QueryPerformanceCounter() to get the time taken by the previous frame and instead of
rot += 0.2f;
do
rot += 0.2f*frametime;

Share this post


Link to post
Share on other sites
Looks fine to me. You do realize you are rotating about the vector (1,1,1) right? Since the origin of your scene isn''t the center of the cube, that isn''t going to spin about it''s center, but rather one of the corners.

Share this post


Link to post
Share on other sites
Due to floating point inaccuracy you shouldn''t do :

if(rot == 360.0)
rot = 0.0;

but

if(rot >= 360.0)
rot -= 360.0;

instead, though I don''t think this will fix the problem.

Share this post


Link to post
Share on other sites

  • Advertisement