Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <glut.h>
  3. using namespace std;
  4.  
  5. float Red[3] = {1.0,0.0,0.0};
  6. float RedD[3] = {0.8, 0.0, 0.0};
  7.  
  8. float Blue[3] = {0.0, 0.0, 1.0};
  9. float BlueD[3] = {0.0, 0.0, 0.8};
  10.  
  11. float White[3] = {0.9, 0.9,0.9};
  12. float WhiteD[3] = {0.7, 0.7, 0.7};
  13.  
  14. float angle = 1.0;
  15. float angle2 = 1.0;
  16. float angle3 = 1.0;
  17.  
  18. void gameScene()
  19. {
  20. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  21.  
  22. glPushMatrix();
  23. //red Sphere
  24. glMaterialfv(GL_FRONT, GL_DIFFUSE, RedD);
  25. glMaterialfv(GL_FRONT, GL_AMBIENT, Red);
  26.  
  27. glScalef(1, 1, 1);
  28. glutSolidSphere(.8, 35, 8);
  29. glPopMatrix();
  30.  
  31. //white torus/axis1
  32. glPushMatrix();
  33. glMaterialfv(GL_FRONT, GL_DIFFUSE, WhiteD);
  34. glMaterialfv(GL_FRONT, GL_AMBIENT, White);
  35. glScalef(1, 1, 1);
  36. glRotatef(80, 0, 1, 0);
  37. glRotatef(-30, 1, 0, 0);
  38. glutSolidTorus(.2, 8, 10, 40);
  39. glPopMatrix();
  40.  
  41. //white torus/axis2
  42. glPushMatrix();
  43. glScalef(1, 1, 1);
  44. glRotatef(-80, 0, 1, 0);
  45. glRotatef(-30, 1, 0, 0);
  46. glutSolidTorus(.2, 8, 10, 40);
  47. glPopMatrix();
  48.  
  49. //white torus/axis3
  50. glPushMatrix();
  51. glScalef(1, 1, 1);
  52. glRotatef(90, 1, 0, 0);
  53. glRotatef(10, 1, 0, 0);
  54. glutSolidTorus(.2, 8, 10, 40);
  55. glPopMatrix();
  56.  
  57. //Blue balls
  58. glPushMatrix();
  59. glMaterialfv(GL_FRONT, GL_DIFFUSE, BlueD);
  60. glMaterialfv(GL_FRONT, GL_AMBIENT, Blue);
  61. glScalef(1,1,1);
  62. glRotatef(10, 1, 0, 0);
  63. glRotatef(angle, 0, 1, 0);
  64. glTranslatef(8, 0, 0);
  65. glutSolidSphere(.5, 35, 8);
  66. glPopMatrix();
  67.  
  68. glPushMatrix();
  69. glScalef(1,1,1);
  70. glRotatef(30, 0, 0, 1);
  71. glRotatef(-9,0,1,0);
  72. glRotatef(angle2, 1, 0, 0);
  73. glTranslatef(0, 8, 0);
  74. glutSolidSphere(.5, 35, 8);
  75. glPopMatrix();
  76.  
  77. glPushMatrix();
  78. glScalef(1,1,1);
  79. glRotatef(-30, 0, 0, 1);
  80. glRotatef(9,0,1,0);
  81. glRotatef(angle3, 1, 0, 0);
  82. glTranslatef(0, 8, 0);
  83. glutSolidSphere(.5, 35, 8);
  84. glPopMatrix();
  85.  
  86.  
  87.  
  88. angle += 1.1;
  89. angle2 += 1.3;
  90. angle3 += 1.8;
  91. //glTranslatef(0.0, 0.0, 0.10);
  92. //glRotatef(30,1.0, 0.0, 0.0);
  93. //glPushMatrix();
  94. //glutSolidCube(3);
  95. //glutSolidSphere(3, 6, 3);
  96.  
  97. //glutSolidTeapot(3);
  98. //glPopMatrix();
  99.  
  100.  
  101. glutSwapBuffers();
  102. }
  103.  
  104. void camera(int w, int h)
  105. {
  106. float ratio = 1.0 * w / h;
  107. glMatrixMode(GL_PROJECTION);
  108. glLoadIdentity();
  109. glViewport(0,0,w,h);
  110. gluPerspective(30.0, ratio, 1, 1000);
  111. glMatrixMode(GL_MODELVIEW);
  112. glLoadIdentity();
  113.  
  114. gluLookAt(
  115. 0.0, 0.0, 50.0, //camera position
  116. 0.0, 0.0, 0.0, //where camera is looking
  117. 0.0, 1.0, 0.0 // direction of up
  118. );
  119. }
  120.  
  121. void Keys(unsigned char key, int x, int y)
  122. {
  123. switch(key)
  124. {
  125. case 'w':
  126. break;
  127. case 'a':
  128. break;
  129. case 's':
  130. break;
  131. case 'd':
  132. break;
  133. }
  134.  
  135. }
  136.  
  137. void main(int argc, char **argv)
  138. {
  139. /*open gl setup*/
  140.  
  141. glutInit (&argc, argv);
  142. glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  143.  
  144. /*setup drawing window*/
  145. glutInitWindowPosition (0,0);
  146. glutInitWindowSize (500, 500);
  147. glutCreateWindow ("Hello OpenGL");
  148. glutReshapeFunc(camera);
  149. glutDisplayFunc(gameScene);
  150. glutKeyboardFunc(Keys);
  151.  
  152. //*Let there be light!*/
  153. glEnable (GL_LIGHT0);
  154. glEnable (GL_LIGHTING);
  155. //glEnable (GL_COLOR_MATERIAL);
  156.  
  157. //*Let there be depth!*/
  158. glEnable (GL_DEPTH_TEST);
  159.  
  160. /*start option*/
  161. glutMainLoop();
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement