Advertisement

need help on rotation

Started by February 28, 2003 10:03 AM
2 comments, last by gl_newbie 22 years ago
i was just trying to do lesson 4 on console mode and i can''t make the quad rotate. any tips? thanks in advance. here''s the code: #include <GL/glut.h> GLfloat x; void event_display (void) { // set background color (black) for clearing window glClearColor(0.0, 0.0, 0.0, 0.0); // clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //glTranslatef(-1.0,0.0,-1.0); glRotatef(x,0.0,0.0,1.0); glBegin(GL_QUADS); glColor3f(0.0, 1.0, 0.0); glVertex3f(-0.4f, 0.4f, 0.0f); glColor3f(1.0, 0.0, 0.0); glVertex3f(0.4f, 0.4f, 0.0f); glColor3f(0.0, 0.0, 1.0); glVertex3f(0.4f,-0.4f,0.0f); glColor3f(0.5, 0.5, 0.0); glVertex3f(-0.4f, -0.4f, 0.0f); glEnd(); x+=0.15f; // ensure completion of previous commands! glFlush(); } void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(300, 300); glutInitWindowPosition(0, 0); glutCreateWindow(argv[0]); glutDisplayFunc(event_display); glutMainLoop(); }
Ufff, all seemes OK, but:

try to change
x+=0.15f; // 0.15 degrees
to
x+=5.0f; // 5 degrees
PM Times change... Excuse my poor english!
Advertisement
GLfloat x;

should be:

GLfloat x=0;

because you didn't assign x a valid value, it will likly be set to a pre-defined bit pattern or simply be randome noise (depends on os, compile type, etc) It will actually least likly be 0. This means it's likly set to an extremly huge value, thus due to the low precision of floats, adding 0.15 to a number with potentially 100s of significant figures won't do a thing, especially since a float is only accurate to around 7 sf.

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |

[edited by - RipTorn on February 28, 2003 5:37:35 PM]
thanks for the tips guys! it is rotating slowly, but hey it''s a start.

This topic is closed to new replies.

Advertisement