- #include <windows.h>
- #include <glut.h>
- #define WHITE 1.0, 1.0, 1.0
- #define BLACK 0.0, 0.0, 0.0
- #define GREEN 0.0, 1.0, 0.0
- #define BLUE 0.0, 0.0, 1.0
- #define RED 1.0, 0.0, 0.0
- #define YELLOW 1.0, 1.0, 0.15
- void init(void);
- void display(void);
- void keyboard(unsigned char key);
- void draw(void);
- double window_size_x = 1000.0;
- double window_size_y = 1000.0;
- double window_size_z = 1000.0;
- float zoom = 2.0, radius, schritt_x = 1.0, schritt_y = 1.0, schritt_z = 1.0, geschwindigkeit = 0.5, x = 5.0, y = 10.0, z = 15.0,
- durchmesser = 50.0,
- breite = 1000.0,
- hoehe = 1500.0,
- tiefe = 2000.0;
- int main(int argc, char** argv)
- {
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize (window_size_x,window_size_y);
- glutInitWindowPosition (700.0,300.0);
- glutCreateWindow ("Geschicklichkeitsspiel von Nebauer Gunter");
- init();
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
- void init(void)
- {
- GLfloat pos [] = {1.0, 1.0, 1.0, 0.0};
- glClearColor(BLUE, 0.0);
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_DEPTH_TEST);
- glShadeModel(GL_FLAT);
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- draw();
- glPopMatrix();
- glutSwapBuffers();
- }
- void keyboard(unsigned char key)
- {
- switch(key)
- {
- case 'a':
- glRotatef(-5.0, 0.0, 1.0, 0.0);
- break;
- case 'd':
- glRotatef(5.0, 0.0, 1.0, 0.0);
- break;
- case 's':
- glRotatef(-5.0, 1.0, 0.0, 0.0);
- break;
- case 'w':
- glRotatef(5.0, 1.0, 0.0, 0.0);
- break;
- case '+':
- zoom = zoom + 0.1;
- break;
- case '-':
- zoom = zoom - 0.1;
- break;
- case 'q':
- exit(0);
- break;
- default:
- break;
- }
- glutPostRedisplay();
- }
- void draw()
- {
- glScalef(zoom/window_size_x, zoom/window_size_y, zoom/window_size_z);
- glColor3f(RED);
- glBegin(GL_LINE_LOOP);
- glVertex3f(breite , hoehe , tiefe );
- glVertex3f(breite , -hoehe , tiefe );
- glVertex3f(-breite , -hoehe , tiefe );
- glVertex3f(-breite , hoehe , tiefe );
- glEnd();
- glBegin(GL_LINE_LOOP);
- glVertex3f(breite , hoehe , -tiefe );
- glVertex3f(breite , -hoehe , -tiefe);
- glVertex3f(-breite , -hoehe , -tiefe;
- glVertex3f(-breite , hoehe , -tiefe);
- glEnd();
- glBegin(GL_LINES);
- glVertex3f(breite , hoehe, -tiefe);
- glVertex3f(breite, hoehe , tiefe );
- glVertex3f(-breite, hoehe, -tiefe);
- glVertex3f(-breite , hoehe , tiefe);
- glEnd();
- glBegin(GL_LINES);
- glVertex3f(breite, -hoehe, -tiefe);
- glVertex3f(breite , -hoehe, tiefe);
- glVertex3f(-breite, -hoehe, -tiefe);
- glVertex3f(-breite , -hoehe, tiefe);
- glEnd();
- x += geschwindigkeit * schritt_x;
- y += geschwindigkeit * schritt_y;
- z += geschwindigkeit * schritt_z;
- glTranslatef(x, y, z);
- radius = durchmesser / 2.0;
- glutSolidSphere(radius, 50.0, 50.0);
- if (x == breite- radius)
- schritt_x = -2.0;
- if (x == -breite+ radius)
- schritt_x = 2.0;
- if (y == hoehe- radius)
- schritt_y = -2.0;
- if (y == -hoehe+ radius)
- schritt_y = 2.0;
- if (z == tiefe- radius)
- schritt_z = -2.0;
- if (z == -tiefe+ radius)
- schritt_z = 2.0;
- x += geschwindigkeit * schritt_x;
- y += geschwindigkeit * schritt_y;
- z += geschwindigkeit * schritt_z;
- glTranslatef(x, y, z);
- radius = durchmesser / 4.0;
- glutSolidSphere(radius, 50.0, 50.0);
- if (x == breite- radius)
- schritt_x = -1.0;
- if (x == -breite + radius)
- schritt_x = 1.0;
- if (y == hoehe - radius)
- schritt_y = -1.0;
- if (y == -hoehe + radius)
- schritt_y = 1.0;
- if (z == tiefe - radius)
- schritt_z = -1.0;
- if (z == -tiefe + radius)
- schritt_z = 1.0;
- glutPostRedisplay();
- }