1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <glut.h>
#include <cmath>
#include <time.h>
#include <string>
using namespace std;
int genrandom();
GLfloat tplayer;
GLfloat tobject;
double angle = 0;
double angleadd = 0.2;
int c = 0;
int d = 0;
int random;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 0.5, 1);
glColor3f (0, 0.2, 1);
glutWireSphere(5, 10, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(10, 10, 0);
glRotatef(angle, 0, 0.5, 1);
glColor3f (1, 0, 0);
glutWireCube(3);
glPopMatrix();
glutSwapBuffers();
}
int genrandom(){
srand ( time(NULL) );
random = rand() % 95 + -95;
return random;
}
void KeySet() { DWORD old = 0;
SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &old, 0);
SystemParametersInfo(SPI_SETKEYBOARDDELAY,0, &old, 0);
}
void keyboard(unsigned char key, int x, int y)
{
KeySet();
if(key == 27) exit (0);
else if( (key == 119) && (95 > d) ){
glTranslatef(0, 1, 0);
d = d + 1;
}
else if( (key == 115) && (d > -95) ){
glTranslatef(0, -1, 0);
d = d - 1;
}
else if( (key == 97) && (c > -95) ){
glTranslatef(-1, 0, 0);
c = c - 1;
}
else if( (key == 100) && (95 > c) ){
glTranslatef(1, 0, 0);
c = c + 1;
}
}
void idle()
{
angle += angleadd;
glutPostRedisplay();
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (800, 800);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Space Journey");
glClearColor (0, 0, 0, 0);
glColor3f (1, 1, 1);
glEnable (GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
glOrtho(-100, 100, -100, 100, -100, 100);
glutDisplayFunc (display);
glutKeyboardFunc (keyboard);
glutIdleFunc (idle);
glutFullScreen ();
glutMainLoop ();
return 0;
}
|