Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. #define GLUT_DISABLE_ATEXIT_HACK
  2. #include <windows.h>
  3. #ifdef __APPLE__
  4. #include <GLUT/glut.h>
  5. #else
  6. #include <GL/glut.h>
  7. #endif
  8.  
  9. #include <stdlib.h>
  10.  
  11. static int slices = 16;
  12. static int stacks = 16;
  13. float obrot_x;
  14. /* GLUT callback Handlers */
  15. int angle = 1;
  16. static void Timer(int value){
  17.     obrot_x += 1.0;
  18.     glutPostRedisplay();
  19.     // 100 milliseconds
  20.     glutTimerFunc(10, Timer, 0);
  21. }
  22. static void resize(int width, int height)
  23. {
  24.     const float ar = (float) width / (float) height;
  25.  
  26.     glViewport(0, 0, width, height);
  27.     glMatrixMode(GL_PROJECTION);
  28.     glLoadIdentity();
  29.   //  glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
  30.  
  31.     gluPerspective(60,ar,2.0,100.0);
  32.  
  33. }
  34. float posx = 4;
  35. float posz = 5;
  36. float d = 0;
  37. float f= 60;
  38. float g1 = 90;
  39. float g2 = 90;
  40.  
  41. float obrot_y;
  42. float xx;
  43. float yx;
  44. float zx;
  45.  
  46. float xy;
  47. float yy;
  48. float zy;
  49.  
  50. static void display(void)
  51. {
  52.     const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
  53.     const double b = t*g1;
  54.     const double a = t*g2;
  55.  
  56. GLfloat fPozycja_swiatla[4] = {100.0f, 100.0f, 50.0f, 1.0f};
  57. GLfloat fSlabe_swiatlo[] = {0.25f, 0.25f, 0.25f, 1.0f};
  58. GLfloat fMocne_swiatlo[] = {1.0f, 1.0f, 1.0f, 1.0f};
  59.  
  60. glLightfv (GL_LIGHT0, GL_AMBIENT, fSlabe_swiatlo); // światło otoczenia
  61. glLightfv (GL_LIGHT0, GL_DIFFUSE, fMocne_swiatlo); // światło rozproszenia
  62. glLightfv (GL_LIGHT0, GL_SPECULAR, fMocne_swiatlo); // światło odbite
  63. glLightfv (GL_LIGHT0, GL_POSITION, fPozycja_swiatla); // pozycja światła
  64.  
  65.  glMatrixMode(GL_MODELVIEW);
  66.     glLoadIdentity() ;
  67.     gluLookAt(
  68.         posx, 0, posz,
  69.         0,0,-1,
  70.         0,1,0);
  71.      //   gluRotated
  72.    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  73. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  74. // obrót wokół osi y dla klawiszy l i r
  75.  
  76. //dwie kule
  77.  
  78.     glPushMatrix();
  79.         glTranslated(1.0,1.0,-2);
  80.         glRotated(-60,-1,-0,-0);
  81.         glRotated(0,0,0,1);
  82.         glutSolidSphere(1,slices,stacks);
  83.     glPopMatrix();
  84.  
  85.  
  86.  
  87.     glPushMatrix();
  88.     glRotatef(obrot_x, 0.0f, 1.0f, 0.0f);
  89. glRotatef(obrot_y, xy, yy, zy);
  90.         glTranslated(-1.0,1.0,-3);
  91.         glRotated(-60,-1,-0,-0);
  92.         glRotated(0,0,0,1);
  93.         glutSolidSphere(1,slices,stacks);
  94.     glPopMatrix();
  95.  
  96.     glutSwapBuffers();
  97. }
  98.  
  99. static void key(unsigned char key, int x, int y)
  100. {
  101.     switch (key)
  102.     {
  103.         case 27 :
  104.         case 'q':
  105.             exit(0);
  106.             break;
  107.  
  108.         case '+':
  109.             slices++;
  110.             stacks++;
  111.             break;
  112.  
  113.         case '-':
  114.             if (slices>3 && stacks>3)
  115.             {
  116.                 slices--;
  117.                 stacks--;
  118.             }
  119.  
  120.         case'r':
  121.  
  122.             xx=0;
  123.             yx=1;
  124.             zx=0;
  125.             obrot_x=obrot_x-5;
  126.             break;
  127.  
  128.             case'u':
  129.  
  130.             xy=1;
  131.             yy=0;
  132.             zy=0;
  133.             obrot_y=obrot_y+5;
  134.             break;
  135.  
  136.     }
  137.  
  138.     glutPostRedisplay();
  139. }
  140.  
  141. static void idle(void)
  142. {
  143.     glutPostRedisplay();
  144. }
  145. /*
  146. const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
  147. const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
  148. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  149. const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
  150.  
  151. const GLfloat mat_ambient[]    = { 0.1f, 0.1f, 0.1f, 1.0f };
  152. const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
  153. const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
  154. const GLfloat high_shininess[] = { 100.0f };
  155.  
  156. /* Program entry point */
  157.  
  158. int main(int argc, char *argv[])
  159. {
  160.      glClearColor(1.0, 1.0, 1.0, 1.0);
  161.     glutInit(&argc, argv);
  162.     glutInitWindowSize(640,480);
  163.     glutInitWindowPosition(10,10);
  164.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  165.  
  166.     glutCreateWindow("Uklad sloneczny");
  167.  
  168.     glutReshapeFunc(resize);
  169.     glutDisplayFunc(display);
  170.     glutKeyboardFunc(key);
  171.     glutIdleFunc(idle);
  172. glClear(GL_COLOR_BUFFER_BIT);
  173.    glClearColor(2.0, 2.0, 2.0, 1.0);
  174.     glEnable(GL_CULL_FACE);
  175.     glCullFace(GL_BACK);
  176.  
  177.     glEnable(GL_DEPTH_TEST);
  178.     glDepthFunc(GL_LESS);
  179.  
  180.     glEnable(GL_LIGHT0);
  181.    /* glEnable(GL_NORMALIZE);
  182.     glEnable(GL_COLOR_MATERIAL);*/
  183.     glEnable(GL_LIGHTING);
  184. /*
  185.     glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
  186.     glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
  187.     glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  188.     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  189.  
  190.     glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
  191.     glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
  192.     glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
  193.     glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  194. */ Timer(0);
  195.     glutMainLoop();
  196.  
  197.     return EXIT_SUCCESS;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement