Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <glut.h>
- using namespace std;
- float Red[3] = {1.0,0.0,0.0};
- float RedD[3] = {0.8, 0.0, 0.0};
- float Blue[3] = {0.0, 0.0, 1.0};
- float BlueD[3] = {0.0, 0.0, 0.8};
- float White[3] = {0.9, 0.9,0.9};
- float WhiteD[3] = {0.7, 0.7, 0.7};
- float angle = 1.0;
- float angle2 = 1.0;
- float angle3 = 1.0;
- void gameScene()
- {
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- //red Sphere
- glMaterialfv(GL_FRONT, GL_DIFFUSE, RedD);
- glMaterialfv(GL_FRONT, GL_AMBIENT, Red);
- glScalef(1, 1, 1);
- glutSolidSphere(.8, 35, 8);
- glPopMatrix();
- //white torus/axis1
- glPushMatrix();
- glMaterialfv(GL_FRONT, GL_DIFFUSE, WhiteD);
- glMaterialfv(GL_FRONT, GL_AMBIENT, White);
- glScalef(1, 1, 1);
- glRotatef(80, 0, 1, 0);
- glRotatef(-30, 1, 0, 0);
- glutSolidTorus(.2, 8, 10, 40);
- glPopMatrix();
- //white torus/axis2
- glPushMatrix();
- glScalef(1, 1, 1);
- glRotatef(-80, 0, 1, 0);
- glRotatef(-30, 1, 0, 0);
- glutSolidTorus(.2, 8, 10, 40);
- glPopMatrix();
- //white torus/axis3
- glPushMatrix();
- glScalef(1, 1, 1);
- glRotatef(90, 1, 0, 0);
- glRotatef(10, 1, 0, 0);
- glutSolidTorus(.2, 8, 10, 40);
- glPopMatrix();
- //Blue balls
- glPushMatrix();
- glMaterialfv(GL_FRONT, GL_DIFFUSE, BlueD);
- glMaterialfv(GL_FRONT, GL_AMBIENT, Blue);
- glScalef(1,1,1);
- glRotatef(10, 1, 0, 0);
- glRotatef(angle, 0, 1, 0);
- glTranslatef(8, 0, 0);
- glutSolidSphere(.5, 35, 8);
- glPopMatrix();
- glPushMatrix();
- glScalef(1,1,1);
- glRotatef(30, 0, 0, 1);
- glRotatef(-9,0,1,0);
- glRotatef(angle2, 1, 0, 0);
- glTranslatef(0, 8, 0);
- glutSolidSphere(.5, 35, 8);
- glPopMatrix();
- glPushMatrix();
- glScalef(1,1,1);
- glRotatef(-30, 0, 0, 1);
- glRotatef(9,0,1,0);
- glRotatef(angle3, 1, 0, 0);
- glTranslatef(0, 8, 0);
- glutSolidSphere(.5, 35, 8);
- glPopMatrix();
- angle += 1.1;
- angle2 += 1.3;
- angle3 += 1.8;
- //glTranslatef(0.0, 0.0, 0.10);
- //glRotatef(30,1.0, 0.0, 0.0);
- //glPushMatrix();
- //glutSolidCube(3);
- //glutSolidSphere(3, 6, 3);
- //glutSolidTeapot(3);
- //glPopMatrix();
- glutSwapBuffers();
- }
- void camera(int w, int h)
- {
- float ratio = 1.0 * w / h;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glViewport(0,0,w,h);
- gluPerspective(30.0, ratio, 1, 1000);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(
- 0.0, 0.0, 50.0, //camera position
- 0.0, 0.0, 0.0, //where camera is looking
- 0.0, 1.0, 0.0 // direction of up
- );
- }
- void Keys(unsigned char key, int x, int y)
- {
- switch(key)
- {
- case 'w':
- break;
- case 'a':
- break;
- case 's':
- break;
- case 'd':
- break;
- }
- }
- void main(int argc, char **argv)
- {
- /*open gl setup*/
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- /*setup drawing window*/
- glutInitWindowPosition (0,0);
- glutInitWindowSize (500, 500);
- glutCreateWindow ("Hello OpenGL");
- glutReshapeFunc(camera);
- glutDisplayFunc(gameScene);
- glutKeyboardFunc(Keys);
- //*Let there be light!*/
- glEnable (GL_LIGHT0);
- glEnable (GL_LIGHTING);
- //glEnable (GL_COLOR_MATERIAL);
- //*Let there be depth!*/
- glEnable (GL_DEPTH_TEST);
- /*start option*/
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement