about rotate on Y axis!

Hi all,

I draw a circle and try to rotate it on the Y axis, but it does not work as i think. It works well on every
first PI/2 rotate, but when the second PI rotate begins, the circle becomes very big, with rotate continues,
it occupies all the client area, then it begins to become small and return back to its origin mode. How to
solve this problem? Thanks a lot!

my code is as follow:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

float r;
static float angle;
glTranslatef(0.0f, 0.0f, -2.0f);
glRotatef(angle, 0.0f, 1.0f, 0.0f);
float fxMin, fxMax, fyMin, fyMax;
GL_GetViewRange(-2.0f, fxMin, fxMax, fyMin, fyMax);
r = min((fxMax-fxMin)/2, (fyMax-fyMin)/2) - 0.5;
glBegin(GL_POLYGON);
for (float f=0.0f; f<2*PI; f+=0.01f)
{
	glVertex3f(r*cos(f), r*sin(f), 0.0f);
}
glEnd();
angle -= 0.05f;

Thanks again!

sorry, i want the circle rotates on its diameter, not the Y axis!
can anybody help me? thanks in advance!

What’s your projection matrix set to?

Are you sure you’re in MODELVIEW matrix mode when entering the display loop?

What rotating an circle across it’s diameter mean? There are a whole bunch of axes you can rotate around. What are you trying to do? If I can safely assume you are entering your display loop in MODELVIEW mode, you don’t set a camera (which is fine) so you’re looking down the negative z-axis. Rotating it about y or x will give a look of the circle collapsing and growing again while rotating about z is it just spinning around like you’d see a tire do on the side of a car. Just try a different angle in glRotate until you get the one you want.

Hi strattonbrazil,

Thanks for your reply!

What’s your projection matrix set to?

My projection matrix setting is as follow:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Are you sure you’re in MODELVIEW matrix mode when entering the display loop?

and my draw circle function is here:

void GL_DrawCircle()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

float r;
static float angle;

glPushMatrix();
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -2.0f);

float fxMin, fxMax, fyMin, fyMax;
GL_GetViewRange(-2.0f, fxMin, fxMax, fyMin, fyMax);
r = min((fxMax-fxMin)/2, (fyMax-fyMin)/2) - 0.5;
glBegin(GL_POLYGON);
for (float f=0.0f; f<2*PI; f+=0.01f)
{
	glVertex3f(r*cos(f), r*sin(f), -0.0f);
}
glEnd();
glPopMatrix();

angle -= 0.05f;

}

What rotating an circle across it’s diameter mean? There are a whole bunch of axes you can rotate around. What are you trying to do?

Sorry for my poor english, i want to rotate a circle on its diameter whose direction is the same as the Y axis.

can anybody help me? thanks a lot!

Hi there,

I use the following code, but it also cannt work.

#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 480

glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, WINDOW_WIDTH, 0.0, WINDOW_HEIGHT, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

void DrawRect()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

static float angle;

glTranslatef(0.0f, 0.0f, -2.0f);
glRotatef(angle, 0.0f, 1.0f, 0.0f);

glBegin(GL_QUADS);
glVertex3f(WINDOW_WIDTH-250, WINDOW_HEIGHT-100, 0.0f);
glVertex3f(251, WINDOW_HEIGHT-100, 0.0f);
glVertex3f(251, 100, 0.0f);
glVertex3f(WINDOW_WIDTH-250, 100, 0.0f);
glEnd();

angle -= 0.05f;

}

thanks!