⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glutmech.c

📁 学习c++必备
💻 C
📖 第 1 页 / 共 3 页
字号:
  glColor3f(0.5, 0.5, 0.5);  Box(0.5, 0.6, 2.0, solid);  glTranslatef(-1.5, 0.0, 0.0);  Box(0.5, 0.6, 2.0, solid);  glTranslatef(0.75, 0.0, 0.0);  glEndList();}voidMechHip(char solid){  int i;  glNewList(SOLID_MECH_HIP, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  Octagon(0.7, 0.5, solid);#ifdef SPHERE  for (i = 0; i < 2; i++) {    if (i)      glScalef(-1.0, 1.0, 1.0);    glTranslatef(1.0, 0.0, 0.0);#ifdef LIGHT    SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif    glColor3f(0.5, 0.5, 0.5);    if (!solid)      gluQuadricDrawStyle(qobj, GLU_LINE);    gluSphere(qobj, 0.2, 16, 16);    glTranslatef(-1.0, 0.0, 0.0);  }  glScalef(-1.0, 1.0, 1.0);#endif  glEndList();}voidShoulder(char solid){  glNewList(SOLID_MECH_SHOULDER, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  Box(1.0, 0.5, 0.5, solid);  glTranslatef(0.9, 0.0, 0.0);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);#ifdef SPHERE  if (!solid)    gluQuadricDrawStyle(qobj, GLU_LINE);  gluSphere(qobj, 0.6, 16, 16);#endif  glTranslatef(-0.9, 0.0, 0.0);  glEndList();}voidUpperArm(char solid){  int i;  glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  Box(1.0, 2.0, 1.0, solid);  glTranslatef(0.0, -0.95, 0.0);  glRotatef(90.0, 1.0, 0.0, 0.0);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  if (!solid)    gluQuadricDrawStyle(qobj, GLU_LINE);  gluCylinder(qobj, 0.4, 0.4, 1.5, 16, 10);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  glRotatef(-90.0, 1.0, 0.0, 0.0);  glTranslatef(-0.4, -1.85, 0.0);  glRotatef(90.0, 0.0, 1.0, 0.0);  for (i = 0; i < 2; i++) {    if (!solid)      gluQuadricDrawStyle(qobj, GLU_LINE);    if (i)      gluCylinder(qobj, 0.5, 0.5, 0.8, 16, 10);    else      gluCylinder(qobj, 0.2, 0.2, 0.8, 16, 10);  }  for (i = 0; i < 2; i++) {    if (i)      glScalef(-1.0, 1.0, 1.0);    if (!solid)      gluQuadricDrawStyle(qobj, GLU_LINE);    if (i)      glTranslatef(0.0, 0.0, 0.8);    gluDisk(qobj, 0.2, 0.5, 16, 10);    if (i)      glTranslatef(0.0, 0.0, -0.8);  }  glScalef(-1.0, 1.0, 1.0);  glRotatef(-90.0, 0.0, 1.0, 0.0);  glTranslatef(0.4, 2.9, 0.0);  glEndList();}voidVulcanGun(char solid){  int i;  glNewList(SOLID_MECH_VULCAN, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  if (!solid) {    gluQuadricDrawStyle(qobj, GLU_LINE);  }  gluCylinder(qobj, 0.5, 0.5, 0.5, 16, 10);  glTranslatef(0.0, 0.0, 0.5);  gluDisk(qobj, 0.0, 0.5, 16, 10);  for (i = 0; i < 5; i++) {    glRotatef(72.0, 0.0, 0.0, 1.0);    glTranslatef(0.0, 0.3, 0.0);    if (!solid) {      gluQuadricDrawStyle(qobj, GLU_LINE);    }    gluCylinder(qobj, 0.15, 0.15, 2.0, 16, 10);    gluCylinder(qobj, 0.06, 0.06, 2.0, 16, 10);    glTranslatef(0.0, 0.0, 2.0);    gluDisk(qobj, 0.1, 0.15, 16, 10);    gluCylinder(qobj, 0.1, 0.1, 0.1, 16, 5);    glTranslatef(0.0, 0.0, 0.1);    gluDisk(qobj, 0.06, 0.1, 16, 5);    glTranslatef(0.0, -0.3, -2.1);  }  glEndList();}voidForeArm(char solid){  char i;  glNewList(SOLID_MECH_FOREARM, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  for (i = 0; i < 5; i++) {    glTranslatef(0.0, -0.1, -0.15);    Box(0.6, 0.8, 0.2, solid);    glTranslatef(0.0, 0.1, -0.15);    Box(0.4, 0.6, 0.1, solid);  }  glTranslatef(0.0, 0.0, 2.45);  Box(1.0, 1.0, 2.0, solid);  glTranslatef(0.0, 0.0, -1.0);  glEndList();}voidUpperLeg(char solid){  int i;  glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  if (!solid) {    gluQuadricDrawStyle(qobj, GLU_LINE);  }  glTranslatef(0.0, -1.0, 0.0);  Box(0.4, 1.0, 0.7, solid);  glTranslatef(0.0, -0.65, 0.0);  for (i = 0; i < 5; i++) {    Box(1.2, 0.3, 1.2, solid);    glTranslatef(0.0, -0.2, 0.0);    Box(1.0, 0.1, 1.0, solid);    glTranslatef(0.0, -0.2, 0.0);  }  glTranslatef(0.0, -0.15, -0.4);  Box(2.0, 0.5, 2.0, solid);  glTranslatef(0.0, -0.3, -0.2);  glRotatef(90.0, 1.0, 0.0, 0.0);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  gluCylinder(qobj, 0.6, 0.6, 3.0, 16, 10);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  glRotatef(-90.0, 1.0, 0.0, 0.0);  glTranslatef(0.0, -1.5, 1.0);  Box(1.5, 3.0, 0.5, solid);  glTranslatef(0.0, -1.75, -0.8);  Box(2.0, 0.5, 2.0, solid);  glTranslatef(0.0, -0.9, -0.85);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);  for (i = 0; i < 2; i++) {    if (i)      glScalef(-1.0, 1.0, 1.0);    if (!solid)      gluQuadricDrawStyle(qobj, GLU_LINE);    if (i)      glTranslatef(0.0, 0.0, 1.8);    gluDisk(qobj, 0.0, 0.8, 16, 10);    if (i)      glTranslatef(0.0, 0.0, -1.8);  }  glScalef(-1.0, 1.0, 1.0);  glEndList();}voidFoot(char solid){  glNewList(SOLID_MECH_FOOT, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  glRotatef(90.0, 1.0, 0.0, 0.0);  Octagon(1.5, 0.6, solid);  glRotatef(-90.0, 1.0, 0.0, 0.0);  glEndList();}voidLowerLeg(char solid){  float k, l;#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  for (k = 0.0; k < 2.0; k++) {    for (l = 0.0; l < 2.0; l++) {      glPushMatrix();      glTranslatef(k, 0.0, l);#ifdef LIGHT      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif      glColor3f(1.0, 1.0, 0.0);      Box(1.0, 0.5, 1.0, solid);      glTranslatef(0.0, -0.45, 0.0);#ifdef LIGHT      SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif      glColor3f(0.5, 0.5, 0.5);#ifdef SPHERE      if (!solid)        glutWireSphere(0.2, 16, 10);      else        glutSolidSphere(0.2, 16, 10);#endif      if (leg)        glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);      else        glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);      /* glTranslatef(0.0, -0.2, 0.0); */      glTranslatef(0.0, -1.7, 0.0);#ifdef LIGHT      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif      glColor3f(1.0, 1.0, 0.0);      Box(0.25, 3.0, 0.25, solid);      glTranslatef(0.0, -1.7, 0.0);#ifdef LIGHT      SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif      glColor3f(0.5, 0.5, 0.5);#ifdef SPHERE      if (!solid)        glutWireSphere(0.2, 16, 10);      else        glutSolidSphere(0.2, 16, 10);#endif      if (leg)        glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);      else        glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);      glTranslatef(0.0, -0.45, 0.0);#ifdef LIGHT      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif      glColor3f(1.0, 1.0, 0.0);      Box(1.0, 0.5, 1.0, solid);      if (!k && !l) {        int j;        glTranslatef(-0.4, -0.8, 0.5);        if (leg)          glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);        else          glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);        glRotatef(90.0, 0.0, 1.0, 0.0);        if (!solid)          gluQuadricDrawStyle(qobj, GLU_LINE);        gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);        for (j = 0; j < 2; j++) {          if (!solid)            gluQuadricDrawStyle(qobj, GLU_LINE);          if (j) {            glScalef(-1.0, 1.0, 1.0);            glTranslatef(0.0, 0.0, 1.8);          }          gluDisk(qobj, 0.0, 0.8, 16, 10);          if (j)            glTranslatef(0.0, 0.0, -1.8);        }        glScalef(-1.0, 1.0, 1.0);        glRotatef(-90.0, 0.0, 1.0, 0.0);        glTranslatef(0.95, -0.8, 0.0);        glCallList(SOLID_MECH_FOOT);      }      glPopMatrix();    }  }}voidRocketPod(char solid){  int i, j, k = 0;  glNewList(SOLID_MECH_ROCKET, GL_COMPILE);#ifdef LIGHT  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);#endif  glColor3f(0.5, 0.5, 0.5);  glScalef(0.4, 0.4, 0.4);  glRotatef(45.0, 0.0, 0.0, 1.0);  glTranslatef(1.0, 0.0, 0.0);  Box(2.0, 0.5, 3.0, solid);  glTranslatef(1.0, 0.0, 0.0);  glRotatef(45.0, 0.0, 0.0, 1.0);  glTranslatef(0.5, 0.0, 0.0);  Box(1.2, 0.5, 3.0, solid);  glTranslatef(2.1, 0.0, 0.0);  glRotatef(-90.0, 0.0, 0.0, 1.0);#ifdef LIGHT  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);#endif  glColor3f(1.0, 1.0, 0.0);  Box(2.0, 3.0, 4.0, solid);  glTranslatef(-0.5, -1.0, 1.3);  for (i = 0; i < 2; i++) {    for (j = 0; j < 3; j++) {      if (!solid) {        gluQuadricDrawStyle(qobj, GLU_LINE);      }      glTranslatef(i, j, 0.6);#ifdef LIGHT      SetMaterial(mat_specular3, mat_ambient3, mat_diffuse3, mat_shininess3);#endif      glColor3f(1.0, 1.0, 1.0);      gluCylinder(qobj, 0.4, 0.4, 0.3, 16, 10);      glTranslatef(0.0, 0.0, 0.3);#ifdef LIGHT      SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);#endif      glColor3f(0.0, 1.0, 0.0);      gluCylinder(qobj, 0.4, 0.0, 0.5, 16, 10);      k++;      glTranslatef(-i, -j, -0.9);    }  }  glEndList();}voidEnviro(char solid){  int i, j;  glNewList(SOLID_ENVIRO, GL_COMPILE);  SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);  glColor3f(0.0, 1.0, 0.0);  Box(20.0, 0.5, 30.0, solid);  SetMaterial(mat_specular4, mat_ambient3, mat_diffuse2, mat_shininess);  glColor3f(0.6, 0.6, 0.6);  glTranslatef(0.0, 0.0, -10.0);  for (j = 0; j < 6; j++) {    for (i = 0; i < 2; i++) {      if (i)        glScalef(-1.0, 1.0, 1.0);      glTranslatef(10.0, 4.0, 0.0);      Box(4.0, 8.0, 2.0, solid);      glTranslatef(0.0, -1.0, -3.0);      Box(4.0, 6.0, 2.0, solid);      glTranslatef(-10.0, -3.0, 3.0);    }    glScalef(-1.0, 1.0, 1.0);    glTranslatef(0.0, 0.0, 5.0);  }  glEndList();}voidToggle(void){  if (solid_part)    solid_part = 0;  else    solid_part = 1;}voiddisable(void){  glDisable(GL_LIGHTING);  glDisable(GL_DEPTH_TEST);  glDisable(GL_NORMALIZE);  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);}voidlighting(void){  GLfloat position[] =  {0.0, 0.0, 2.0, 1.0};#ifdef MOVE_LIGHT  glRotatef((GLfloat) lightturn1, 1.0, 0.0, 0.0);  glRotatef((GLfloat) lightturn, 0.0, 1.0, 0.0);  glRotatef(0.0, 1.0, 0.0, 0.0);#endif  glEnable(GL_LIGHTING);  glEnable(GL_LIGHT0);  glEnable(GL_NORMALIZE);  glDepthFunc(GL_LESS);  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);  glLightfv(GL_LIGHT0, GL_POSITION, position);  glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 80.0);  glTranslatef(0.0, 0.0, 2.0);  glDisable(GL_LIGHTING);  Box(0.1, 0.1, 0.1, 0);  glEnable(GL_LIGHTING);}voidDrawMech(void){  int i, j;  glScalef(0.5, 0.5, 0.5);  glPushMatrix();  glTranslatef(0.0, -0.75, 0.0);  glRotatef((GLfloat) tilt, 1.0, 0.0, 0.0);  glRotatef(90.0, 1.0, 0.0, 0.0);#ifdef HIP  glCallList(SOLID_MECH_HIP);#endif  glRotatef(-90.0, 1.0, 0.0, 0.0);  glTranslatef(0.0, 0.75, 0.0);  glPushMatrix();  glRotatef((GLfloat) pivot, 0.0, 1.0, 0.0);  glPushMatrix();#ifdef TORSO  glCallList(SOLID_MECH_TORSO);#endif  glPopMatrix();  glPushMatrix();  glTranslatef(0.5, 0.5, 0.0);#ifdef ROCKET_POD  glCallList(SOLID_MECH_ROCKET);#endif  glPopMatrix();  for (i = 0; i < 2; i++) {    glPushMatrix();    if (i)      glScalef(-1.0, 1.0, 1.0);    glTranslatef(1.5, 0.0, 0.0);#ifdef SHOULDER    glCallList(SOLID_MECH_SHOULDER);#endif    glTranslatef(0.9, 0.0, 0.0);    if (i) {      glRotatef((GLfloat) lat1, 0.0, 0.0, 1.0);      glRotatef((GLfloat) shoulder1, 1.0, 0.0, 0.0);      glRotatef((GLfloat) shoulder3, 0.0, 1.0, 0.0);    } else {      glRotatef((GLfloat) lat2, 0.0, 0.0, 1.0);      glRotatef((GLfloat) shoulder2, 1.0, 0.0, 0.0);      glRotatef((GLfloat) shoulder4, 0.0, 1.0, 0.0);    }    glTranslatef(0.0, -1.4, 0.0);#ifdef UPPER_ARM    glCallList(SOLID_MECH_UPPER_ARM);#endif    glTranslatef(0.0, -2.9, 0.0);    if (i)      glRotatef((GLfloat) elbow1, 1.0, 0.0, 0.0);    else      glRotatef((GLfloat) elbow2, 1.0, 0.0, 0.0);    glTranslatef(0.0, -0.9, -0.2);#ifdef LOWER_ARM    glCallList(SOLID_MECH_FOREARM);    glPushMatrix();    glTranslatef(0.0, 0.0, 2.0);    glRotatef((GLfloat) fire, 0.0, 0.0, 1.0);    glCallList(SOLID_MECH_VULCAN);    glPopMatrix();#endif    glPopMatrix();  }  glPopMatrix();  glPopMatrix();  for (j = 0; j < 2; j++) {    glPushMatrix();    if (j) {      glScalef(-0.5, 0.5, 0.5);      leg = 1;    } else {      glScalef(0.5, 0.5, 0.5);      leg = 0;    }    glTranslatef(2.0, -1.5, 0.0);    if (j) {      glRotatef((GLfloat) hip11, 1.0, 0.0, 0.0);      glRotatef((GLfloat) hip12, 0.0, 0.0, 1.0);    } else {      glRotatef((GLfloat) hip21, 1.0, 0.0, 0.0);      glRotatef((GLfloat) hip22, 0.0, 0.0, 1.0);    }    glTranslatef(0.0, 0.3, 0.0);#ifdef UPPER_LEG    glPushMatrix();    glCallList(SOLID_MECH_UPPER_LEG);    glPopMatrix();#endif    glTranslatef(0.0, -8.3, -0.4);    if (j)      glRotatef((GLfloat) - hip12, 0.0, 0.0, 1.0);    else      glRotatef((GLfloat) - hip22, 0.0, 0.0, 1.0);    glTranslatef(-0.5, -0.85, -0.5);#ifdef LOWER_LEG    LowerLeg(1);#endif    glPopMatrix();  }}voiddisplay(void){  glClearColor(0.0, 0.0, 0.0, 0.0);  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glEnable(GL_DEPTH_TEST);  glPushMatrix();  glRotatef((GLfloat) turn, 0.0, 1.0, 0.0);  glRotatef((GLfloat) turn1, 1.0, 0.0, 0.0);#ifdef LIGHT  if (solid_part) {    glPushMatrix();    lighting();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -