我是使用openGL的新手,现在我正在尝试旋转我制作的正方形,但是当我旋转它时,正方形不仅会旋转,还会在旋转时四处移动。我想我在旋转和翻译过程中犯了一个错误,但找不到解决方案
void drawSquare(double x,double y, int num)
{
double xLength = 0.6;
double yLength = 0.6;
for(int i=0;i<num;i++)
{
glLoadIdentity();
glPushMatrix();
glTranslatef(0, 0, 0.0f);
glRotatef(angleCW, 0.0f, 0.0f,1.0f);
glBegin( GL_QUADS );
if(i%2==0)
{
glColor3f(gCurrentRed,gCurrentGreen,gCurrentBlue);
}
else
{
glColor3f(0.0f,0.0f,0.0f);
}
glVertex3f(x,y,0);
glVertex3f(x+xLength,y,0);
glVertex3f(x+xLength,y+yLength,0);
glVertex3f(x,y+yLength,0);
xLength -=0.1;
yLength -=0.1;
x += 0.05;
y += 0.05;
glEnd();
glPopMatrix();
}
}