Advertisement
Guest User

wersja ostateczna

a guest
Oct 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 KB | None | 0 0
  1. #include <windows.h>
  2. #define _USE_MATH_DEFINES
  3. #include <cmath>
  4. #include <iostream>
  5.  
  6. #include <gl/gl.h>
  7. #include <gl/glu.h>
  8. #include <gl/freeglut.h>
  9.  
  10. #include "glscene.h"
  11.  
  12. GLint glScene::winx_ = 0;
  13. GLint glScene::winy_ = 0;
  14.  
  15.  
  16.  
  17. glScene::glScene()
  18.     :
  19.     repaintRequest_(GL_FALSE)
  20. {
  21.     rot_[0] = rot_[1] = rot_[2] = 0.0f;
  22. }
  23.  
  24. glScene::~glScene()
  25. {
  26. }
  27.  
  28. void glScene::Resize()
  29. {
  30.     Resize(winx_, winy_);
  31. }
  32.  
  33. void glScene::Resize(int _w, int _h)
  34. {
  35.     winx_ = _w;
  36.     winy_ = _h;
  37.  
  38.     if (_h == 0)
  39.         _h = 1;
  40.     if (_w == 0)
  41.         _w = 1;
  42.  
  43.     //ustawienie viewportu
  44.     glViewport(0, 0, _w, _h);
  45.  
  46.     //macierze projekcji
  47.     glMatrixMode(GL_PROJECTION);
  48.     //ustaw aktualna macierz na I
  49.     glLoadIdentity();
  50.  
  51.     //ustaw uklad wspolrzednych
  52.     glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
  53.  
  54.     //macierze modelowania
  55.     glMatrixMode(GL_MODELVIEW);
  56.     //ustaw aktualna macierz na I
  57.     glLoadIdentity();
  58. }
  59.  
  60. void glScene::SetupRC()
  61. {
  62.     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  63. }
  64.  
  65. void glScene::CleanRC()
  66. {
  67. }
  68.  
  69. void sphere(GLdouble R, GLint row, GLint pol)
  70. {
  71. }
  72.  
  73.  
  74. void sfera(GLfloat promien, GLint rownolezniki, GLint poludniki)
  75. {
  76.     glPointSize(2.0);
  77.     GLdouble R = promien;
  78.     GLdouble x = 0.0f;
  79.     GLdouble y;
  80.     GLdouble z;
  81.     GLint row = rownolezniki;
  82.     GLint pol = poludniki;
  83.  
  84.  
  85.  
  86.     for (GLint j = 0; j < pol; j++) //południki
  87.     {
  88.         glBegin(GL_POINTS);
  89.  
  90.         for (GLfloat i = 0.0f; i <= 180.0f; i += (180.0f / row)) //równoleżniki
  91.         {
  92.             y = R*cos(i / 180.0f * M_PI);
  93.             z = R*sin(i / 180.0f * M_PI);
  94.             glVertex3f(x, y, z);
  95.  
  96.         }
  97.  
  98.         glEnd();
  99.  
  100.         glFlush();
  101.  
  102.         glRotatef(360.0f / pol, 0.0f, 1.0f, 0.0f); //obrót jednego południka dookoła osi y
  103.     }
  104. }
  105.  
  106.  
  107. void glScene::RenderScene()
  108. {
  109.  
  110.     //malujemy scene, mozna skasowac flage aby scena ciagle sie nie odmalowywala
  111.     repaintRequest_ = GL_FALSE;
  112.  
  113.     glClear(GL_COLOR_BUFFER_BIT);
  114.  
  115.     glColor3f(1.0f, 0.0f, 0.0f);
  116.  
  117.     glPushMatrix();
  118.     glRotatef(rot_[0], 1.0, 0.0, 0.0);
  119.     glRotatef(rot_[1], 0.0, 1.0, 0.0);
  120.     glRotatef(rot_[2], 0.0, 0.0, 1.0);
  121.  
  122.  
  123.     /*  glBegin(GL_POINTS);
  124.     //glVertex3f(-0.5f, 0.1f, 0.3f);
  125.     glVertex3f(-0.5f, 0.1f, -0.4f);
  126.     glVertex2f(0.0f, 0.0f);
  127.     glEnd();*/
  128.  
  129.     glBegin(GL_POINTS);
  130.     /*for (float i = 0.0f; i < 800.0f; i++) {
  131.     y = r * sinf(i*(M_PI/180.0f));
  132.     x = r * cosf(i*(M_PI/180.0f));
  133.     glVertex2f(x, y);
  134.     std::cout << i;
  135.     }
  136.     */
  137.  
  138.     sfera(0.70, 100, 100);
  139.  
  140.     glEnd();
  141.  
  142.     glPopMatrix();
  143.  
  144.     glFlush();
  145. }
  146.  
  147.  
  148. void glScene::KeyboardFunction(char _key, int, int)
  149. {
  150.     if (_key == 32)
  151.     {
  152.         rot_[0] = rot_[1] = rot_[2] = 0.0;
  153.         Resize(winx_, winy_);
  154.     }
  155.     repaintRequest_ = GL_TRUE;
  156. }
  157.  
  158.  
  159. void glScene::KeyboardFunction(int _key, int, int)
  160. {
  161.     if (_key == GLUT_KEY_RIGHT)
  162.         rot_[1] += 0.5;
  163.     else if (_key == GLUT_KEY_LEFT)
  164.         rot_[1] -= 0.5;
  165.     else if (_key == GLUT_KEY_UP)
  166.         rot_[0] += 0.5;
  167.     else if (_key == GLUT_KEY_DOWN)
  168.         rot_[0] -= 0.5;
  169.     else if (_key == GLUT_KEY_PAGE_UP)
  170.         rot_[2] += 0.5;
  171.     else if (_key == GLUT_KEY_PAGE_DOWN)
  172.         rot_[2] -= 0.5;
  173.  
  174.     if (rot_[0] > 360) rot_[0] = 360 - rot_[0];
  175.     if (rot_[1] > 360) rot_[1] = 360 - rot_[1];
  176.     if (rot_[2] > 360) rot_[2] = 360 - rot_[2];
  177.  
  178.     repaintRequest_ = GL_TRUE;
  179. }
  180.  
  181. void glScene::MouseMove(int, int)
  182. {
  183. }
  184. void glScene::MouseLBDown(int, int)
  185. {
  186. }
  187. void glScene::MouseLBUp(int, int)
  188. {
  189. }
  190.  
  191.  
  192. void glScene::Timer()
  193. {
  194.     repaintRequest_ = GL_TRUE;
  195. }
  196.  
  197. bool glScene::WantTimer()
  198. {
  199.     return false;
  200. }
  201.  
  202. int glScene::GetTimer()
  203. {
  204.     return 0;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement