PDA

View Full Version : how to do continous rotation?



coda
12-07-2003, 08:32 PM
I want to rotate my object continuously when user click my rotate button. i tried:

void CDialog::OnRotate()
{
GLfloat rquad;
glRotatef(rquad,1.0f,1.0f,1.0f);
RenderScene();//my drawing function

rquad-=20.0f;

}
but it is not working so where is the problem?

ZbuffeR
12-07-2003, 11:07 PM
static GLfloat rquad=0.0f;
rquad-=20.0f;
glRotatef(rquad,1.0f,1.0f,1.0f);
RenderScene();//my drawing function


Well, I would do that in plain C, but I'm not too familiar with C++.

Is that really what you want, glRotatef(rquad,1.0f,1.0f,1.0f); ??
It is often simpler to rotate about one of the x y or z axis, instead of this strange vector. (glRotatef(rquad,0.0f,0.0f,1.0f); )

You can also do something like :




GLfloat rquad=-20.0f;
glRotatef(rquad,0.0f,0.0f,1.0f);
glPushMatrix();
RenderScene();//my drawing function
glPopMatrix();


[This message has been edited by ZbuffeR (edited 12-08-2003).]

[This message has been edited by ZbuffeR (edited 12-08-2003).]

coda
12-08-2003, 12:13 AM
well, it still back to same problem, coz it only rotate each time by additional 20 deg whenever i click button continuosly. What i want is only on 1 click of button then the object will start rotating without stopping.

cwc36
12-08-2003, 01:16 AM
Hi,

Your object did not rotated automatically, because the rquad increase once only.

The steps that you need to do....
1)You should create a flag for mouse click.
2)rquad should declare as global variable.
3)rquad need to put in timer func.

The code :

GLfloat rquad;
bool CLICK = false;

void CDialog::OnRotate()
{
glRotatef(rquad,1.0f,1.0f,1.0f);
RenderScene();//my drawing function
}
void mouseclick()
{
CLICK = true;
}
int TimerFunc()
{
if(CLICK)
{
rquad-=20.0f;
}
SendMessage(WM_PAINT);
}

Hope it can help.

coda
12-08-2003, 04:01 AM
thanx! helps a lot http://www.opengl.org/discussion_boards/ubb/smile.gif