home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / crend5 / cyberman.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-15  |  5.0 KB  |  260 lines

  1. // This cyberman interface code is written by Joseph D. Gradecki of
  2. // PCVR Magazine.  Give us a call at 608-877-0909 or our BBS at
  3. // 608-877-1017
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include "cyberman.h"
  8. #include "rend386.h"
  9. #include "intmath.h"
  10.  
  11. #define to_rad(a) ((a) * 3.14159262 / 180.0)
  12. #define sine(x)   sin(to_rad(x/65536L))
  13. #define cosine(x) cos(to_rad(x/65536L))
  14.  
  15.  
  16. extern cyberman_info cyberman_data;
  17. extern VIEW *current_view;
  18. extern int redraw;
  19. extern SEGMENT *body_seg;
  20.  
  21. int cyberman_step = 50;
  22. long cyberman_angle = 2*65536L;
  23.  
  24. int get_SWIFT_static ( cyberman_static_data *data)
  25. {
  26.   struct REGPACK r;
  27.  
  28.   r.r_ax = 0x53C1;
  29.   r.r_es = FP_SEG(data);
  30.   r.r_dx = FP_OFF(data);        // This is DX not DI -- 12-14-93 Joe
  31.   intr(0x33, &r);
  32.  
  33.   if (r.r_ax == 1) return 1;
  34.   else return 0;
  35. }
  36.  
  37. int cyberman_available()
  38. {
  39.   cyberman_static_data data;
  40.  
  41.   get_SWIFT_static (&data);
  42.   if ( data.device_type == 1 ) return 1;
  43.   else return 0;
  44. }
  45.  
  46.  
  47.  
  48. void get_SWIFT_dynamic(unsigned *data)
  49. {
  50.   union REGS r;
  51.  
  52.   r.x.ax = 0x53C2;
  53.   int86(0x33, &r, &r);
  54.   printf ( "%d\n", r.x.ax );
  55.   *data = r.x.ax;
  56. }
  57.  
  58.  
  59. void get_cyberman_data (cyberman_info *data)
  60. {
  61.   struct REGPACK r;
  62.  
  63.   r.r_ax = 0x5301;
  64.   r.r_es = FP_SEG(data);
  65.   r.r_dx = FP_OFF(data);        // This is DX not DI -- 12-14-93 Joe
  66.   intr(0x33, &r);
  67.  
  68. }
  69.  
  70.  
  71. void set_cyberman_event(void *routine)
  72. {
  73.  
  74.   cyberman_static_data data;
  75.   struct REGPACK r;
  76.  
  77.   get_SWIFT_static (&data);
  78.  
  79.   r.r_ax = 0xC0;
  80.   r.r_cx = 0xFFFF;
  81.   r.r_es = FP_SEG(routine);
  82.   r.r_dx = FP_OFF(routine);        // This is DX not DI -- 12-14-93
  83.   intr(0x33, &r);
  84.  
  85. /* Upon a call from the interrupt, the registers in the routine passed above
  86.    will have the following values:
  87.  
  88.    AX= Event bits    0 - Mouse cursor changed
  89.             1 - left button pressed
  90.             2 - left button released
  91.             3 - right button pressed
  92.             4 - right button released
  93.             5 - middle button pressed
  94.             6 - middle button released
  95.             7 - other button pressed
  96.             8 - other button released
  97.             9 - X coordinate changed
  98.             10 - Y coordinate changed
  99.             11 - Z coordinate changed
  100.             12 - pitch changed
  101.             13 - roll changed
  102.             14 - yaw changed
  103.             15 - 'other' condition
  104.  
  105.    BX = button status
  106.    CX = Horizontal cursor position
  107.    DX = Vertical cursor position
  108.    SI = Address of extended information block which contains following data:
  109.  
  110.             Word 0 = X coordinate value
  111.             Word 1 = Y coordinate value
  112.             Word 2 = Z coordinate value
  113.             Word 3 = Pitch value
  114.             Word 4 = Roll value
  115.             Word 5 = Yaw value
  116.             Word 6 = Button Status
  117.             Word 7 = Dynamic Device Data word
  118.  
  119.    SS:SP = stack pointer
  120.    DS = data segment of mouse driver - Save and load appropriately
  121. */
  122. }
  123.  
  124.  
  125. void remove_cyberman_event()
  126. {
  127.   struct REGPACK r;
  128.  
  129.   r.r_ax = 0xC0;
  130.   r.r_cx = 0;
  131.   intr(0x33, &r);
  132. }
  133.  
  134. /*
  135. void main()
  136. {
  137.   cyberman_info  cyberman_data;
  138.  
  139.   printf ( "Cyberman %d\n", cyberman_available());
  140.  
  141.   while (!kbhit())
  142.   {
  143.     get_cyberman_data (&cyberman_data);
  144.     printf ( "%d %d %d  %d %d %d %d\n", cyberman_data.x,
  145.                     cyberman_data.y,
  146.                     cyberman_data.z,
  147.                     cyberman_data.yaw,
  148.                     cyberman_data.pitch,
  149.                     cyberman_data.roll,
  150.                     cyberman_data.button );
  151.  
  152.   }
  153.  
  154. }
  155. */
  156.  
  157. void check_cyberman(cyberman_info *data)
  158. {
  159.   if (!cyberman_available())
  160.   {
  161.     printf ( "\nCyberman was not found!\n");
  162.     delay (2000);
  163.   }
  164.  
  165.   get_cyberman_data (data);
  166.   data->center_x = data->x;
  167.   data->center_y = data->y;
  168. }
  169.  
  170.  
  171. void get_cyberman(cyberman_info *data)
  172. {
  173.   long x,y,z;
  174.   MATRIX n;
  175.  
  176.   get_cyberman_data (data);
  177.  
  178.   //Pitch
  179.   if (data->pitch > 0)
  180.   {
  181.     current_view->tilt -= cyberman_angle;
  182.   }
  183.   else if (data->pitch < 0)
  184.   {
  185.     current_view->tilt += cyberman_angle;
  186.   }
  187.  
  188.   //Roll
  189.   if (data->roll > 0)
  190.   {
  191.     current_view->roll += cyberman_angle;
  192.   }
  193.   else if (data->roll < 0)
  194.   {
  195.     current_view->roll -= cyberman_angle;
  196.   }
  197.  
  198.  
  199.   //Yaw
  200.   if (data->yaw > 0)
  201.   {
  202.     current_view->pan -= cyberman_angle;
  203.   }
  204.   else if (data->yaw < 0)
  205.   {
  206.     current_view->pan += cyberman_angle;
  207.   }
  208.  
  209.  
  210.   //Z
  211.   if (data->z < 0)
  212.     current_view->ey -= cyberman_step;
  213.   else if (data->z > 0)
  214.     current_view->ey += cyberman_step;
  215.  
  216.   //X
  217.   if (data->y > data->center_y+1500)
  218.   {
  219.     x = y = 0;
  220.     z = cyberman_step;
  221.  
  222.     std_matrix(n, 0, current_view->pan, 0, 0, 0, 0);
  223.     matrix_point(n, &x, &y, &z);
  224.     current_view->ex += x;
  225.     current_view->ez += z;
  226.   }
  227.   else if (data->y < (data->center_y-1000))
  228.   {
  229.     x = y = 0;
  230.     z = cyberman_step;
  231.  
  232.     std_matrix(n, 0, current_view->pan, 0, 0, 0, 0);
  233.     matrix_point(n, &x, &y, &z);
  234.     current_view->ez -= z;
  235.   }
  236.  
  237.  
  238.   if (data->x > (data->center_x+1000))
  239.   {
  240.     x = cyberman_step;
  241.     y = z = 0;
  242.  
  243.     std_matrix(n, 0, current_view->pan, 0, 0, 0, 0);
  244.     matrix_point(n, &x, &y, &z);
  245.     current_view->ex += x;
  246.   }
  247.   else if (data->x < (data->center_x-1000))
  248.   {
  249.     x = -cyberman_step;
  250.     y = z = 0;
  251.  
  252.     std_matrix(n, 0, current_view->pan, 0, 0, 0, 0);
  253.     matrix_point(n, &x, &y, &z);
  254.     current_view->ex += x;
  255.   }
  256.  
  257.   redraw = 1;
  258. }
  259.  
  260.