Advertisement
Gireada

Sistemul Solar cu Umbre

Apr 17th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include <glos.h>
  2. #include <gl/gl.h>
  3. #include <gl/glu.h>
  4. #include <GL/glut.h>
  5. #include <gl/glaux.h>
  6. #include <conio.h>
  7.  
  8.  
  9. void CALLBACK display(void);
  10. void CALLBACK myReshape(GLsizei w, GLsizei h);
  11.  
  12. double v;
  13.  
  14. void CALLBACK display(void)
  15. {
  16.  
  17. GLfloat materialEmission[] = { 0.1f,0.1f,0.1f, 0.8f };
  18. GLfloat materialColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  19. GLfloat materialSpecular[] = { 0.1f,0.0f,0.1f,1.0f };
  20. GLfloat shininess = 150.0f;
  21.  
  22. GLfloat no_materialEmission[] = { 0.0f,0.0f,0.0f, 1.0f };
  23. GLfloat no_materialColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
  24. GLfloat no_materialSpecular[] = { 0.0f,0.0f,0.0f,1.0f };
  25. GLfloat no_shininess = 0.0f;
  26.  
  27. GLfloat ambient[] = { 0.8f, 0.8f, 0.8f, 1.0f };
  28. GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  29. GLfloat specular[] = { 0.8f, 0.5f, 0.5f, 1.0f };
  30. GLfloat position[] = { 0.0f, 200.0f, 200.0f, 0.0f };
  31.  
  32. glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
  33. glEnable(GL_COLOR_MATERIAL);
  34. glEnable(GL_LIGHT0);
  35. glEnable(GL_LIGHTING);
  36. glEnable(GL_AUTO_NORMAL);
  37. glEnable(GL_NORMALIZE);
  38. glShadeModel(GL_FLAT);
  39. glClearColor(0.0, 0.0, 0.0, 0.0);
  40. //pentru a fi desenat sistemul astfel încât obiectele din spate să fie acoperite de cele din faţă se va folosi următoarele doua functii
  41. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  42. glEnable(GL_DEPTH_TEST);
  43. glColor3f(1.0, 1.0, 1.0);
  44. glPushMatrix();
  45. /* Soare */
  46. glColor3d(1.0, 1.0, 0.0);
  47. glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
  48. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColor);
  49. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
  50. glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, materialEmission);
  51. glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); //The shininess parameter
  52. auxSolidSphere(0.8);
  53.  
  54.  
  55. /* Pamantul */
  56. glRotatef((GLfloat)v, 0.0, 1.0, 0.0);
  57. glTranslatef(2.2, 0.0, 0.0);
  58. glColor3d(0.0, 0.0, 1.0);
  59. glMaterialfv(GL_FRONT, GL_EMISSION, no_materialEmission);
  60. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, no_materialColor);
  61. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, no_materialSpecular);
  62. glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_materialEmission);
  63. glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, no_shininess); //The shininess parameter
  64. auxSolidSphere(0.3);
  65.  
  66. /* Luna */
  67. glRotatef((GLfloat)v * 2, 0.0, 1.0, 0.0);
  68. glTranslatef(0.8, 0.0, 0.0);
  69. glMaterialfv(GL_FRONT, GL_EMISSION, no_materialEmission);
  70. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, no_materialColor);
  71. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, no_materialSpecular);
  72. glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_materialEmission);
  73. glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, no_shininess); //The shininess parameter
  74. glColor3d(0.5, 0.5, 0.5);
  75. auxSolidSphere(0.15);
  76. glPopMatrix();
  77. v++;
  78. glFlush();
  79. Sleep(30);
  80. }
  81. void CALLBACK myReshape(GLsizei w, GLsizei h)
  82. {
  83. if (!h) return;
  84. glViewport(0, 0, w, h);
  85. glMatrixMode(GL_PROJECTION);
  86. glLoadIdentity();
  87. gluPerspective(40.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
  88. glMatrixMode(GL_MODELVIEW);
  89. glLoadIdentity();
  90. glTranslatef(0.0, 0.0, -5.0);
  91. }
  92.  
  93. void main()
  94. {
  95. auxInitDisplayMode(AUX_SINGLE | AUX_RGB);
  96. auxInitPosition(0, 0, 800, 600);
  97. auxInitWindow("Sistem solar");
  98. auxIdleFunc(display);
  99. auxReshapeFunc(myReshape);
  100. auxMainLoop(display);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement