代码如下:
#include <GL/glut.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
const GLfloat PI=3.14;
static int shoulder = 0, elbow = 0; //shoulder:肩部角度,elbow: 肘部角度
/// record the state of mouse
GLboolean mouserdown = GL_FALSE;
GLboolean mouseldown = GL_FALSE;
GLboolean mousemdown = GL_FALSE;
/// when a mouse-key is pressed, record current mouse position
static GLint mousex = 0, mousey = 0;
static GLfloat center[3] = {0.0f, 0.0f, 0.0f}; /// center position
static GLfloat eye[3]; /// eye's position
static GLfloat yrotate = PI/4; /// angle between y-axis and look direction
static GLfloat xrotate = PI/4; /// angle between x-axis and look direction
static GLfloat celength = 20.0f;/// lenght between center and eye
static GLfloat mSpeed = 0.4f; /// center move speed
static GLfloat rSpeed = 0.02f; /// rotate speed