icatalin

tema 4 ex 1 [GRAFICA]

Mar 25th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include<windows.h>
  2. #include <gl/freeglut.h>
  3.  
  4.  
  5. double i = 0.0;
  6. double j = 0.0;
  7. double alpha = 0.5;
  8. double alpha2 = 1;
  9.  
  10. void init(void)
  11. {
  12.     glClearColor(1.0, 1.0, 1.0, 0.0);
  13.     glMatrixMode(GL_PROJECTION);
  14.     glOrtho(-20.0, 780.0, 0.0, 600.0, -1.0, 1.0);
  15.  
  16. }
  17.  
  18. void deseneazaScena(void)
  19. {
  20.     glClear(GL_COLOR_BUFFER_BIT);
  21.  
  22.     glLineWidth(6.0);
  23.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  24.  
  25.     // CENTRUL DE GREUTATE
  26.     glColor3f(0, 0, 0);
  27.     glPointSize(10);
  28.     glEnable(GL_POINT_SMOOTH);
  29.     glBegin(GL_POINTS);
  30.     glVertex2f(300, 200);
  31.     glEnd();
  32.  
  33.     // APLICAREA TRANSFORMARII ASUPRA TRIUNGHIULUI
  34.  
  35.     glPushMatrix();
  36.     glTranslated(300, 200, 0);
  37.     glScaled(j, j, j);
  38.     glRotated(i, 0, 0, 1);
  39.     glTranslated(-300, -200, 0);
  40.     glBegin(GL_TRIANGLES);
  41.     glColor3f(0, 0, 1);
  42.     glVertex2f(100, 100);
  43.     glColor3f(0, 1, 0);
  44.     glVertex2f(500, 100);
  45.     glColor3f(1, 0, 0);
  46.     glVertex2f(300, 400);
  47.     glEnd();
  48.     glPopMatrix();
  49.  
  50.     glutSwapBuffers();
  51.     glFlush();
  52. }
  53.  
  54. void reshape(int w, int h)
  55. {
  56.     glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  57.     glMatrixMode(GL_PROJECTION);
  58.     glLoadIdentity();
  59.     glOrtho(-20.0, 780.0, 0.0, 600.0, -1.0, 1.0);
  60.     glMatrixMode(GL_MODELVIEW);
  61.     glLoadIdentity();
  62. }
  63.  
  64. void miscad(void)
  65. {
  66.     i = i + alpha;
  67.     if (i > 750.0)
  68.         alpha = -0.5;
  69.     else if (i < 0.0)
  70.         alpha = 0.5;
  71.  
  72.     j = j + alpha2;
  73.     if (j > 1)
  74.         alpha2 = -0.3;
  75.     else if (j < 0.1)
  76.         alpha2 = 0.3;
  77.  
  78.     glutPostRedisplay();
  79. }
  80.  
  81. void miscas(void)
  82. {
  83.     i = i + alpha;
  84.     if (i < 0.0)
  85.         alpha = 0.5;u
  86.     else if (i > 750.0)
  87.         alpha = -0.5;
  88.  
  89.     j = j + alpha2;
  90.     if (j > 1)
  91.         alpha2 = -0.3;
  92.     else if (j < 0.1)
  93.         alpha2 = 0.3;
  94.  
  95.     glutPostRedisplay();
  96. }
  97.  
  98. void mouse(int button, int state, int x, int y)
  99. {
  100.     switch (button) {
  101.     case GLUT_LEFT_BUTTON:
  102.         if (state == GLUT_DOWN)
  103.             alpha = -0.5; glutIdleFunc(miscas);
  104.         break;
  105.     case GLUT_RIGHT_BUTTON:
  106.         if (state == GLUT_DOWN)
  107.             alpha = 0.5; glutIdleFunc(miscad);
  108.         break;
  109.     default:
  110.         break;
  111.     }
  112. }
  113.  
  114.  
  115. void main(int argc, char** argv)
  116. {
  117.     glutInit(&argc, argv);
  118.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  119.     glutInitWindowSize(800, 600);
  120.     glutInitWindowPosition(100, 100);
  121.     glutCreateWindow("Triunghi rotitor scalat");
  122.     init();
  123.     glutDisplayFunc(deseneazaScena);
  124.     glutReshapeFunc(reshape);
  125.     glutMouseFunc(mouse);
  126.     glutMainLoop();
  127. }
Advertisement
Add Comment
Please, Sign In to add comment