简体   繁体   中英

glRotatef() works weird in Opengl

I'm about to make a rotating sphere in C++ OpenGL, MFC Application. so I declared a variable that has a spinning velocity in demo.h :

GLfloat angle;
void Init();

Also, I initialized that variable and implemented one normal sphere at xyz(0,0,0) in demo.cpp :

Init();
angle += 1;
glRotatef(angle, 0, 1, 0);
GLUquadricObj* a = gluNewQuadric();
gluSphere(a, 10, 100, 100);  //radius = 10

Init() is user-defined function that initiates the value of angle variable :

void Init() = {
    angle = 1.0;
}

In this situation, the sphere spins well. But if I change angle += 1; to angle += angle; , then the Sphere does not rotate at the same speed and finally disappears :( I don't know what is the difference between these two. Is there a problem with applying "+=" operator to GLfloat type variables?

angle += angle doubles the rotation value every update. Depending on your update frequency, the spinning will almost immediately become completely erratic, and within a few seconds at most overflow the possible values for a float, thus becoming INFINITY, which OpenGL most likely errors out on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM