FaisalAhemdBijoy

room 43

Apr 18th, 2021
679
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include<math.h>
  8.  
  9. const int width = 500;
  10. const int height = 500;
  11.  
  12. GLfloat eyeX = 5;
  13. GLfloat eyeY = 10;
  14. GLfloat eyeZ = -10;
  15.  
  16. GLfloat lookX = 0;
  17. GLfloat lookY = 0;
  18. GLfloat lookZ = 0;
  19.  
  20. float rot = 0;
  21.  
  22. static GLfloat v_cube[8][3] =
  23. {
  24.     {0,0,0},
  25.     {0,0,1},
  26.     {0,1,0},
  27.     {0,1,1},
  28.  
  29.     {1,0,0},
  30.     {1,0,1},
  31.     {1,1,0},
  32.     {1,1,1}
  33. };
  34.  
  35. static GLubyte c_ind[6][4] =
  36. {
  37.     {0,2,6,4},
  38.     {1,5,7,3},
  39.     {0,4,5,1},
  40.     {2,3,7,6},
  41.     {0,1,3,2},
  42.     {4,6,7,5}
  43. };
  44.  
  45.  
  46. void cube(float colR=0.5, float colG=0.5, float colB=0.5, float alpha=1)
  47. {
  48.     glBegin(GL_QUADS);
  49.     for (GLint i = 0; i <6; i++)
  50.     {
  51.         glColor4f(colR,colG,colB,alpha);
  52.  
  53.         colR += 0.03;
  54.         colG += 0.03;
  55.         colB += 0.03;
  56.  
  57.         for (GLint j=0; j<4; j++)
  58.         {
  59.             glVertex3fv(&v_cube[c_ind[i][j]][0]);
  60.         }
  61.     }
  62.     glEnd();
  63. }
  64.  
  65. void axes()
  66. {
  67.     float length = 10;
  68.     float width = 0.3;
  69.  
  70.     // X-axis
  71.     glPushMatrix();
  72.     glTranslatef(length/2,0,0);
  73.     glScalef(length,width,width);
  74.     glTranslatef(-0.5,-0.5,-0.5);
  75.     cube(0.8,0.1,0.1);
  76.     glPopMatrix();
  77.  
  78.     // Y-axis
  79.     glPushMatrix();
  80.     glTranslatef(0,length/2,0);
  81.     glScalef(width,length,width);
  82.     glTranslatef(-0.5,-0.5,-0.5);
  83.     cube(0.1,0.8,0.1);
  84.     glPopMatrix();
  85.  
  86.     // Z-axis
  87.     glPushMatrix();
  88.     glTranslatef(0,0,length/2);
  89.     glScalef(width,width,length);
  90.     glTranslatef(-0.5,-0.5,-0.5);
  91.     cube(0.1,0.1,0.8);
  92.     glPopMatrix();
  93. }
  94.  
  95. void flr()
  96. {
  97.     glPushMatrix();
  98. //    glTranslatef(0,-0.5,0);
  99.     glScalef(20,1,20);
  100.     glTranslatef(-0.5,-1,-0.5);
  101.     cube();
  102.     glPopMatrix();
  103. }
  104.  
  105. void table()
  106. {
  107.     float height=6;
  108.     float width=10;
  109.     float length=5;
  110.  
  111.     float base_height=1;
  112.     float leg_height=height-base_height;
  113.     float leg_width=0.5;
  114.  
  115.     // whole table
  116.     glPushMatrix();
  117.     glTranslatef(0,leg_height,0);
  118.  
  119.     // base
  120.     glPushMatrix();
  121.     glScalef(width,base_height,length);
  122.     glTranslatef(-0.5,0,-0.5);
  123.     cube(0.53,0.39,0.28);
  124.     glPopMatrix();
  125.  
  126.     // legs
  127.     glPushMatrix();
  128.     glTranslatef((width/2-leg_width/2),0,(length/2-leg_width/2));
  129.     glScalef(leg_width,leg_height,leg_width);
  130.     glTranslatef(-0.5,-1,-0.5);
  131.     cube(0.53,0.39,0.28);
  132.     glPopMatrix();
  133.  
  134.     glPushMatrix();
  135.     glTranslatef((width/2-leg_width/2),0,-(length/2-leg_width/2));
  136.     glScalef(leg_width,leg_height,leg_width);
  137.     glTranslatef(-0.5,-1,-0.5);
  138.     cube(0.53,0.39,0.28);
  139.     glPopMatrix();
  140.  
  141.     glPushMatrix();
  142.     glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
  143.     glScalef(leg_width,leg_height,leg_width);
  144.     glTranslatef(-0.5,-1,-0.5);
  145.     cube(0.53,0.39,0.28);
  146.     glPopMatrix();
  147.  
  148.     glPushMatrix();
  149.     glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
  150.     glScalef(leg_width,leg_height,leg_width);
  151.     glTranslatef(-0.5,-1,-0.5);
  152.     cube(0.53,0.39,0.28);
  153.     glPopMatrix();
  154.  
  155.     glPopMatrix();
  156. }
  157.  
  158. static void display(void)
  159. {
  160.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  161.     glMatrixMode(GL_PROJECTION);
  162.     glLoadIdentity();
  163.     glFrustum(-3, 3, -3, 3, 2.0, 100.0);
  164.  
  165.     glMatrixMode(GL_MODELVIEW);
  166.     glLoadIdentity();
  167.     gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0);
  168.     glViewport(0, 0, width, height);
  169.  
  170.     glRotatef(rot, 0,1,0);
  171.     axes();
  172.  
  173.     table();
  174.     flr();
  175.  
  176.     glutSwapBuffers();
  177. }
  178.  
  179.  
  180. static void key(unsigned char key, int x, int y)
  181. {
  182.     switch (key)
  183.     {
  184.     case 27 :
  185.     case 'q':
  186.         exit(0);
  187.         break;
  188.  
  189.     case ',':
  190.         rot++;
  191.         break;
  192.     case '.':
  193.         rot--;
  194.         break;
  195.     }
  196.  
  197.     glutPostRedisplay();
  198. }
  199.  
  200. static void idle(void)
  201. {
  202.     glutPostRedisplay();
  203. }
  204.  
  205. /* Program entry point */
  206.  
  207. int main(int argc, char *argv[])
  208. {
  209.     glutInit(&argc, argv);
  210.     glutInitWindowSize(width,height);
  211.     glutInitWindowPosition(10,10);
  212.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  213.  
  214.     glutCreateWindow("GLUT Shapes");
  215.  
  216.     glutDisplayFunc(display);
  217.     glutKeyboardFunc(key);
  218.     glutIdleFunc(idle);
  219.  
  220. //    glClearColor(1,1,1,1);
  221.  
  222.     glEnable(GL_DEPTH_TEST);
  223.     glShadeModel( GL_SMOOTH );
  224.     glEnable(GL_NORMALIZE);
  225.     glEnable(GL_BLEND);
  226.  
  227.     printf("########################################################################################\n");
  228.     printf("########################################################################################\n");
  229.     printf("##############                                                         #################\n");
  230.     printf("##############           PLEASE FOLLOW THE BELOW INSTRUCTIONS          #################\n");
  231.     printf("##############                                                         #################\n");
  232.     printf("########################################################################################\n");
  233.     printf("########################################################################################\n\n\n");
  234.     printf("Use 'w' to look up, 's' to look down, 'd' to look right, and 'a' to look left.\n");
  235.     printf("Use 'i' to move camera up, 'k' to move camera down, 'l' to move camera right, and 'j' to move camera left with the look at point fixed.\n");
  236.     printf("Use '+' to zoom in and '-' to zoom out.\n\n\n");
  237.  
  238.     glutMainLoop();
  239.  
  240.     return EXIT_SUCCESS;
  241. }
  242.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×