Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.46 KB | None | 0 0
  1. #include "h.h"
  2. #include <math.h>
  3. #include <string.h>
  4. #include <QApplication>
  5. #include <QtOpenGL>
  6. #include <GL/glut.h>
  7. #include <GL/freeglut.h>
  8. #include <iostream>
  9.  
  10. void display(void) {}
  11.  
  12.  
  13. void initValues(t_badprog *bp)
  14. {
  15.     bp->screenPositionX = 100;
  16.     bp->screenPositionY = 100;
  17.  
  18.     bp->bgRed            = 0;
  19.     bp->bgGreen        = 0;
  20.     bp->bgBlue            = 0;
  21.     bp->bgAlpha        = 0;
  22.  
  23.     bp->drawRed        = 0;
  24.     bp->drawGreen        = 1;
  25.     bp->drawBlue        = 0;
  26.  
  27.     bp->side            = 3;
  28.     bp->hyp            = bp->side;
  29.     bp->sideHalf        = bp->hyp / 2;
  30.  
  31.     bp->sideToFind        = pow(bp->hyp, 2) - pow(bp->sideHalf, 2);
  32.     bp->sideToFind        = sqrt(bp->sideToFind);
  33.     bp->ratio            = pow(bp->sideHalf, 2) / 2;
  34.  
  35.     bp->z                = -8;
  36.  
  37.     bp->x1                = -1.5;
  38.     bp->x2                = 0;
  39.     bp->x3                = 1.5;
  40.  
  41.     bp->y1                = 0 - bp->ratio;
  42.     bp->y2                = bp->sideToFind - bp->ratio;
  43.     bp->y3                = 0 - bp->ratio;
  44. }
  45.  
  46. void initProgram(t_badprog *bp)
  47. {
  48.     initValues(bp);
  49.     glClearColor(bp->bgRed, bp->bgGreen, bp->bgBlue, bp->bgAlpha);
  50.     glColor3f(bp->drawRed, bp->drawGreen, bp->drawBlue);
  51. }
  52.  
  53. void drawTriangle(t_badprog bp, char colour){
  54.     switch(colour) {
  55.     case 'g': //green
  56.         glColor3f(0, 1, 0);
  57.         glBegin(GL_TRIANGLES);
  58.             glVertex3f(bp.x1, bp.y1, bp.z);
  59.             glVertex3f(bp.x2, bp.y2, bp.z);
  60.             glVertex3f(bp.x3, bp.y3, bp.z);
  61.         glEnd();
  62.         break;
  63.     case 'r': //red
  64.         glColor3f(1, 0, 0);
  65.         glBegin(GL_TRIANGLES);
  66.             glVertex3f(bp.x1, bp.y1, bp.z);
  67.             glVertex3f(bp.x2, bp.y2, bp.z);
  68.             glVertex3f(bp.x3, bp.y3, bp.z);
  69.         glEnd();
  70.         break;
  71.     case 'b': //blue
  72.         glColor3f(0, 0, 1);
  73.         glBegin(GL_TRIANGLES);
  74.             glVertex3f(bp.x1, bp.y1, bp.z);
  75.             glVertex3f(bp.x2, bp.y2, bp.z);
  76.             glVertex3f(bp.x3, bp.y3, bp.z);
  77.         glEnd();
  78.         break;
  79.  
  80.     }
  81. }
  82.  
  83. void managerDisplay(void)
  84. {
  85.     t_badprog bp;
  86.     float var = 5;
  87.     float newAngle = 0;
  88.  
  89.     initProgram(&bp);
  90.  
  91.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  92.  
  93.     glMatrixMode(GL_MODELVIEW);
  94.  
  95.  
  96.     glLoadIdentity();
  97.     glTranslatef(0.0f, 0.0f, -30.0f);
  98.  
  99. //    drawTriangle(bp, 'g'); //cup A
  100. //    glPushMatrix();
  101. //    glTranslatef(2, -2, 0);
  102. //    glPushMatrix();
  103. //    glRotatef(45, 0, 0, 1);
  104. //    drawTriangle(bp, 'r'); // cup B
  105. //    glTranslatef(-3, 1, 0);
  106.  
  107. //    glPopMatrix();
  108. //    drawTriangle(bp, 'b');
  109. //    glScalef(-2, 1, 1);
  110. //    glTranslatef(4, 4, 0);
  111. //    glRotatef(45, 0, 0, 1);
  112. //    drawTriangle(bp, 'b'); // cup C
  113. //    glPopMatrix();
  114.  
  115.  
  116.     for (int count = 0; count<3; count++)
  117.     {
  118.         // Green X
  119.             glPushMatrix();
  120.             if(count!=0) {
  121.                 glTranslatef(0.0f, 0.0f, 0.0f);
  122.                 glRotatef(newAngle, 1.0f, 0.0f, 0.0f);
  123.             }
  124.                 glColor3f(0, 1, 0);
  125.                 glBegin(GL_TRIANGLES);
  126.                     glVertex3f(bp.x1, bp.y1, bp.z);
  127.                     glVertex3f(bp.x2, bp.y2, bp.z);
  128.                     glVertex3f(bp.x3, bp.y3, bp.z);
  129.                 glEnd();
  130.             glPopMatrix();
  131.  
  132.             // Blue Y
  133.  
  134.             glPushMatrix();
  135.             if(count!=0) {
  136.                 glTranslatef(0.0f, 0.0f, 0.0f);
  137.                 glRotatef(newAngle, 0.0f, 1.0f, 0.0f);
  138.             }
  139.                 glColor3f(0, 0, 1);
  140.                 glBegin(GL_TRIANGLES);
  141.                     glVertex3f(bp.x1, bp.y1, bp.z);
  142.                     glVertex3f(bp.x2, bp.y2, bp.z);
  143.                     glVertex3f(bp.x3, bp.y3, bp.z);
  144.                 glEnd();
  145.             glPopMatrix();
  146.  
  147.             // *****RED Z***************************
  148.             glPushMatrix();
  149.             if(count==1) {
  150.                 glRotatef(90, 0.0f, 0.0f, 1.0f);
  151.                // glTranslatef(2.0f, 1.0f, 0.0f);
  152.             }
  153.             if(count==2) {
  154.                 glTranslatef(1.0f, 5.0f, 0.0f);
  155.                  glRotatef(90, 0.0f, 0.0f, 1.0f);
  156.                  //glTranslatef(5.0f, 1.0f, 0.0f);
  157.             }
  158.                 //glRotatef(newAngle, 0.0f, 0.0f, 1.0f);
  159.                 glColor3f(1, 0, 0);
  160.                 glBegin(GL_TRIANGLES);
  161.                     glVertex3f(bp.x1 + var, bp.y1, bp.z);
  162.                     glVertex3f(bp.x2 + var, bp.y2, bp.z);
  163.                     glVertex3f(bp.x3 + var, bp.y3, bp.z);
  164.                 glEnd();
  165.             glPopMatrix();
  166.         newAngle += 90; //yeeet
  167.     }
  168.  
  169.  
  170.     glutSwapBuffers();
  171. }
  172.  
  173. void managerKeyboard(unsigned char key, int x, int y)
  174. {
  175.     switch (key)
  176.     {
  177.         case 27:
  178.         {
  179.             exit(0);
  180.         }
  181.     }
  182.     (void)(x);
  183.     (void)(y);
  184. }
  185.  
  186. void managerResize(int w, int h) {
  187.     glViewport(0, 0, w, h);
  188.     glMatrixMode(GL_PROJECTION);
  189.     glLoadIdentity();
  190.     gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
  191. }
  192.  
  193. void init(int ac, char *av[])
  194. {
  195.   glutInit(&ac, av);
  196.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  197.   glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  198.   glutInitWindowPosition(SCREEN_POSITION_X, SCREEN_POSITION_Y);
  199.  
  200.   glutCreateWindow(SCREEN_TITLE);
  201.  
  202.   glEnable(GL_DEPTH_TEST);
  203.  
  204.   glutDisplayFunc(managerDisplay);
  205.   glutKeyboardFunc(managerKeyboard);
  206.   glutReshapeFunc(managerResize);
  207.  
  208.   glutMainLoop();
  209. }
  210.  
  211. int  main(int ac, char *av[])
  212. {
  213.   init(ac, av);
  214.   return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement