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