PageRenderTime 187ms CodeModel.GetById 30ms app.highlight 129ms RepoModel.GetById 12ms app.codeStats 0ms

/1/internet_examples/terminator.c

https://github.com/rajatkhanduja/Dabblings-in-OpenGL
C | 1734 lines | 1535 code | 161 blank | 38 comment | 111 complexity | fdb69114e922661b8d3f2299d540fb29 MD5 | raw file
   1#define SPHERE
   2#define COLOR
   3#define LIGHT
   4#define TORSO
   5#define HIP
   6#define SHOULDER
   7#define UPPER_ARM
   8#define LOWER_ARM
   9#define ROCKET_POD
  10#define UPPER_LEG
  11#define LOWER_LEG
  12#define NO_NORM
  13#define ANIMATION
  14#define DRAW_MECH
  15#define DRAW_ENVIRO
  16#define MOVE_LIGHT
  17/* end of compilation conditions */
  18
  19/* start various header files needed */
  20#include <stdlib.h>
  21
  22#include <math.h>
  23#define GLUT
  24#define GLUT_KEY
  25#define GLUT_SPEC
  26#include <GL/glut.h>
  27#include <GL/gl.h>
  28
  29/* end of header files */
  30
  31/* start of display list definitions */
  32#define SOLID_MECH_TORSO           1
  33#define SOLID_MECH_HIP          2
  34#define SOLID_MECH_SHOULDER     3
  35#define SOLID_MECH_UPPER_ARM    4
  36#define SOLID_MECH_FOREARM    5
  37#define SOLID_MECH_UPPER_LEG       6
  38#define SOLID_MECH_FOOT            7
  39#define SOLID_MECH_ROCKET          8
  40#define SOLID_MECH_VULCAN    9
  41#define SOLID_ENVIRO        10
  42/* end of display list definitions */
  43
  44/* start of motion rate variables */
  45#define ANKLE_RATE    3
  46#define HEEL_RATE    3
  47#define ROTATE_RATE    10
  48#define TILT_RATE    10
  49#define ELBOW_RATE    2
  50#define SHOULDER_RATE    5
  51#define LAT_RATE    5
  52#define CANNON_RATE    40
  53#define UPPER_LEG_RATE    3
  54#define UPPER_LEG_RATE_GROIN 10
  55#define LIGHT_TURN_RATE    10
  56#define VIEW_TURN_RATE    10
  57/* end of motion rate variables */
  58
  59/* start of motion  variables */
  60
  61/* Some <math.h> files do not define M_PI... */
  62#ifndef M_PI
  63#define M_PI 3.14159265358979323846
  64#endif
  65
  66GLUquadricObj *qobj;
  67
  68char leg = 0;
  69
  70int shoulder1 = 0, shoulder2 = 0, shoulder3 = 0, shoulder4 = 0, lat1 = 20, lat2 = 20,
  71  elbow1 = 0, elbow2 = 0, pivot = 0, tilt = 10, ankle1 = 0, ankle2 = 0, heel1 = 0,
  72  heel2 = 0, hip11 = 0, hip12 = 10, hip21 = 0, hip22 = 10, fire = 0, solid_part = 0,
  73  anim = 0, turn = 0, turn1 = 0, lightturn = 0, lightturn1 = 0;
  74
  75float elevation = 0.0, distance = 0.0, frame = 3.0
  76 /* foot1v[] = {} foot2v[] = {} */ ;
  77
  78/* end of motion variables */
  79
  80/* start of material definitions */
  81#ifdef LIGHT
  82GLfloat mat_specular[] =
  83{0.628281, 0.555802, 0.366065, 1.0};
  84GLfloat mat_ambient[] =
  85{0.24725, 0.1995, 0.0745, 1.0};
  86GLfloat mat_diffuse[] =
  87{0.75164, 0.60648, 0.22648, 1.0};
  88GLfloat mat_shininess[] =
  89{128.0 * 0.4};
  90
  91GLfloat mat_specular2[] =
  92{0.508273, 0.508273, 0.508373};
  93GLfloat mat_ambient2[] =
  94{0.19225, 0.19225, 0.19225};
  95GLfloat mat_diffuse2[] =
  96{0.50754, 0.50754, 0.50754};
  97GLfloat mat_shininess2[] =
  98{128.0 * 0.6};
  99
 100GLfloat mat_specular3[] =
 101{0.296648, 0.296648, 0.296648};
 102GLfloat mat_ambient3[] =
 103{0.25, 0.20725, 0.20725};
 104GLfloat mat_diffuse3[] =
 105{1, 0.829, 0.829};
 106GLfloat mat_shininess3[] =
 107{128.0 * 0.088};
 108
 109GLfloat mat_specular4[] =
 110{0.633, 0.727811, 0.633};
 111GLfloat mat_ambient4[] =
 112{0.0215, 0.1745, 0.0215};
 113GLfloat mat_diffuse4[] =
 114{0.07568, 0.61424, 0.07568};
 115GLfloat mat_shininess4[] =
 116{128 * 0.6};
 117
 118GLfloat mat_specular5[] =
 119{0.60, 0.60, 0.50};
 120GLfloat mat_ambient5[] =
 121{0.0, 0.0, 0.0};
 122GLfloat mat_diffuse5[] =
 123{0.5, 0.5, 0.0};
 124GLfloat mat_shininess5[] =
 125{128.0 * 0.25};
 126
 127#endif
 128/* end of material definitions */
 129
 130/* start of the body motion functions */
 131void
 132Heel1Add(void)
 133{
 134  heel1 = (heel1 + HEEL_RATE) % 360;
 135}
 136
 137void
 138Heel1Subtract(void)
 139{
 140  heel1 = (heel1 - HEEL_RATE) % 360;
 141}
 142
 143void
 144Heel2Add(void)
 145{
 146  heel2 = (heel2 + HEEL_RATE) % 360;
 147}
 148
 149void
 150Heel2Subtract(void)
 151{
 152  heel2 = (heel2 - HEEL_RATE) % 360;
 153}
 154
 155void
 156Ankle1Add(void)
 157{
 158  ankle1 = (ankle1 + ANKLE_RATE) % 360;
 159}
 160
 161void
 162Ankle1Subtract(void)
 163{
 164  ankle1 = (ankle1 - ANKLE_RATE) % 360;
 165}
 166
 167void
 168Ankle2Add(void)
 169{
 170  ankle2 = (ankle2 + ANKLE_RATE) % 360;
 171}
 172
 173void
 174Ankle2Subtract(void)
 175{
 176  ankle2 = (ankle2 - ANKLE_RATE) % 360;
 177}
 178
 179void
 180RotateAdd(void)
 181{
 182  pivot = (pivot + ROTATE_RATE) % 360;
 183}
 184
 185void
 186RotateSubtract(void)
 187{
 188  pivot = (pivot - ROTATE_RATE) % 360;
 189}
 190
 191void
 192MechTiltSubtract(void)
 193{
 194  tilt = (tilt - TILT_RATE) % 360;
 195}
 196
 197void
 198MechTiltAdd(void)
 199{
 200  tilt = (tilt + TILT_RATE) % 360;
 201}
 202
 203void
 204elbow1Add(void)
 205{
 206  elbow1 = (elbow1 + ELBOW_RATE) % 360;
 207}
 208
 209void
 210elbow1Subtract(void)
 211{
 212  elbow1 = (elbow1 - ELBOW_RATE) % 360;
 213}
 214
 215void
 216elbow2Add(void)
 217{
 218  elbow2 = (elbow2 + ELBOW_RATE) % 360;
 219}
 220
 221void
 222elbow2Subtract(void)
 223{
 224  elbow2 = (elbow2 - ELBOW_RATE) % 360;
 225}
 226
 227void
 228shoulder1Add(void)
 229{
 230  shoulder1 = (shoulder1 + SHOULDER_RATE) % 360;
 231}
 232
 233void
 234shoulder1Subtract(void)
 235{
 236  shoulder1 = (shoulder1 - SHOULDER_RATE) % 360;
 237}
 238
 239void
 240shoulder2Add(void)
 241{
 242  shoulder2 = (shoulder2 + SHOULDER_RATE) % 360;
 243}
 244
 245void
 246shoulder2Subtract(void)
 247{
 248  shoulder2 = (shoulder2 - SHOULDER_RATE) % 360;
 249}
 250
 251void
 252shoulder3Add(void)
 253{
 254  shoulder3 = (shoulder3 + SHOULDER_RATE) % 360;
 255}
 256
 257void
 258shoulder3Subtract(void)
 259{
 260  shoulder3 = (shoulder3 - SHOULDER_RATE) % 360;
 261}
 262
 263void
 264shoulder4Add(void)
 265{
 266  shoulder4 = (shoulder4 + SHOULDER_RATE) % 360;
 267}
 268
 269void
 270shoulder4Subtract(void)
 271{
 272  shoulder4 = (shoulder4 - SHOULDER_RATE) % 360;
 273}
 274
 275void
 276lat1Raise(void)
 277{
 278  lat1 = (lat1 + LAT_RATE) % 360;
 279}
 280
 281void
 282lat1Lower(void)
 283{
 284  lat1 = (lat1 - LAT_RATE) % 360;
 285}
 286
 287void
 288lat2Raise(void)
 289{
 290  lat2 = (lat2 + LAT_RATE) % 360;
 291}
 292
 293void
 294lat2Lower(void)
 295{
 296  lat2 = (lat2 - LAT_RATE) % 360;
 297}
 298
 299void
 300FireCannon(void)
 301{
 302  fire = (fire + CANNON_RATE) % 360;
 303}
 304
 305void
 306RaiseLeg1Forward(void)
 307{
 308  hip11 = (hip11 + UPPER_LEG_RATE) % 360;
 309}
 310
 311void
 312LowerLeg1Backwards(void)
 313{
 314  hip11 = (hip11 - UPPER_LEG_RATE) % 360;
 315}
 316
 317void
 318RaiseLeg1Outwards(void)
 319{
 320  hip12 = (hip12 + UPPER_LEG_RATE_GROIN) % 360;
 321}
 322
 323void
 324LowerLeg1Inwards(void)
 325{
 326  hip12 = (hip12 - UPPER_LEG_RATE_GROIN) % 360;
 327}
 328
 329void
 330RaiseLeg2Forward(void)
 331{
 332  hip21 = (hip21 + UPPER_LEG_RATE) % 360;
 333}
 334
 335void
 336LowerLeg2Backwards(void)
 337{
 338  hip21 = (hip21 - UPPER_LEG_RATE) % 360;
 339}
 340
 341void
 342RaiseLeg2Outwards(void)
 343{
 344  hip22 = (hip22 + UPPER_LEG_RATE_GROIN) % 360;
 345}
 346
 347void
 348LowerLeg2Inwards(void)
 349{
 350  hip22 = (hip22 - UPPER_LEG_RATE_GROIN) % 360;
 351}
 352
 353/* end of body motion functions */
 354
 355/* start of light source position functions */
 356void
 357TurnRight(void)
 358{
 359  turn = (turn - VIEW_TURN_RATE) % 360;
 360}
 361
 362void
 363TurnLeft(void)
 364{
 365  turn = (turn + VIEW_TURN_RATE) % 360;
 366}
 367
 368void
 369TurnForwards(void)
 370{
 371  turn1 = (turn1 - VIEW_TURN_RATE) % 360;
 372}
 373
 374void
 375TurnBackwards(void)
 376{
 377  turn1 = (turn1 + VIEW_TURN_RATE) % 360;
 378}
 379
 380void
 381LightTurnRight(void)
 382{
 383  lightturn = (lightturn + LIGHT_TURN_RATE) % 360;
 384}
 385
 386void
 387LightTurnLeft(void)
 388{
 389  lightturn = (lightturn - LIGHT_TURN_RATE) % 360;
 390}
 391
 392void
 393LightForwards(void)
 394{
 395  lightturn1 = (lightturn1 + LIGHT_TURN_RATE) % 360;
 396}
 397
 398void
 399LightBackwards(void)
 400{
 401  lightturn1 = (lightturn1 - LIGHT_TURN_RATE) % 360;
 402}
 403
 404/* end of light source position functions */
 405
 406/* start of geometric shape functions */
 407void
 408Box(float width, float height, float depth, char solid)
 409{
 410  char i, j = 0;
 411  float x = width / 2.0, y = height / 2.0, z = depth / 2.0;
 412
 413  for (i = 0; i < 4; i++) {
 414    glRotatef(90.0, 0.0, 0.0, 1.0);
 415    if (j) {
 416      if (!solid)
 417        glBegin(GL_LINE_LOOP);
 418      else
 419        glBegin(GL_QUADS);
 420      glNormal3f(-1.0, 0.0, 0.0);
 421      glVertex3f(-x, y, z);
 422      glVertex3f(-x, -y, z);
 423      glVertex3f(-x, -y, -z);
 424      glVertex3f(-x, y, -z);
 425      glEnd();
 426      if (solid) {
 427        glBegin(GL_TRIANGLES);
 428        glNormal3f(0.0, 0.0, 1.0);
 429        glVertex3f(0.0, 0.0, z);
 430        glVertex3f(-x, y, z);
 431        glVertex3f(-x, -y, z);
 432        glNormal3f(0.0, 0.0, -1.0);
 433        glVertex3f(0.0, 0.0, -z);
 434        glVertex3f(-x, -y, -z);
 435        glVertex3f(-x, y, -z);
 436        glEnd();
 437      }
 438      j = 0;
 439    } else {
 440      if (!solid)
 441        glBegin(GL_LINE_LOOP);
 442      else
 443        glBegin(GL_QUADS);
 444      glNormal3f(-1.0, 0.0, 0.0);
 445      glVertex3f(-y, x, z);
 446      glVertex3f(-y, -x, z);
 447      glVertex3f(-y, -x, -z);
 448      glVertex3f(-y, x, -z);
 449      glEnd();
 450      if (solid) {
 451        glBegin(GL_TRIANGLES);
 452        glNormal3f(0.0, 0.0, 1.0);
 453        glVertex3f(0.0, 0.0, z);
 454        glVertex3f(-y, x, z);
 455        glVertex3f(-y, -x, z);
 456        glNormal3f(0.0, 0.0, -1.0);
 457        glVertex3f(0.0, 0.0, -z);
 458        glVertex3f(-y, -x, -z);
 459        glVertex3f(-y, x, -z);
 460        glEnd();
 461      }
 462      j = 1;
 463    }
 464  }
 465}
 466
 467void
 468Octagon(float side, float height, char solid)
 469{
 470  char j;
 471  float x = sin(0.785398163) * side, y = side / 2.0, z = height / 2.0, c;
 472
 473  c = x + y;
 474  for (j = 0; j < 8; j++) {
 475    glTranslatef(-c, 0.0, 0.0);
 476    if (!solid)
 477      glBegin(GL_LINE_LOOP);
 478    else
 479      glBegin(GL_QUADS);
 480    glNormal3f(-1.0, 0.0, 0.0);
 481    glVertex3f(0.0, -y, z);
 482    glVertex3f(0.0, y, z);
 483    glVertex3f(0.0, y, -z);
 484    glVertex3f(0.0, -y, -z);
 485    glEnd();
 486    glTranslatef(c, 0.0, 0.0);
 487    if (solid) {
 488      glBegin(GL_TRIANGLES);
 489      glNormal3f(0.0, 0.0, 1.0);
 490      glVertex3f(0.0, 0.0, z);
 491      glVertex3f(-c, -y, z);
 492      glVertex3f(-c, y, z);
 493      glNormal3f(0.0, 0.0, -1.0);
 494      glVertex3f(0.0, 0.0, -z);
 495      glVertex3f(-c, y, -z);
 496      glVertex3f(-c, -y, -z);
 497      glEnd();
 498    }
 499    glRotatef(45.0, 0.0, 0.0, 1.0);
 500  }
 501}
 502
 503/* end of geometric shape functions */
 504#ifdef NORM
 505void
 506Normalize(float v[3])
 507{
 508  GLfloat d = sqrt(v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
 509
 510  if (d == 0.0) {
 511    printf("zero length vector");
 512    return;
 513  }
 514  v[1] /= d;
 515  v[2] /= d;
 516  v[3] /= d;
 517}
 518
 519void
 520NormXprod(float v1[3], float v2[3], float v[3], float out[3])
 521{
 522  GLint i, j;
 523  GLfloat length;
 524
 525  out[0] = v1[1] * v2[2] - v1[2] * v2[1];
 526  out[1] = v1[2] * v2[0] - v1[0] * v2[2];
 527  out[2] = v1[0] * v2[1] - v1[1] * v2[0];
 528  Normalize(out);
 529}
 530
 531#endif
 532
 533void
 534SetMaterial(GLfloat spec[], GLfloat amb[], GLfloat diff[], GLfloat shin[])
 535{
 536
 537  glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
 538  glMaterialfv(GL_FRONT, GL_SHININESS, shin);
 539  glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
 540  glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
 541}
 542
 543void
 544MechTorso(char solid)
 545{
 546  glNewList(SOLID_MECH_TORSO, GL_COMPILE);
 547#ifdef LIGHT
 548  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 549#endif
 550  glColor3f(1.0, 1.0, 0.0);
 551  Box(1.0, 1.0, 3.0, solid);
 552  glTranslatef(0.75, 0.0, 0.0);
 553#ifdef LIGHT
 554  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 555#endif
 556  glColor3f(0.5, 0.5, 0.5);
 557  Box(0.5, 0.6, 2.0, solid);
 558  glTranslatef(-1.5, 0.0, 0.0);
 559  Box(0.5, 0.6, 2.0, solid);
 560  glTranslatef(0.75, 0.0, 0.0);
 561  glEndList();
 562}
 563
 564void
 565MechHip(char solid)
 566{
 567  int i;
 568
 569  glNewList(SOLID_MECH_HIP, GL_COMPILE);
 570#ifdef LIGHT
 571  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 572#endif
 573  glColor3f(1.0, 1.0, 0.0);
 574  Octagon(0.7, 0.5, solid);
 575#ifdef SPHERE
 576  for (i = 0; i < 2; i++) {
 577    if (i)
 578      glScalef(-1.0, 1.0, 1.0);
 579    glTranslatef(1.0, 0.0, 0.0);
 580#ifdef LIGHT
 581    SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 582#endif
 583    glColor3f(0.5, 0.5, 0.5);
 584    if (!solid)
 585      gluQuadricDrawStyle(qobj, GLU_LINE);
 586    gluSphere(qobj, 0.2, 16, 16);
 587    glTranslatef(-1.0, 0.0, 0.0);
 588  }
 589  glScalef(-1.0, 1.0, 1.0);
 590#endif
 591  glEndList();
 592}
 593
 594void
 595Shoulder(char solid)
 596{
 597  glNewList(SOLID_MECH_SHOULDER, GL_COMPILE);
 598#ifdef LIGHT
 599  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 600#endif
 601  glColor3f(1.0, 1.0, 0.0);
 602  Box(1.0, 0.5, 0.5, solid);
 603  glTranslatef(0.9, 0.0, 0.0);
 604#ifdef LIGHT
 605  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 606#endif
 607  glColor3f(0.5, 0.5, 0.5);
 608#ifdef SPHERE
 609  if (!solid)
 610    gluQuadricDrawStyle(qobj, GLU_LINE);
 611  gluSphere(qobj, 0.6, 16, 16);
 612#endif
 613  glTranslatef(-0.9, 0.0, 0.0);
 614  glEndList();
 615}
 616
 617void
 618UpperArm(char solid)
 619{
 620  int i;
 621
 622  glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);
 623#ifdef LIGHT
 624  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 625#endif
 626  glColor3f(1.0, 1.0, 0.0);
 627  Box(1.0, 2.0, 1.0, solid);
 628  glTranslatef(0.0, -0.95, 0.0);
 629  glRotatef(90.0, 1.0, 0.0, 0.0);
 630#ifdef LIGHT
 631  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 632#endif
 633  glColor3f(0.5, 0.5, 0.5);
 634  if (!solid)
 635    gluQuadricDrawStyle(qobj, GLU_LINE);
 636  gluCylinder(qobj, 0.4, 0.4, 1.5, 16, 10);
 637#ifdef LIGHT
 638  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 639#endif
 640  glColor3f(1.0, 1.0, 0.0);
 641  glRotatef(-90.0, 1.0, 0.0, 0.0);
 642  glTranslatef(-0.4, -1.85, 0.0);
 643  glRotatef(90.0, 0.0, 1.0, 0.0);
 644  for (i = 0; i < 2; i++) {
 645    if (!solid)
 646      gluQuadricDrawStyle(qobj, GLU_LINE);
 647    if (i)
 648      gluCylinder(qobj, 0.5, 0.5, 0.8, 16, 10);
 649    else
 650      gluCylinder(qobj, 0.2, 0.2, 0.8, 16, 10);
 651  }
 652  for (i = 0; i < 2; i++) {
 653    if (i)
 654      glScalef(-1.0, 1.0, 1.0);
 655    if (!solid)
 656      gluQuadricDrawStyle(qobj, GLU_LINE);
 657    if (i)
 658      glTranslatef(0.0, 0.0, 0.8);
 659    gluDisk(qobj, 0.2, 0.5, 16, 10);
 660    if (i)
 661      glTranslatef(0.0, 0.0, -0.8);
 662  }
 663  glScalef(-1.0, 1.0, 1.0);
 664  glRotatef(-90.0, 0.0, 1.0, 0.0);
 665  glTranslatef(0.4, 2.9, 0.0);
 666  glEndList();
 667}
 668
 669void
 670VulcanGun(char solid)
 671{
 672  int i;
 673
 674  glNewList(SOLID_MECH_VULCAN, GL_COMPILE);
 675
 676#ifdef LIGHT
 677  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 678#endif
 679  glColor3f(0.5, 0.5, 0.5);
 680
 681  if (!solid) {
 682    gluQuadricDrawStyle(qobj, GLU_LINE);
 683  }
 684  gluCylinder(qobj, 0.5, 0.5, 0.5, 16, 10);
 685  glTranslatef(0.0, 0.0, 0.5);
 686  gluDisk(qobj, 0.0, 0.5, 16, 10);
 687
 688  for (i = 0; i < 5; i++) {
 689    glRotatef(72.0, 0.0, 0.0, 1.0);
 690    glTranslatef(0.0, 0.3, 0.0);
 691    if (!solid) {
 692      gluQuadricDrawStyle(qobj, GLU_LINE);
 693    }
 694    gluCylinder(qobj, 0.15, 0.15, 2.0, 16, 10);
 695    gluCylinder(qobj, 0.06, 0.06, 2.0, 16, 10);
 696    glTranslatef(0.0, 0.0, 2.0);
 697    gluDisk(qobj, 0.1, 0.15, 16, 10);
 698    gluCylinder(qobj, 0.1, 0.1, 0.1, 16, 5);
 699    glTranslatef(0.0, 0.0, 0.1);
 700    gluDisk(qobj, 0.06, 0.1, 16, 5);
 701    glTranslatef(0.0, -0.3, -2.1);
 702  }
 703  glEndList();
 704}
 705
 706void
 707ForeArm(char solid)
 708{
 709  char i;
 710
 711  glNewList(SOLID_MECH_FOREARM, GL_COMPILE);
 712#ifdef LIGHT
 713  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 714#endif
 715  glColor3f(1.0, 1.0, 0.0);
 716  for (i = 0; i < 5; i++) {
 717    glTranslatef(0.0, -0.1, -0.15);
 718    Box(0.6, 0.8, 0.2, solid);
 719    glTranslatef(0.0, 0.1, -0.15);
 720    Box(0.4, 0.6, 0.1, solid);
 721  }
 722  glTranslatef(0.0, 0.0, 2.45);
 723  Box(1.0, 1.0, 2.0, solid);
 724  glTranslatef(0.0, 0.0, -1.0);
 725  glEndList();
 726}
 727
 728void
 729UpperLeg(char solid)
 730{
 731  int i;
 732
 733  glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);
 734#ifdef LIGHT
 735  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 736#endif
 737  glColor3f(1.0, 1.0, 0.0);
 738  if (!solid) {
 739    gluQuadricDrawStyle(qobj, GLU_LINE);
 740  }
 741  glTranslatef(0.0, -1.0, 0.0);
 742  Box(0.4, 1.0, 0.7, solid);
 743  glTranslatef(0.0, -0.65, 0.0);
 744  for (i = 0; i < 5; i++) {
 745    Box(1.2, 0.3, 1.2, solid);
 746    glTranslatef(0.0, -0.2, 0.0);
 747    Box(1.0, 0.1, 1.0, solid);
 748    glTranslatef(0.0, -0.2, 0.0);
 749  }
 750  glTranslatef(0.0, -0.15, -0.4);
 751  Box(2.0, 0.5, 2.0, solid);
 752  glTranslatef(0.0, -0.3, -0.2);
 753  glRotatef(90.0, 1.0, 0.0, 0.0);
 754#ifdef LIGHT
 755  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 756#endif
 757  glColor3f(0.5, 0.5, 0.5);
 758  gluCylinder(qobj, 0.6, 0.6, 3.0, 16, 10);
 759#ifdef LIGHT
 760  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 761#endif
 762  glColor3f(1.0, 1.0, 0.0);
 763  glRotatef(-90.0, 1.0, 0.0, 0.0);
 764  glTranslatef(0.0, -1.5, 1.0);
 765  Box(1.5, 3.0, 0.5, solid);
 766  glTranslatef(0.0, -1.75, -0.8);
 767  Box(2.0, 0.5, 2.0, solid);
 768  glTranslatef(0.0, -0.9, -0.85);
 769#ifdef LIGHT
 770  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 771#endif
 772  glColor3f(0.5, 0.5, 0.5);
 773  gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);
 774  for (i = 0; i < 2; i++) {
 775    if (i)
 776      glScalef(-1.0, 1.0, 1.0);
 777    if (!solid)
 778      gluQuadricDrawStyle(qobj, GLU_LINE);
 779    if (i)
 780      glTranslatef(0.0, 0.0, 1.8);
 781    gluDisk(qobj, 0.0, 0.8, 16, 10);
 782    if (i)
 783      glTranslatef(0.0, 0.0, -1.8);
 784  }
 785  glScalef(-1.0, 1.0, 1.0);
 786  glEndList();
 787}
 788
 789void
 790Foot(char solid)
 791{
 792
 793  glNewList(SOLID_MECH_FOOT, GL_COMPILE);
 794#ifdef LIGHT
 795  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 796#endif
 797  glColor3f(0.5, 0.5, 0.5);
 798  glRotatef(90.0, 1.0, 0.0, 0.0);
 799  Octagon(1.5, 0.6, solid);
 800  glRotatef(-90.0, 1.0, 0.0, 0.0);
 801  glEndList();
 802}
 803
 804void
 805LowerLeg(char solid)
 806{
 807  float k, l;
 808
 809#ifdef LIGHT
 810  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 811#endif
 812  glColor3f(1.0, 1.0, 0.0);
 813  for (k = 0.0; k < 2.0; k++) {
 814    for (l = 0.0; l < 2.0; l++) {
 815      glPushMatrix();
 816      glTranslatef(k, 0.0, l);
 817#ifdef LIGHT
 818      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 819#endif
 820      glColor3f(1.0, 1.0, 0.0);
 821      Box(1.0, 0.5, 1.0, solid);
 822      glTranslatef(0.0, -0.45, 0.0);
 823#ifdef LIGHT
 824      SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 825#endif
 826      glColor3f(0.5, 0.5, 0.5);
 827#ifdef SPHERE
 828      if (!solid)
 829        glutWireSphere(0.2, 16, 10);
 830      else
 831        glutSolidSphere(0.2, 16, 10);
 832#endif
 833      if (leg)
 834        glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);
 835      else
 836        glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);
 837      /* glTranslatef(0.0, -0.2, 0.0); */
 838      glTranslatef(0.0, -1.7, 0.0);
 839#ifdef LIGHT
 840      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 841#endif
 842      glColor3f(1.0, 1.0, 0.0);
 843      Box(0.25, 3.0, 0.25, solid);
 844      glTranslatef(0.0, -1.7, 0.0);
 845#ifdef LIGHT
 846      SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 847#endif
 848      glColor3f(0.5, 0.5, 0.5);
 849#ifdef SPHERE
 850      if (!solid)
 851        glutWireSphere(0.2, 16, 10);
 852      else
 853        glutSolidSphere(0.2, 16, 10);
 854#endif
 855      if (leg)
 856        glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);
 857      else
 858        glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);
 859      glTranslatef(0.0, -0.45, 0.0);
 860#ifdef LIGHT
 861      SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 862#endif
 863      glColor3f(1.0, 1.0, 0.0);
 864      Box(1.0, 0.5, 1.0, solid);
 865      if (!k && !l) {
 866        int j;
 867
 868        glTranslatef(-0.4, -0.8, 0.5);
 869        if (leg)
 870          glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);
 871        else
 872          glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);
 873        glRotatef(90.0, 0.0, 1.0, 0.0);
 874        if (!solid)
 875          gluQuadricDrawStyle(qobj, GLU_LINE);
 876        gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);
 877        for (j = 0; j < 2; j++) {
 878          if (!solid)
 879            gluQuadricDrawStyle(qobj, GLU_LINE);
 880          if (j) {
 881            glScalef(-1.0, 1.0, 1.0);
 882            glTranslatef(0.0, 0.0, 1.8);
 883          }
 884          gluDisk(qobj, 0.0, 0.8, 16, 10);
 885          if (j)
 886            glTranslatef(0.0, 0.0, -1.8);
 887        }
 888        glScalef(-1.0, 1.0, 1.0);
 889        glRotatef(-90.0, 0.0, 1.0, 0.0);
 890        glTranslatef(0.95, -0.8, 0.0);
 891        glCallList(SOLID_MECH_FOOT);
 892      }
 893      glPopMatrix();
 894    }
 895  }
 896}
 897
 898void
 899RocketPod(char solid)
 900{
 901
 902  int i, j, k = 0;
 903
 904  glNewList(SOLID_MECH_ROCKET, GL_COMPILE);
 905#ifdef LIGHT
 906  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
 907#endif
 908  glColor3f(0.5, 0.5, 0.5);
 909  glScalef(0.4, 0.4, 0.4);
 910  glRotatef(45.0, 0.0, 0.0, 1.0);
 911  glTranslatef(1.0, 0.0, 0.0);
 912  Box(2.0, 0.5, 3.0, solid);
 913  glTranslatef(1.0, 0.0, 0.0);
 914  glRotatef(45.0, 0.0, 0.0, 1.0);
 915  glTranslatef(0.5, 0.0, 0.0);
 916  Box(1.2, 0.5, 3.0, solid);
 917  glTranslatef(2.1, 0.0, 0.0);
 918  glRotatef(-90.0, 0.0, 0.0, 1.0);
 919#ifdef LIGHT
 920  SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
 921#endif
 922  glColor3f(1.0, 1.0, 0.0);
 923  Box(2.0, 3.0, 4.0, solid);
 924  glTranslatef(-0.5, -1.0, 1.3);
 925  for (i = 0; i < 2; i++) {
 926    for (j = 0; j < 3; j++) {
 927      if (!solid) {
 928        gluQuadricDrawStyle(qobj, GLU_LINE);
 929      }
 930      glTranslatef(i, j, 0.6);
 931#ifdef LIGHT
 932      SetMaterial(mat_specular3, mat_ambient3, mat_diffuse3, mat_shininess3);
 933#endif
 934      glColor3f(1.0, 1.0, 1.0);
 935      gluCylinder(qobj, 0.4, 0.4, 0.3, 16, 10);
 936      glTranslatef(0.0, 0.0, 0.3);
 937#ifdef LIGHT
 938      SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);
 939#endif
 940      glColor3f(0.0, 1.0, 0.0);
 941      gluCylinder(qobj, 0.4, 0.0, 0.5, 16, 10);
 942      k++;
 943      glTranslatef(-i, -j, -0.9);
 944    }
 945  }
 946  glEndList();
 947}
 948
 949void
 950Enviro(char solid)
 951{
 952
 953  int i, j;
 954
 955  glNewList(SOLID_ENVIRO, GL_COMPILE);
 956  SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);
 957  glColor3f(0.0, 1.0, 0.0);
 958  Box(20.0, 0.5, 30.0, solid);
 959  SetMaterial(mat_specular4, mat_ambient3, mat_diffuse2, mat_shininess);
 960  glColor3f(0.6, 0.6, 0.6);
 961  glTranslatef(0.0, 0.0, -10.0);
 962  for (j = 0; j < 6; j++) {
 963    for (i = 0; i < 2; i++) {
 964      if (i)
 965        glScalef(-1.0, 1.0, 1.0);
 966      glTranslatef(10.0, 4.0, 0.0);
 967      Box(4.0, 8.0, 2.0, solid);
 968      glTranslatef(0.0, -1.0, -3.0);
 969      Box(4.0, 6.0, 2.0, solid);
 970      glTranslatef(-10.0, -3.0, 3.0);
 971    }
 972    glScalef(-1.0, 1.0, 1.0);
 973    glTranslatef(0.0, 0.0, 5.0);
 974  }
 975  glEndList();
 976}
 977
 978void
 979Toggle(void)
 980{
 981  if (solid_part)
 982    solid_part = 0;
 983  else
 984    solid_part = 1;
 985}
 986
 987void
 988disable(void)
 989{
 990  glDisable(GL_LIGHTING);
 991  glDisable(GL_DEPTH_TEST);
 992  glDisable(GL_NORMALIZE);
 993  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 994}
 995
 996void
 997lighting(void)
 998{
 999
1000  GLfloat position[] =
1001  {0.0, 0.0, 2.0, 1.0};
1002
1003#ifdef MOVE_LIGHT
1004  glRotatef((GLfloat) lightturn1, 1.0, 0.0, 0.0);
1005  glRotatef((GLfloat) lightturn, 0.0, 1.0, 0.0);
1006  glRotatef(0.0, 1.0, 0.0, 0.0);
1007#endif
1008  glEnable(GL_LIGHTING);
1009  glEnable(GL_LIGHT0);
1010  glEnable(GL_NORMALIZE);
1011  glDepthFunc(GL_LESS);
1012  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1013
1014  glLightfv(GL_LIGHT0, GL_POSITION, position);
1015  glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 80.0);
1016
1017  glTranslatef(0.0, 0.0, 2.0);
1018  glDisable(GL_LIGHTING);
1019  Box(0.1, 0.1, 0.1, 0);
1020  glEnable(GL_LIGHTING);
1021}
1022
1023void
1024DrawMech(void)
1025{
1026  int i, j;
1027
1028  glScalef(0.5, 0.5, 0.5);
1029  glPushMatrix();
1030  glTranslatef(0.0, -0.75, 0.0);
1031  glRotatef((GLfloat) tilt, 1.0, 0.0, 0.0);
1032
1033  glRotatef(90.0, 1.0, 0.0, 0.0);
1034#ifdef HIP
1035  glCallList(SOLID_MECH_HIP);
1036#endif
1037  glRotatef(-90.0, 1.0, 0.0, 0.0);
1038
1039  glTranslatef(0.0, 0.75, 0.0);
1040  glPushMatrix();
1041  glRotatef((GLfloat) pivot, 0.0, 1.0, 0.0);
1042  glPushMatrix();
1043#ifdef TORSO
1044  glCallList(SOLID_MECH_TORSO);
1045#endif
1046  glPopMatrix();
1047  glPushMatrix();
1048  glTranslatef(0.5, 0.5, 0.0);
1049#ifdef ROCKET_POD
1050  glCallList(SOLID_MECH_ROCKET);
1051#endif
1052  glPopMatrix();
1053  for (i = 0; i < 2; i++) {
1054    glPushMatrix();
1055    if (i)
1056      glScalef(-1.0, 1.0, 1.0);
1057    glTranslatef(1.5, 0.0, 0.0);
1058#ifdef SHOULDER
1059    glCallList(SOLID_MECH_SHOULDER);
1060#endif
1061    glTranslatef(0.9, 0.0, 0.0);
1062    if (i) {
1063      glRotatef((GLfloat) lat1, 0.0, 0.0, 1.0);
1064      glRotatef((GLfloat) shoulder1, 1.0, 0.0, 0.0);
1065      glRotatef((GLfloat) shoulder3, 0.0, 1.0, 0.0);
1066    } else {
1067      glRotatef((GLfloat) lat2, 0.0, 0.0, 1.0);
1068      glRotatef((GLfloat) shoulder2, 1.0, 0.0, 0.0);
1069      glRotatef((GLfloat) shoulder4, 0.0, 1.0, 0.0);
1070    }
1071    glTranslatef(0.0, -1.4, 0.0);
1072#ifdef UPPER_ARM
1073    glCallList(SOLID_MECH_UPPER_ARM);
1074#endif
1075    glTranslatef(0.0, -2.9, 0.0);
1076    if (i)
1077      glRotatef((GLfloat) elbow1, 1.0, 0.0, 0.0);
1078    else
1079      glRotatef((GLfloat) elbow2, 1.0, 0.0, 0.0);
1080    glTranslatef(0.0, -0.9, -0.2);
1081#ifdef LOWER_ARM
1082    glCallList(SOLID_MECH_FOREARM);
1083    glPushMatrix();
1084    glTranslatef(0.0, 0.0, 2.0);
1085    glRotatef((GLfloat) fire, 0.0, 0.0, 1.0);
1086    glCallList(SOLID_MECH_VULCAN);
1087    glPopMatrix();
1088#endif
1089    glPopMatrix();
1090  }
1091  glPopMatrix();
1092
1093  glPopMatrix();
1094
1095  for (j = 0; j < 2; j++) {
1096    glPushMatrix();
1097    if (j) {
1098      glScalef(-0.5, 0.5, 0.5);
1099      leg = 1;
1100    } else {
1101      glScalef(0.5, 0.5, 0.5);
1102      leg = 0;
1103    }
1104    glTranslatef(2.0, -1.5, 0.0);
1105    if (j) {
1106      glRotatef((GLfloat) hip11, 1.0, 0.0, 0.0);
1107      glRotatef((GLfloat) hip12, 0.0, 0.0, 1.0);
1108    } else {
1109      glRotatef((GLfloat) hip21, 1.0, 0.0, 0.0);
1110      glRotatef((GLfloat) hip22, 0.0, 0.0, 1.0);
1111    }
1112    glTranslatef(0.0, 0.3, 0.0);
1113#ifdef UPPER_LEG
1114    glPushMatrix();
1115    glCallList(SOLID_MECH_UPPER_LEG);
1116    glPopMatrix();
1117#endif
1118    glTranslatef(0.0, -8.3, -0.4);
1119    if (j)
1120      glRotatef((GLfloat) - hip12, 0.0, 0.0, 1.0);
1121    else
1122      glRotatef((GLfloat) - hip22, 0.0, 0.0, 1.0);
1123    glTranslatef(-0.5, -0.85, -0.5);
1124#ifdef LOWER_LEG
1125    LowerLeg(1);
1126#endif
1127    glPopMatrix();
1128  }
1129}
1130
1131void
1132display(void)
1133{
1134  glClearColor(0.0, 0.0, 0.0, 0.0);
1135  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1136  glEnable(GL_DEPTH_TEST);
1137
1138  glPushMatrix();
1139  glRotatef((GLfloat) turn, 0.0, 1.0, 0.0);
1140  glRotatef((GLfloat) turn1, 1.0, 0.0, 0.0);
1141#ifdef LIGHT
1142  if (solid_part) {
1143    glPushMatrix();
1144    lighting();
1145    glPopMatrix();
1146  } else
1147    disable();
1148#endif
1149#ifdef DRAW_MECH
1150  glPushMatrix();
1151  glTranslatef(0.0, elevation, 0.0);
1152  DrawMech();
1153  glPopMatrix();
1154#endif
1155#ifdef DRAW_ENVIRO
1156  glPushMatrix();
1157  if (distance >= 20.136)
1158    distance = 0.0;
1159  glTranslatef(0.0, -5.0, -distance);
1160  glCallList(SOLID_ENVIRO);
1161  glTranslatef(0.0, 0.0, 10.0);
1162  glCallList(SOLID_ENVIRO);
1163  glPopMatrix();
1164#endif
1165  glPopMatrix();
1166  glFlush();
1167  glutSwapBuffers();
1168}
1169
1170void
1171myinit(void)
1172{
1173  char i = 1;
1174
1175  qobj = gluNewQuadric();
1176#ifdef LIGHT
1177  SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
1178#endif
1179  glEnable(GL_DEPTH_TEST);
1180  MechTorso(i);
1181  MechHip(i);
1182  Shoulder(i);
1183  RocketPod(i);
1184  UpperArm(i);
1185  ForeArm(i);
1186  UpperLeg(i);
1187  Foot(i);
1188  VulcanGun(i);
1189  Enviro(i);
1190}
1191
1192void
1193myReshape(int w, int h)
1194{
1195  glViewport(0, 0, w, h);
1196  glMatrixMode(GL_PROJECTION);
1197  glLoadIdentity();
1198  gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 1.0, 20.0);
1199  glMatrixMode(GL_MODELVIEW);
1200  glLoadIdentity();
1201  glTranslatef(0.0, 1.2, -5.5);  /* viewing transform  */
1202}
1203
1204#ifdef ANIMATION
1205void
1206animation_walk(void)
1207{
1208  float angle;
1209  static int step;
1210
1211  if (step == 0 || step == 2) {
1212    /* for(frame=3.0; frame<=21.0; frame=frame+3.0){ */
1213    if (frame >= 0.0 && frame <= 21.0) {
1214      if (frame == 0.0)
1215        frame = 3.0;
1216      angle = (180 / M_PI) * 
1217	(acos(((cos((M_PI / 180) * frame) * 2.043) + 1.1625) / 3.2059));
1218      if (frame > 0) {
1219        elevation = -(3.2055 - (cos((M_PI / 180) * angle) * 3.2055));
1220      } else
1221        elevation = 0.0;
1222      if (step == 0) {
1223        hip11 = -(frame * 1.7);
1224        if (1.7 * frame > 15)
1225          heel1 = frame * 1.7;
1226        heel2 = 0;
1227        ankle1 = frame * 1.7;
1228        if (frame > 0)
1229          hip21 = angle;
1230        else
1231          hip21 = 0;
1232        ankle2 = -hip21;
1233        shoulder1 = frame * 1.5;
1234        shoulder2 = -frame * 1.5;
1235        elbow1 = frame;
1236        elbow2 = -frame;
1237      } else {
1238        hip21 = -(frame * 1.7);
1239        if (1.7 * frame > 15)
1240          heel2 = frame * 1.7;
1241        heel1 = 0;
1242        ankle2 = frame * 1.7;
1243        if (frame > 0)
1244          hip11 = angle;
1245        else
1246          hip11 = 0;
1247        ankle1 = -hip11;
1248        shoulder1 = -frame * 1.5;
1249        shoulder2 = frame * 1.5;
1250        elbow1 = -frame;
1251        elbow2 = frame;
1252      }
1253      if (frame == 21)
1254        step++;
1255      if (frame < 21)
1256        frame = frame + 3.0;
1257    }
1258  }
1259  if (step == 1 || step == 3) {
1260    /* for(x=21.0; x>=0.0; x=x-3.0){ */
1261    if (frame <= 21.0 && frame >= 0.0) {
1262      angle = (180 / M_PI) * 
1263	(acos(((cos((M_PI / 180) * frame) * 2.043) + 1.1625) / 3.2029));
1264      if (frame > 0)
1265        elevation = -(3.2055 - (cos((M_PI / 180) * angle) * 3.2055));
1266      else
1267        elevation = 0.0;
1268      if (step == 1) {
1269        elbow2 = hip11 = -frame;
1270        elbow1 = heel1 = frame;
1271        heel2 = 15;
1272        ankle1 = frame;
1273        if (frame > 0)
1274          hip21 = angle;
1275        else
1276          hip21 = 0;
1277        ankle2 = -hip21;
1278        shoulder1 = 1.5 * frame;
1279        shoulder2 = -frame * 1.5;
1280      } else {
1281        elbow1 = hip21 = -frame;
1282        elbow2 = heel2 = frame;
1283        heel1 = 15;
1284        ankle2 = frame;
1285        if (frame > 0)
1286          hip11 = angle;
1287        else
1288          hip11 = 0;
1289        ankle1 = -hip11;
1290        shoulder1 = -frame * 1.5;
1291        shoulder2 = frame * 1.5;
1292      }
1293      if (frame == 0.0)
1294        step++;
1295      if (frame > 0)
1296        frame = frame - 3.0;
1297    }
1298  }
1299  if (step == 4)
1300    step = 0;
1301  distance += 0.1678;
1302  glutPostRedisplay();
1303}
1304
1305void
1306animation(void)
1307{
1308  animation_walk();
1309}
1310
1311#endif
1312
1313#ifdef GLUT
1314#ifdef GLUT_KEY
1315/* ARGSUSED1 */
1316void
1317keyboard(unsigned char key, int x, int y)
1318{
1319
1320  int i = 0;
1321
1322  switch (key) {
1323    /* start arm control functions */
1324  case 'q':{
1325      shoulder2Subtract();
1326      i++;
1327    }
1328    break;
1329  case 'a':{
1330      shoulder2Add();
1331      i++;
1332    }
1333    break;
1334  case 'w':{
1335      shoulder1Subtract();
1336      i++;
1337    }
1338    break;
1339  case 's':{
1340      shoulder1Add();
1341      i++;
1342    }
1343    break;
1344  case '2':{
1345      shoulder3Add();
1346      i++;
1347    }
1348    break;
1349  case '1':{
1350      shoulder4Add();
1351      i++;
1352    }
1353    break;
1354  case '4':{
1355      shoulder3Subtract();
1356      i++;
1357    }
1358    break;
1359  case '3':{
1360      shoulder4Subtract();
1361      i++;
1362    }
1363    break;
1364
1365  case 'z':{
1366      lat2Raise();
1367      i++;
1368    }
1369    break;
1370  case 'Z':{
1371      lat2Lower();
1372      i++;
1373    }
1374    break;
1375  case 'x':{
1376      lat1Raise();
1377      i++;
1378    }
1379    break;
1380  case 'X':{
1381      lat1Lower();
1382      i++;
1383    }
1384    break;
1385
1386  case 'A':{
1387      elbow2Add();
1388      i++;
1389    }
1390    break;
1391  case 'Q':{
1392      elbow2Subtract();
1393      i++;
1394    }
1395    break;
1396  case 'S':{
1397      elbow1Add();
1398      i++;
1399    }
1400    break;
1401  case 'W':{
1402      elbow1Subtract();
1403      i++;
1404    }
1405    break;
1406    /* end of arm control functions */
1407
1408    /* start of torso control functions */
1409  case 'd':{
1410      RotateAdd();
1411      i++;
1412    }
1413    break;
1414  case 'g':{
1415      RotateSubtract();
1416      i++;
1417    }
1418    break;
1419  case 'r':{
1420      MechTiltAdd();
1421      i++;
1422    }
1423    break;
1424  case 'f':{
1425      MechTiltSubtract();
1426      i++;
1427    }
1428    break;
1429    /* end of torso control functions */
1430
1431    /* start of leg control functions */
1432  case 'h':{
1433      RaiseLeg2Forward();
1434      i++;
1435    }
1436    break;
1437  case 'y':{
1438      LowerLeg2Backwards();
1439      i++;
1440    }
1441    break;
1442  case 'Y':{
1443      RaiseLeg2Outwards();
1444      i++;
1445    }
1446    break;
1447  case 'H':{
1448      LowerLeg2Inwards();
1449      i++;
1450    }
1451    break;
1452
1453  case 'j':{
1454      RaiseLeg1Forward();
1455      i++;
1456    }
1457    break;
1458  case 'u':{
1459      LowerLeg1Backwards();
1460      i++;
1461    }
1462    break;
1463  case 'U':{
1464      RaiseLeg1Outwards();
1465      i++;
1466    }
1467    break;
1468  case 'J':{
1469      LowerLeg1Inwards();
1470      i++;
1471    }
1472    break;
1473
1474  case 'N':{
1475      Heel2Add();
1476      i++;
1477    }
1478    break;
1479  case 'n':{
1480      Heel2Subtract();
1481      i++;
1482    }
1483    break;
1484  case 'M':{
1485      Heel1Add();
1486      i++;
1487    }
1488    break;
1489  case 'm':{
1490      Heel1Subtract();
1491      i++;
1492    }
1493    break;
1494
1495  case 'k':{
1496      Ankle2Add();
1497      i++;
1498    }
1499    break;
1500  case 'K':{
1501      Ankle2Subtract();
1502      i++;
1503    }
1504    break;
1505  case 'l':{
1506      Ankle1Add();
1507      i++;
1508    }
1509    break;
1510  case 'L':{
1511      Ankle1Subtract();
1512      i++;
1513    }
1514    break;
1515    /* end of leg control functions */
1516
1517    /* start of light source position functions */
1518  case 'p':{
1519      LightTurnRight();
1520      i++;
1521    }
1522    break;
1523  case 'i':{
1524      LightTurnLeft();
1525      i++;
1526    }
1527    break;
1528  case 'o':{
1529      LightForwards();
1530      i++;
1531    }
1532    break;
1533  case '9':{
1534      LightBackwards();
1535      i++;
1536    }
1537    break;
1538    /* end of light source position functions */
1539  }
1540  if (i)
1541    glutPostRedisplay();
1542}
1543
1544#endif
1545
1546#ifdef GLUT_SPEC
1547/* ARGSUSED1 */
1548void
1549special(int key, int x, int y)
1550{
1551
1552  int i = 0;
1553
1554  switch (key) {
1555    /* start of view position functions */
1556  case GLUT_KEY_RIGHT:{
1557      TurnRight();
1558      i++;
1559    }
1560    break;
1561  case GLUT_KEY_LEFT:{
1562      TurnLeft();
1563      i++;
1564    }
1565    break;
1566  case GLUT_KEY_DOWN:{
1567      TurnForwards();
1568      i++;
1569    }
1570    break;
1571  case GLUT_KEY_UP:{
1572      TurnBackwards();
1573      i++;
1574    }
1575    break;
1576    /* end of view positions functions */
1577    /* start of miscellaneous functions */
1578  case GLUT_KEY_PAGE_UP:{
1579      FireCannon();
1580      i++;
1581    }
1582    break;
1583    /* end of miscellaneous functions */
1584  }
1585  if (i)
1586    glutPostRedisplay();
1587}
1588
1589#endif
1590#endif
1591void
1592menu_select(int mode)
1593{
1594  switch (mode) {
1595#ifdef ANIMATION
1596  case 1:
1597    glutIdleFunc(animation);
1598    break;
1599#endif
1600  case 2:
1601    glutIdleFunc(NULL);
1602    break;
1603  case 3:
1604    Toggle();
1605    glutPostRedisplay();
1606    break;
1607  case 4:
1608    exit(EXIT_SUCCESS);
1609  }
1610}
1611
1612/* ARGSUSED */
1613void
1614null_select(int mode)
1615{
1616}
1617
1618void
1619glutMenu(void)
1620{
1621
1622  int glut_menu[13];
1623
1624  glut_menu[5] = glutCreateMenu(null_select);
1625  glutAddMenuEntry("forward       : q,w", 0);
1626  glutAddMenuEntry("backwards     : a,s", 0);
1627  glutAddMenuEntry("outwards      : z,x", 0);
1628  glutAddMenuEntry("inwards       : Z,X", 0);
1629
1630  glut_menu[6] = glutCreateMenu(null_select);
1631  glutAddMenuEntry("upwards       : Q,W", 0);
1632  glutAddMenuEntry("downwards     : A,S", 0);
1633  glutAddMenuEntry("outwards      : 1,2", 0);
1634  glutAddMenuEntry("inwards       : 3,4", 0);
1635
1636  glut_menu[1] = glutCreateMenu(null_select);
1637  glutAddMenuEntry(" : Page_up", 0);
1638
1639  glut_menu[8] = glutCreateMenu(null_select);
1640  glutAddMenuEntry("forward       : y,u", 0);
1641  glutAddMenuEntry("backwards     : h.j", 0);
1642  glutAddMenuEntry("outwards      : Y,U", 0);
1643  glutAddMenuEntry("inwards       : H,J", 0);
1644
1645  glut_menu[9] = glutCreateMenu(null_select);
1646  glutAddMenuEntry("forward       : n,m", 0);
1647  glutAddMenuEntry("backwards     : N,M", 0);
1648
1649  glut_menu[9] = glutCreateMenu(null_select);
1650  glutAddMenuEntry("forward       : n,m", 0);
1651  glutAddMenuEntry("backwards     : N,M", 0);
1652
1653  glut_menu[10] = glutCreateMenu(null_select);
1654  glutAddMenuEntry("toes up       : K,L", 0);
1655  glutAddMenuEntry("toes down     : k,l", 0);
1656
1657  glut_menu[11] = glutCreateMenu(null_select);
1658  glutAddMenuEntry("right         : right arrow", 0);
1659  glutAddMenuEntry("left          : left arrow", 0);
1660  glutAddMenuEntry("down          : up arrow", 0);
1661  glutAddMenuEntry("up            : down arrow", 0);
1662
1663  glut_menu[12] = glutCreateMenu(null_select);
1664  glutAddMenuEntry("right         : p", 0);
1665  glutAddMenuEntry("left          : i", 0);
1666  glutAddMenuEntry("up            : 9", 0);
1667  glutAddMenuEntry("down          : o", 0);
1668
1669  glut_menu[4] = glutCreateMenu(NULL);
1670  glutAddSubMenu("at the shoulders? ", glut_menu[5]);
1671  glutAddSubMenu("at the elbows?", glut_menu[6]);
1672
1673  glut_menu[7] = glutCreateMenu(NULL);
1674  glutAddSubMenu("at the hip? ", glut_menu[8]);
1675  glutAddSubMenu("at the knees?", glut_menu[9]);
1676  glutAddSubMenu("at the ankles? ", glut_menu[10]);
1677
1678  glut_menu[2] = glutCreateMenu(null_select);
1679  glutAddMenuEntry("turn left    : d", 0);
1680  glutAddMenuEntry("turn right    : g", 0);
1681
1682  glut_menu[3] = glutCreateMenu(null_select);
1683  glutAddMenuEntry("tilt backwards : f", 0);
1684  glutAddMenuEntry("tilt forwards  : r", 0);
1685
1686  glut_menu[0] = glutCreateMenu(NULL);
1687  glutAddSubMenu("move the arms.. ", glut_menu[4]);
1688  glutAddSubMenu("fire the vulcan guns?", glut_menu[1]);
1689  glutAddSubMenu("move the legs.. ", glut_menu[7]);
1690  glutAddSubMenu("move the torso?", glut_menu[2]);
1691  glutAddSubMenu("move the hip?", glut_menu[3]);
1692  glutAddSubMenu("rotate the scene..", glut_menu[11]);
1693#ifdef MOVE_LIGHT
1694  glutAddSubMenu("rotate the light source..", glut_menu[12]);
1695#endif
1696
1697  glutCreateMenu(menu_select);
1698#ifdef ANIMATION
1699  glutAddMenuEntry("Start Walk", 1);
1700  glutAddMenuEntry("Stop Walk", 2);
1701#endif
1702  glutAddMenuEntry("Toggle Wireframe", 3);
1703  glutAddSubMenu("How do I ..", glut_menu[0]);
1704  glutAddMenuEntry("Quit", 4);
1705  glutAttachMenu(GLUT_LEFT_BUTTON);
1706  glutAttachMenu(GLUT_RIGHT_BUTTON);
1707}
1708
1709int
1710main(int argc, char **argv)
1711{
1712#ifdef GLUT
1713  /* start of glut windowing and control functions */
1714  glutInit(&argc, argv);
1715  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
1716  glutInitWindowSize(800, 600);
1717  glutCreateWindow("glutmech: Vulcan Gunner");
1718  myinit();
1719  glutDisplayFunc(display);
1720  glutReshapeFunc(myReshape);
1721#ifdef GLUT_KEY
1722  glutKeyboardFunc(keyboard);
1723#endif
1724#ifdef GLUT_SPEC
1725  glutSpecialFunc(special);
1726#endif
1727  glutMenu();
1728  glutMainLoop();
1729  /* end of glut windowing and control functions */
1730#endif
1731  return 0;             
1732}
1733
1734