[英]glRotatef() works weird in Opengl
I'm about to make a rotating sphere in C++ OpenGL, MFC Application.我即将在 C++ OpenGL、MFC 应用程序中制作一个旋转球体。 so I declared a variable that has a spinning velocity in demo.h
:所以我在demo.h
声明了一个具有旋转速度的demo.h
:
GLfloat angle;
void Init();
Also, I initialized that variable and implemented one normal sphere at xyz(0,0,0) in demo.cpp
:此外,我初始化了该变量并在demo.cpp
xyz(0,0,0) 处实现了一个法线球体:
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 : Init() 是用户定义的函数,用于初始化角度变量的值:
void Init() = {
angle = 1.0;
}
In this situation, the sphere spins well.在这种情况下,球体旋转良好。 But if I change angle += 1;
但是如果我改变angle += 1;
to angle += angle;
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? ,然后Sphere不以相同的速度旋转,最后消失了:(我不知道这两者有什么区别。将“+ =”运算符应用于GLfloat类型变量有问题吗?
angle += angle
doubles the rotation value every update. angle += angle
每次更新都会使旋转值加倍。 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.根据您的更新频率,旋转几乎会立即变得完全不稳定,并且最多在几秒钟内溢出浮点数的可能值,从而变为 INFINITY,OpenGL 最有可能出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.