首先要进行旋转,要生成对应的简易3d模型,这里使用的是老师的机械臂代码。
void CSphereView::Display()
{
GLUquadricObj* quad_obj = NULL;
if (quad_obj == NULL) quad_obj = gluNewQuadric();
gluQuadricDrawStyle(quad_obj, GLU_LINE);
gluQuadricNormals(quad_obj, GLU_SMOOTH);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
//view
gluLookAt(-2.0, -1.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glPushMatrix();
//the first joint
if (selectedNum == 1) { glColor3f(1, 0, 0); }
else { glColor3f(1, 1, 1); }
gluSphere(quad_obj, 1.0f, 20, 20);
//the first degree
glRotated(armsDegree[0].xy, 0, 0, 1);
glRotated(armsDegree[0].yz, 1, 0, 0);
glRotated(armsDegree[0].xz, 0, 0, 1);
glPushMatrix();
//draw the first arm
glPushMatrix();
glColor3f(1, 1, 1);
glTranslated(6, 0, 0);
glScaled(10, 2, 2);
DrawUnitCube();
glPopMatrix();
//draw the second joint
glTranslated(11.8, 0, 0);
glPushMatrix();
if (selectedNum ==