Advertisement
jovanovski

КГ Дом1

Mar 31st, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.20 KB | None | 0 0
  1.     #include <windows.h>
  2.     #include <gl\gl.h>
  3.     #include <gl\glu.h>
  4.     #include <gl\glut.h>
  5.     #define _USE_MATH_DEFINES
  6.     #include <math.h>
  7.     #include <stdio.h>
  8.     #include <iostream>
  9.     #include <ctime>
  10.  
  11.     static void redraw(void);
  12.     int main(int argc, char **argv);
  13.  
  14.     int main(int argc, char **argv)
  15.     {
  16.  
  17.  
  18.             glutInit(&argc,argv);
  19.             glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  20.             glutInitWindowSize(800,800);
  21.             glutCreateWindow("Шаховска Табла");
  22.  
  23.             glutDisplayFunc(redraw);
  24.  
  25.             glMatrixMode(GL_PROJECTION);                                            //hello
  26.             gluPerspective(45, //view angle
  27.                                                     1.0,    //aspect ratio
  28.                                                     10.0, //near clip
  29.                                                     200.0);//far clip
  30.             glMatrixMode(GL_MODELVIEW);
  31.  
  32.             glutMainLoop();
  33.  
  34.             return 0;
  35.     }
  36.  
  37.     static void crtajKrug(int s, int od, float r, float xk, float yk, bool bela, bool loop){
  38.         float x,y;
  39.         float radius = r;
  40.         yk*=-1;
  41.         if(!loop)
  42.         glBegin(GL_POLYGON);
  43.         else
  44.             glBegin(GL_LINE_LOOP);
  45.         if(bela)
  46.             glColor3f(1.0f,1.0f,1.0f);
  47.         else
  48.             glColor3f(0.0f,0.0f,0.0f);
  49.         if(od==0){
  50.         x = (float)radius * cos(359 * M_PI/180.0f)+xk;
  51.         y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
  52.         }
  53.         else{
  54.             x = (float)radius * cos(od * M_PI/180.0f)+xk;
  55.             y = (float)radius * sin(od * M_PI/180.0f)+8+yk;
  56.         }
  57.         for(int j = od; j <= s; j++)
  58.         {
  59.             glVertex2f(x,y);
  60.             x = (float)radius * cos(j * M_PI/180.0f)+xk;
  61.             y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
  62.             glVertex2f(x,y);
  63.         }
  64.         glEnd();
  65.     }
  66.  
  67.     static void crtajKrugsostrelki(int s, int od, float r, float xk, float yk, bool bela, bool loop, int agol){
  68.         float x,y;
  69.         float radius = r;
  70.         yk*=-1;
  71.         if(!loop)
  72.         glBegin(GL_POLYGON);
  73.         else
  74.             glBegin(GL_LINE_LOOP);
  75.         if(bela)
  76.             glColor3f(1.0f,1.0f,1.0f);
  77.         else
  78.             glColor3f(0.0f,0.0f,0.0f);
  79.         if(od==0){
  80.         x = (float)radius * cos(359 * M_PI/180.0f)+xk;
  81.         y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
  82.         }
  83.         else{
  84.             x = (float)radius * cos(od * M_PI/180.0f)+xk;
  85.             y = (float)radius * sin(od * M_PI/180.0f)+8+yk;
  86.         }
  87.         for(int j = od; j <= s; j++)
  88.         {
  89.             glVertex2f(x,y);
  90.             x = (float)radius * cos(j * M_PI/180.0f)+xk;
  91.             y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
  92.             glVertex2f(x,y);
  93.         }
  94.         glEnd();
  95.  
  96.         glBegin(GL_LINES);
  97.             glVertex2f(xk, yk+8);
  98.             glVertex2f(xk, yk+8.8);
  99.             glVertex2f(xk, yk+8);
  100.             xk = 0.5 * cos(agol * M_PI/180.0f);
  101.             yk = 0.5 * sin(agol * M_PI/180.0f);
  102.             glVertex2f(xk, yk+8);
  103.         glEnd();
  104.     }
  105.  
  106.  
  107.     static void crtajkrugcinja(int s, int od, float r, float xk, float yk, bool bela){
  108.         float x,y;
  109.         float radius = r;
  110.         yk*=-1;
  111.         x = (float)radius * cos(359 * M_PI/180.0f)+xk;
  112.         y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
  113.  
  114.         float xstar = 0, ystar = 0;
  115.         for(int j = od; j <= s; j+=30)
  116.         {
  117.             x = (float)radius * cos(j * M_PI/180.0f)+xk;
  118.             y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
  119.             glLoadIdentity();
  120.             glTranslatef(x,y-12,-10);
  121.             glScalef(0.5,0.5,1);
  122.             crtajKrugsostrelki(360,0,1,0,0,false,true, j);
  123.         }
  124.  
  125.     }
  126.  
  127.  
  128.  
  129.  
  130.     static void redraw(void)
  131.     {
  132.             glClear(GL_COLOR_BUFFER_BIT);
  133.  
  134.             glPushMatrix();
  135.             glTranslatef(0,-8,-10);
  136.             //Crtaj osnova
  137.             crtajKrug(360,0,3.5,0,0,true,false);
  138.             crtajKrug(360,0,0.1,0,0,false,false);
  139.  
  140.             time_t now = time(0);
  141.  
  142.             tm *ltm = localtime(&now);
  143.             printf("%d", ltm->tm_min);
  144.             int minagol, casagol;
  145.  
  146.             if(ltm->tm_min<=15){
  147.                 minagol = 90-((ltm->tm_min)*6);
  148.             }
  149.             else
  150.                 minagol = 360 - ((ltm->tm_min-15)*6);
  151.  
  152.             if(ltm->tm_hour > 12) ltm->tm_hour -=12;
  153.             if(ltm->tm_hour<=3){
  154.                 casagol = 90-((ltm->tm_hour)*30 + (ltm->tm_min)*0.5);
  155.             }
  156.             else
  157.                 casagol = 360 - ((ltm->tm_hour-3)*30 + (ltm->tm_min)*0.5);
  158.  
  159.  
  160.             glBegin(GL_LINES);
  161.             glVertex2f(0, 8);
  162.             glVertex2f(2 * cos(minagol * M_PI/180.0f), 2 * sin(minagol * M_PI/180.0f)+8);
  163.             glVertex2f(0, 8);
  164.             glVertex2f(1 * cos(casagol * M_PI/180.0f), 1 * sin(casagol * M_PI/180.0f)+8);
  165.  
  166.         glEnd();
  167.  
  168.  
  169.             //Crtaj pomali
  170.              glLoadIdentity();
  171.              glTranslatef(2.8,-4,-10);
  172.              glScalef(0.5,0.5,1);
  173.              crtajkrugcinja(360,0,2.8,0,0,false);
  174.  
  175.             glPopMatrix();
  176.             glutSwapBuffers();
  177.  
  178.  
  179.  
  180.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement