下边代码给出一个动画程序的例子。该例子在xy平面上绕z轴连续旋转一个正六边形。三维屏幕的原点放在窗口中心,z轴经过窗口中心。
具体代码如下:
#include <GL\glut.h>
#include <math.h>#include <stdlib.h>
const double TWO_PI = 6.2831853;
GLsizei winWidth = 500, winHeight = 500;
GLuint regHex; //Define name for display list
static GLfloat rotTheta = 0.0;
class scrPt
{
public:
GLint
x, y;
};
static void init(void){
scrPt hexVertex;
GLdouble hexTheta;
GLint k;
glClearColor(1.0, 1.0, 1.0, 0.0);
/* set up a display list for a red regular hexagon */
/* Vertices for the hexagon are six equally spaced points around the circumference of a circle */ //六边形的顶点在圆周上是6个等距点