#include "stdafx.h" #include #include //Подключение библиотеки glut.h #include #include #include #include #define PI 3.14159265 using namespace std; void Initialize(); void DrawField(); void _TIME(); void Draw(); void timer(int = 0) { _TIME(); glutTimerFunc(10, timer, 0); } int _tmain(int argc, _TCHAR* argv[]) { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(400, 400); //Указываем размер окна glutInitWindowPosition(100, 100); //Позиция окна glutCreateWindow("Clock v0.1a"); //Имя окна Initialize(); //Вызов функции Initialize glutDisplayFunc(Draw); //Вызов функции отрисовки timer(); glutMainLoop(); _getch(); return 0; } void Initialize() { //Выбрать фоновый (очищающий) цвет glClearColor(0.1, 0.0, 0.3, 1.0); //Установить проекцию glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(5.0, 20.0, 20.0, 20.0, 0.0, 0.0); } void DrawField() { float x = 0.0, y = 0.0; glBegin(GL_LINES); for (int i = 0; i < 60; i++) // Рисуем секундную шкалу { x = (0.9 * cos(((i * 6) - 90) * PI / 180)); y = (0.9 * sin(((i * 6) - 90) * PI / 180)); glVertex2f(x, y); x = (0.92 * cos(((i * 6) - 90) * PI / 180)); y = (0.92 * sin(((i * 6) - 90) * PI / 180)); glVertex2f(x, y); } for (int i = 0; i < 12; i++) // Рисуем часовую шкалу { x = (0.88 * cos(((i * 30) - 90) * PI / 180)); y = (0.88 * sin(((i * 30) - 90) * PI / 180)); glVertex2f(x, y); x = (0.95 * cos(((i * 30) - 90) * PI / 180)); y = (0.95 * sin(((i * 30) - 90) * PI / 180)); glVertex2f(x, y); } glEnd(); } void _TIME() { time_t t = time(0); tm *lt = localtime(&t); int h = lt->tm_hour; int m = lt->tm_min; int s = lt->tm_sec; int plusToHour = 0; float x = 0.0, y = 0.0; glClear(GL_COLOR_BUFFER_BIT); DrawField(); glBegin(GL_LINES); glVertex2f(0.0, 0.0); x = (0.86 * cos((((-s * 6) - 270) * PI / 180))); y = (0.86 * sin((((-s * 6) - 270) * PI / 180))); glVertex2f(x, y); glVertex2f(0.0, 0.0); x = (0.81 * cos((((-m * 6) - 270) * PI / 180))); y = (0.81 * sin((((-m * 6) - 270) * PI / 180))); glVertex2f(x, y); if (m >= 5 && m <= 15) // добавление к стрелке часов plusToHour = 1; if (m >= 16 && m <= 30) plusToHour = 2; if (m >= 31 && m <= 45) plusToHour = 3; if (m >= 46 && m <= 59) plusToHour = 4; glVertex2f(0.0, 0.0); x = (0.60 * cos((((-h * 30 - plusToHour * 6) - 270) * PI / 180))); y = (0.60 * sin((((-h * 30 - plusToHour * 6) - 270) * PI / 180))); glVertex2f(x, y); glEnd(); glutSwapBuffers(); } void Draw() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); _TIME(); }