Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <gl\gl.h>
- #include <gl\glu.h>
- #include <gl\glut.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <stdio.h>
- #include <iostream>
- #include <ctime>
- static void redraw(void);
- int main(int argc, char **argv);
- int main(int argc, char **argv)
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(800,800);
- glutCreateWindow("Шаховска Табла");
- glutDisplayFunc(redraw);
- glMatrixMode(GL_PROJECTION); //hello
- gluPerspective(45, //view angle
- 1.0, //aspect ratio
- 10.0, //near clip
- 200.0);//far clip
- glMatrixMode(GL_MODELVIEW);
- glutMainLoop();
- return 0;
- }
- static void crtajKrug(int s, int od, float r, float xk, float yk, bool bela, bool loop){
- float x,y;
- float radius = r;
- yk*=-1;
- if(!loop)
- glBegin(GL_POLYGON);
- else
- glBegin(GL_LINE_LOOP);
- if(bela)
- glColor3f(1.0f,1.0f,1.0f);
- else
- glColor3f(0.0f,0.0f,0.0f);
- if(od==0){
- x = (float)radius * cos(359 * M_PI/180.0f)+xk;
- y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
- }
- else{
- x = (float)radius * cos(od * M_PI/180.0f)+xk;
- y = (float)radius * sin(od * M_PI/180.0f)+8+yk;
- }
- for(int j = od; j <= s; j++)
- {
- glVertex2f(x,y);
- x = (float)radius * cos(j * M_PI/180.0f)+xk;
- y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
- glVertex2f(x,y);
- }
- glEnd();
- }
- static void crtajKrugsostrelki(int s, int od, float r, float xk, float yk, bool bela, bool loop, int agol){
- float x,y;
- float radius = r;
- yk*=-1;
- if(!loop)
- glBegin(GL_POLYGON);
- else
- glBegin(GL_LINE_LOOP);
- if(bela)
- glColor3f(1.0f,1.0f,1.0f);
- else
- glColor3f(0.0f,0.0f,0.0f);
- if(od==0){
- x = (float)radius * cos(359 * M_PI/180.0f)+xk;
- y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
- }
- else{
- x = (float)radius * cos(od * M_PI/180.0f)+xk;
- y = (float)radius * sin(od * M_PI/180.0f)+8+yk;
- }
- for(int j = od; j <= s; j++)
- {
- glVertex2f(x,y);
- x = (float)radius * cos(j * M_PI/180.0f)+xk;
- y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
- glVertex2f(x,y);
- }
- glEnd();
- glBegin(GL_LINES);
- glVertex2f(xk, yk+8);
- glVertex2f(xk, yk+8.8);
- glVertex2f(xk, yk+8);
- xk = 0.5 * cos(agol * M_PI/180.0f);
- yk = 0.5 * sin(agol * M_PI/180.0f);
- glVertex2f(xk, yk+8);
- glEnd();
- }
- static void crtajkrugcinja(int s, int od, float r, float xk, float yk, bool bela){
- float x,y;
- float radius = r;
- yk*=-1;
- x = (float)radius * cos(359 * M_PI/180.0f)+xk;
- y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
- float xstar = 0, ystar = 0;
- for(int j = od; j <= s; j+=30)
- {
- x = (float)radius * cos(j * M_PI/180.0f)+xk;
- y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
- glLoadIdentity();
- glTranslatef(x,y-12,-10);
- glScalef(0.5,0.5,1);
- crtajKrugsostrelki(360,0,1,0,0,false,true, j);
- }
- }
- static void redraw(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(0,-8,-10);
- //Crtaj osnova
- crtajKrug(360,0,3.5,0,0,true,false);
- crtajKrug(360,0,0.1,0,0,false,false);
- time_t now = time(0);
- tm *ltm = localtime(&now);
- printf("%d", ltm->tm_min);
- int minagol, casagol;
- if(ltm->tm_min<=15){
- minagol = 90-((ltm->tm_min)*6);
- }
- else
- minagol = 360 - ((ltm->tm_min-15)*6);
- if(ltm->tm_hour > 12) ltm->tm_hour -=12;
- if(ltm->tm_hour<=3){
- casagol = 90-((ltm->tm_hour)*30 + (ltm->tm_min)*0.5);
- }
- else
- casagol = 360 - ((ltm->tm_hour-3)*30 + (ltm->tm_min)*0.5);
- glBegin(GL_LINES);
- glVertex2f(0, 8);
- glVertex2f(2 * cos(minagol * M_PI/180.0f), 2 * sin(minagol * M_PI/180.0f)+8);
- glVertex2f(0, 8);
- glVertex2f(1 * cos(casagol * M_PI/180.0f), 1 * sin(casagol * M_PI/180.0f)+8);
- glEnd();
- //Crtaj pomali
- glLoadIdentity();
- glTranslatef(2.8,-4,-10);
- glScalef(0.5,0.5,1);
- crtajkrugcinja(360,0,2.8,0,0,false);
- glPopMatrix();
- glutSwapBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement