PDA

View Full Version : anyone help me for rotate this circle



hesam
07-05-2011, 05:05 AM
hi..
below i try to draw a simple flag... and now i want to raotate this x OR y axis.. how can i do it??
this is my code:


#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>

#define PI 3.14159265

int color[5][3]={{0,0,1}, {0,0,0},{1,0,0}, {1,1,0},{0,1,0}};
float center[5][2]={{-30.0,10.0},{-8.0,10.0},{14.0,10.0},{-19.0,-2.0},{4.0,-2.0}};

static void circle(float radius)
{
int i;
glBegin(GL_LINE_LOOP);
for (i = 0; i < 90; i++){
glVertex2f(radius*cos((2*PI*i)/90),radius*sin((2*PI*i)/90));
glVertex2f(radius*cos((2*PI*(i+1))/90),radius*sin((2*PI*(i+1))/90));
}
glEnd();
}
void display (void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
for(int i = 0 ; i <5; i++)
{
glColor3f (color[i][0],color[i][1],color[i][2]);
glPushMatrix();
glTranslatef( center[i][0], center[i][1], -100.0 );

circle(10);
glPopMatrix();
}
glutSwapBuffers();
}

void init()
{
glPointSize(3);
glShadeModel (GL_FLAT);
glMatrixMode(GL_PROJECTION);
gluPerspective(45,1.0,10.0,200.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0,1.0,1.0,0.0);
}

int main(int argc, char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(110*3, 110*3);
glutCreateWindow("simple rotate");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}

potatosoftware
07-06-2011, 05:50 AM
There is a glRotate function or something. I think it accepts three params pertaining to the 3 angles over the 3 axis.

Since you want to rotate it over one axis, all you have to do is to zero two params and pass one param value that you would update (increment) at each call.