#include #include #include // Define a constant for the value of PI #define GL_PI 3.1415f static float orbitDegreeZ = 0.0f; static float orbitDegreeX = 0.0f; static float zoom = 1.0f; static float alfa = 0.0f; GLint i = 0; void rotor() { glPushMatrix(); glTranslatef(0.0,0.0,25.0); gluCylinder(gluNewQuadric(), 2.0,2.0,5,60,10); glTranslatef(0.0,0.0,5); glRotatef(alfa, 0.0,0.0,1.0); glColor3f(0.5f,0.5f,0.5f); glBegin(GL_POLYGON); glVertex3i(0,0,0); glVertex3i(-50,0,0); glVertex3i(-50,5,0); glVertex3i(0,5,0); glEnd(); glBegin(GL_POLYGON); glVertex3i(0,0,0); glVertex3i(50,0,0); glVertex3i(50,-5,0); glVertex3i(0,-5,0); glEnd(); glPopMatrix(); } void kormany() { glPushMatrix(); glTranslatef(70.0,0.0,30); glRotatef(90,-1.0,0.0,0.0); glScalef(0.2,0.2,0.2); rotor(); glPopMatrix(); } void helicopter() { // orr glColor3f(0.0f,0.3f,1.0f); glBegin(GL_POLYGON); glVertex3i(-35,-5,15); glVertex3i(-35,5,15); glVertex3i(-15,10,25); glVertex3i(-15,-10,25); glEnd(); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_POLYGON); // also glVertex3i(-35,-5,15); glVertex3i(-35,5,15); glVertex3i(-25,10,5); glVertex3i(-25,-10,5); glEnd(); glBegin(GL_POLYGON); // jobb also glVertex3i(-35,5,15); glVertex3i(-25,10,5); glVertex3i(-25,15,15); glEnd(); glBegin(GL_POLYGON); // jobb felso glVertex3i(-35,5,15); glVertex3i(-25,15,15); glVertex3i(-15,10,25); glEnd(); glBegin(GL_POLYGON); // bal also glVertex3i(-35,-5,15); glVertex3i(-25,-10,5); glVertex3i(-25,-15,15); glEnd(); glBegin(GL_POLYGON); // bal felso glVertex3i(-35,-5,15); glVertex3i(-15,-10,25); glVertex3i(-25,-15,15); glEnd(); //torzs glBegin(GL_POLYGON); // teteje glVertex3i(-15,10,25); glVertex3i(15,10,25); glVertex3i(15,-10,25); glVertex3i(-15,-10,25); glEnd(); glBegin(GL_POLYGON); // alja glVertex3i(-25,10,5); glVertex3i(15,10,5); glVertex3i(15,-10,5); glVertex3i(-25,-10,5); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); // jobb felso glVertex3i(-25,15,15); glVertex3i(15,15,15); glVertex3i(15,10,25); glVertex3i(-15,10,25); glEnd(); glBegin(GL_POLYGON); // bal felso glVertex3i(-25,-15,15); glVertex3i(15,-15,15); glVertex3i(15,-10,25); glVertex3i(-15,-10,25); glEnd(); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_POLYGON); // jobb also glVertex3i(-25,15,15); glVertex3i(15,15,15); glVertex3i(15,10,5); glVertex3i(-25,10,5); glEnd(); glBegin(GL_POLYGON); // bal also glVertex3i(-25,-15,15); glVertex3i(15,-15,15); glVertex3i(15,-10,5); glVertex3i(-25,-10,5); glEnd(); //farokto glBegin(GL_POLYGON); // teteje glVertex3i(15,10,25); glVertex3i(30,7,25); glVertex3i(30,-7,25); glVertex3i(15,-10,25); glEnd(); glBegin(GL_POLYGON); // alja glVertex3i(15,10,5); glVertex3i(30,7,20); glVertex3i(30,-7,20); glVertex3i(15,-10,5); glEnd(); glBegin(GL_POLYGON); // jobb felso glVertex3i(15,15,15); glVertex3i(30,7,20); glVertex3i(30,7,25); glVertex3i(15,10,25); glEnd(); glBegin(GL_POLYGON); // bal felso glVertex3i(15,-15,15); glVertex3i(30,-7,20); glVertex3i(30,-7,25); glVertex3i(15,-10,25); glEnd(); glBegin(GL_POLYGON); // jobb also glVertex3i(15,15,15); glVertex3i(30,7,20); glVertex3i(15,10,5); glEnd(); glBegin(GL_POLYGON); // bal also glVertex3i(15,-15,15); glVertex3i(30,-7,20); glVertex3i(15,-10,5); glEnd(); // farok glBegin(GL_POLYGON); // teteje glVertex3i(30,7,25); glVertex3i(70,2,25); glVertex3i(70,-2,25); glVertex3i(30,-7,25); glEnd(); glBegin(GL_POLYGON); // alja glVertex3i(30,7,20); glVertex3i(70,2,20); glVertex3i(70,-2,20); glVertex3i(30,-7,20); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); // jobb felso glVertex3i(30,7,20); glVertex3i(70,2,20); glVertex3i(70,2,25); glVertex3i(30,7,25); glEnd(); glBegin(GL_POLYGON); // jobb felso glVertex3i(30,-7,20); glVertex3i(70,-2,20); glVertex3i(70,-2,25); glVertex3i(30,-7,25); glEnd(); glColor3f(0.0f,1.0f,0.0f); glBegin(GL_POLYGON); // vege glVertex3i(70,-2,20); glVertex3i(70,2,20); glVertex3i(70,2,25); glVertex3i(70,-2,25); glEnd(); glBegin(GL_POLYGON); glVertex3i(70,2,25); glVertex3i(55,2,25); glVertex3i(70,0,35); glVertex3i(80,0,35); glEnd(); glBegin(GL_POLYGON); glVertex3i(70,-2,25); glVertex3i(55,-2,25); glVertex3i(70,0,35); glVertex3i(80,0,35); glEnd(); glBegin(GL_POLYGON); glVertex3i(55,2,25); glVertex3i(70,0,35); glVertex3i(55,-2,25); glEnd(); glBegin(GL_POLYGON); glVertex3i(70,2,25); glVertex3i(80,0,35); glVertex3i(70,-2,25); glEnd(); rotor(); kormany(); } // Called to draw scene void RenderScene(void) { int j = 0; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(-50.0 + orbitDegreeX, 1.0f, 0.0f, 0.0f); glRotatef(orbitDegreeZ, 0.0f,0.0f,1.0f); helicopter(); glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); } void Timer(int value) { //printf("Timer esemeny (%d)\n", value); alfa = alfa+5.0; if( alfa==360 ) alfa= 0; glutPostRedisplay(); glutTimerFunc(2, Timer, value + 1); } void Idle() { glutPostRedisplay(); } void ChangeSizeOrtho(int w, int h) { //GLfloat nRange = 25.0f; //GLfloat nRange = 30.0f; GLfloat nRange = 80.0f ; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void SpecialKeys(int key, int x, int y) { if (key == GLUT_KEY_UP ) { orbitDegreeX += 1.0f; } if (key == GLUT_KEY_DOWN ) { orbitDegreeX -= 1.0f; } if (key == GLUT_KEY_LEFT ) { orbitDegreeZ -= 1.0f; } if (key == GLUT_KEY_RIGHT) { orbitDegreeZ += 1.0f; } if ( orbitDegreeX > 80.0f ) orbitDegreeX = 80.0f; if ( orbitDegreeX < -50.0f ) orbitDegreeX = -50.0f; if (orbitDegreeZ <= 360.0f) orbitDegreeZ -= 360.0f; if (orbitDegreeZ < 0.0f) orbitDegreeZ = 360.0f - orbitDegreeZ; glutPostRedisplay(); } int main(int argc, char* argv[]) { // >> Inicializalas glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(300, 300); glutCreateWindow("GLUT Alap"); // << Inicializalas // >> Callback fuggvenyek glutReshapeFunc(ChangeSizeOrtho); // Parhuzamos vetites //glutReshapeFunc(ChangeSizePerspective); // Perspektiv vetites glutSpecialFunc(SpecialKeys); //glutKeyboardFunc(Keyboard); //glutKeyboardFunc(Keyboard); glutDisplayFunc(RenderScene); glutTimerFunc(2, Timer, 1); // 1 mp mulva meghivodik a Timer() fuggveny glutIdleFunc(Idle); // Idle(), ha nem tortenik semmi // << Callback fuggvenyek SetupRC(); glutMainLoop(); return 0; }