效果
在窗口中央显示一个时钟,单击鼠标右键时钟开始走时;按住鼠标左键上下移动可以调节时刻。
源代码
#include <gl/glut.h>
#include <cmath>
#define HOURHAND (handtype)0
#define MINUTEHAND (handtype)1
#define SECONDHAND (handtype)2
typedef unsigned handtype;
const double Pi = 3.1415926535;
bool leftmousedown = false;
bool clockloop = false; //时钟开始走
int winwidth = 800;
int winheight = 800;
const int CLOCKRADIUS = 120;
const int HOURWIDTH = 5;
const int HOURLENGTH = 55;
const int MINUTEWIDTH = 3;
const int MINUTELENGTH = 80;
const int SECONDWIDTH = 2;
const int SECONDLENGTH = 105;
double hourdegree = 0.0;
double minutedegree = 0.0;
double seconddegree = 0.0;
int xlast = 0, ylast = 0;
void Timer(int);
void Mouse(int, int, int, int);
void Motion(int, int y);
void DrawCircle(int, int x = round(winwidth / 2), int y = round(winheight / 2));
void DrawHand(handtype, int x = round(winwidth / 2), int y = round(winheight / 2));
void Display();
void ChangeSize(int, int);
void Display() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, winwidth, 0,<