home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter54 / xsharp18.exe / MOVEOBJ.C < prev    next >
Text File  |  1992-04-04  |  3KB  |  70 lines

  1. /* Rotates and moves polygon-based objects (only balls, at the moment). */
  2. #include "polygon.h"
  3.  
  4. #define X_BALL_MOVE 1.0
  5. #define Y_BALL_MOVE 1.0
  6. #define Z_BALL_MOVE 4.0
  7.  
  8. void RotateAndMoveBall(PObject * ObjectToMove)
  9. {
  10.    /* Rotate the ball as needed */
  11.    if (--ObjectToMove->RDelayCount == 0) {   /* rotate */
  12.       ObjectToMove->RDelayCount = ObjectToMove->RDelayCountBase;
  13.       if (ObjectToMove->Rotate.RotateX != 0.0)
  14.          AppendRotationX(ObjectToMove->XformToWorld,
  15.                ObjectToMove->Rotate.RotateX);
  16.       if (ObjectToMove->Rotate.RotateY != 0.0)
  17.          AppendRotationY(ObjectToMove->XformToWorld,
  18.                ObjectToMove->Rotate.RotateY);
  19.       if (ObjectToMove->Rotate.RotateZ != 0.0)
  20.          AppendRotationZ(ObjectToMove->XformToWorld,
  21.                ObjectToMove->Rotate.RotateZ);
  22.       ObjectToMove->RecalcXform = 1;
  23.    }
  24.  
  25.    /* Move the ball in response to recorded key events */
  26.    if (BallEvent & MOVE_LEFT) {
  27.       if (ObjectToMove->XformToWorld[0][3] > DOUBLE_TO_FIXED(-15000.0)) {
  28.          ObjectToMove->XformToWorld[0][3] -= DOUBLE_TO_FIXED(X_BALL_MOVE);
  29.          ObjectToMove->RecalcXform = 1;
  30.       }
  31.       BallEvent &= ~MOVE_LEFT;
  32.    }
  33.    if (BallEvent & MOVE_RIGHT) {
  34.       if (ObjectToMove->XformToWorld[0][3] < DOUBLE_TO_FIXED(15000.0)) {
  35.          ObjectToMove->XformToWorld[0][3] += DOUBLE_TO_FIXED(X_BALL_MOVE);
  36.          ObjectToMove->RecalcXform = 1;
  37.       }
  38.       BallEvent &= ~MOVE_RIGHT;
  39.    }
  40.    if (BallEvent & MOVE_UP) {
  41.       if (ObjectToMove->XformToWorld[1][3] < DOUBLE_TO_FIXED(15000.0)) {
  42.          ObjectToMove->XformToWorld[1][3] += DOUBLE_TO_FIXED(Y_BALL_MOVE);
  43.          ObjectToMove->RecalcXform = 1;
  44.       }
  45.       BallEvent &= ~MOVE_UP;
  46.    }
  47.    if (BallEvent & MOVE_DOWN) {
  48.       if (ObjectToMove->XformToWorld[1][3] > DOUBLE_TO_FIXED(-15000.0)) {
  49.          ObjectToMove->XformToWorld[1][3] -= DOUBLE_TO_FIXED(Y_BALL_MOVE);
  50.          ObjectToMove->RecalcXform = 1;
  51.       }
  52.       BallEvent &= ~MOVE_DOWN;
  53.    }
  54.    if (BallEvent & MOVE_TOWARD) {
  55.       if (ObjectToMove->XformToWorld[2][3] < DOUBLE_TO_FIXED(-100.0)) {
  56.          ObjectToMove->XformToWorld[2][3] += DOUBLE_TO_FIXED(Z_BALL_MOVE);
  57.          ObjectToMove->RecalcXform = 1;
  58.       }
  59.       BallEvent &= ~MOVE_TOWARD;
  60.    }
  61.    if (BallEvent & MOVE_AWAY) {
  62.       if (ObjectToMove->XformToWorld[2][3] > DOUBLE_TO_FIXED(-15000.0)) {
  63.          ObjectToMove->XformToWorld[2][3] -= DOUBLE_TO_FIXED(Z_BALL_MOVE);
  64.          ObjectToMove->RecalcXform = 1;
  65.       }
  66.       BallEvent &= ~MOVE_AWAY;
  67.    }
  68. }
  69.  
  70.