Hi,
I wrote a OpenGL prorgam to rotate 1 line around a fixed line. Every time the program is idle, it rotates 2 degrees. The rotation of the full 360 degrees takes up to 5 seconds. Can someone see how to rotate this line faster?
#include <GL/glut.h>
#include <math.h>
#include <unistd.h>
#define SCREEN_HORIZONTAL 800
#define SCREEN_VERTICAL 600
#define DEG_TO_RAD .017453
double theta=0;
void keyHandler(unsigned char key, int x, int y)
{
if( key == 'q' || key == 'Q')
exit(0);
}
void idleHandler()
{
theta += 2;
if (theta >= 360) theta -= 360;
glutPostRedisplay();
}
void reshapeHandler(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1,1,-1,1,1,50);
glMatrixMode(GL_MODELVIEW);
}
void displayHandler()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslated(0,-2,-5);
glBegin(GL_LINES);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glColor3f(0,0,1);
glVertex3f(0, 5, 0);
glEnd();
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glColor3f(1,0,0);
glVertex3f(cos(DEG_TO_RAD*theta), 5, sin(DEG_TO_RAD*theta));
glEnd();
glutSwapBuffers();
}
void init()
{
glutFullScreen();
glClearColor(0,0,0,0);
}
int main(int argc, char** argv)
{
// glut init
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(SCREEN_HORIZONTAL, SCREEN_VERTICAL);
glutInitWindowPosition(0,0);
glutCreateWindow("Rotate Program");
// handler functions
glutDisplayFunc(displayHandler);
glutKeyboardFunc(keyHandler);
glutReshapeFunc(reshapeHandler);
glutIdleFunc(idleHandler);
init();
// start program
glutMainLoop();
}