home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_11 / wiredemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-05  |  4.3 KB  |  187 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <io.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <bios.h>
  10. #include <fcntl.h>
  11. #include <memory.h>
  12. #include <malloc.h>
  13. #include <math.h>
  14. #include <string.h>
  15. #include <search.h>             // this one is needed for qsort()
  16.  
  17. // include all of our stuff
  18.  
  19. #include "black3.h"
  20. #include "black4.h"
  21. #include "black5.h"
  22. #include "black6.h"
  23. #include "black8.h"
  24. #include "black9.h"
  25. #include "black11.h"
  26.  
  27. // G L O B A L S /////////////////////////////////////////////////////////////
  28.  
  29. object test_object;   // the test object
  30.  
  31. // M A I N ////////////////////////////////////////////////////////////////////
  32.  
  33. void main(int argc,char **argv)
  34. {
  35.  
  36. int index,   // looping variable
  37.     done=0;  // exit flag
  38.  
  39. char buffer[80]; // used to print strings
  40.  
  41. // load in the object from the command line
  42.  
  43. if (!PLG_Load_Object(&test_object,argv[1],1))
  44.    {
  45.    printf("\nCouldn't find file %s",argv[1]);
  46.    return;
  47.  
  48.    } // end if
  49.  
  50. // position the object
  51.  
  52. test_object.world_pos.x = 0;
  53. test_object.world_pos.y = 0;
  54. test_object.world_pos.z = 300;
  55.  
  56. // create the sin/cos lookup tables used for the rotation function
  57.  
  58. Build_Look_Up_Tables();
  59.  
  60. // set graphics to mode 13h
  61.  
  62. Set_Graphics_Mode(GRAPHICS_MODE13);
  63.  
  64. // allocate double buffer
  65.  
  66. Create_Double_Buffer(200);
  67.  
  68. // install the isr keyboard driver
  69.  
  70. Keyboard_Install_Driver();
  71.  
  72. // set viewing distance
  73.  
  74. viewing_distance = 250;
  75.  
  76. // main event loop
  77.  
  78. while(!done)
  79.      {
  80.  
  81.      // compute starting time of this frame
  82.  
  83.      starting_time = Timer_Query();
  84.  
  85.      // erase the screen
  86.  
  87.      Fill_Double_Buffer(0);
  88.  
  89.      // test what key(s) user is pressing
  90.  
  91.      // test if user is moving object to right
  92.  
  93.      if (keyboard_state[MAKE_RIGHT])
  94.         test_object.world_pos.x+=5;
  95.  
  96.      // test if user is moving object to left
  97.  
  98.      if (keyboard_state[MAKE_LEFT])
  99.         test_object.world_pos.x-=5;
  100.  
  101.      // test if user is moving object up
  102.  
  103.      if (keyboard_state[MAKE_UP])
  104.         test_object.world_pos.y-=5;
  105.  
  106.      // test if user is moving object down
  107.  
  108.      if (keyboard_state[MAKE_DOWN])
  109.         test_object.world_pos.y+=5;
  110.  
  111.      // test if user is moving object farther
  112.  
  113.      if (keyboard_state[MAKE_PGUP])
  114.         test_object.world_pos.z+=15;
  115.  
  116.      // test if user is moving object nearer
  117.  
  118.      if (keyboard_state[MAKE_PGDWN])
  119.         test_object.world_pos.z-=15;
  120.  
  121.      // test for exit key
  122.  
  123.      if (keyboard_state[MAKE_ESC])
  124.         done=1;
  125.  
  126.  
  127.      // rotate the object on all three axes
  128.  
  129.      Rotate_Object((object_ptr)&test_object,2,4,6);
  130.  
  131. //////////////////////////////////////////////////////////////////////////////
  132.  
  133.      // convert the local coordinates into camera coordinates for projection
  134.      // note the viewer is at (0,0,0) with angles 0,0,0 so the transformaton
  135.      // is simply to add the world position to each local vertex
  136.  
  137.      for (index=0; index<test_object.num_vertices; index++)
  138.          {
  139.  
  140.          test_object.vertices_camera[index].x =
  141.                    test_object.vertices_local[index].x+test_object.world_pos.x;
  142.  
  143.          test_object.vertices_camera[index].y =
  144.                    test_object.vertices_local[index].y+test_object.world_pos.y;
  145.  
  146.          test_object.vertices_camera[index].z =
  147.                    test_object.vertices_local[index].z+test_object.world_pos.z;
  148.  
  149.          } // end for index
  150.  
  151. //////////////////////////////////////////////////////////////////////////////
  152.  
  153.      // draw the object
  154.  
  155.      Draw_Object_Wire((object_ptr)&test_object);
  156.  
  157.      // print out position of object
  158.  
  159.      sprintf(buffer,"Object is at (%d,%d,%d)     ",(int)test_object.world_pos.x,
  160.                                                    (int)test_object.world_pos.y,
  161.                                                    (int)test_object.world_pos.z);
  162.  
  163.      Print_String_DB(0,0,9,buffer,0);
  164.  
  165.      // display double buffer
  166.  
  167.      Display_Double_Buffer(double_buffer,0);
  168.  
  169.      // lock onto 18 frames per second max
  170.  
  171.      while((Timer_Query()-starting_time)<1);
  172.  
  173.      } // end while
  174.  
  175. // restore graphics mode back to text
  176.  
  177. Set_Graphics_Mode(TEXT_MODE);
  178.  
  179. // restore the old keyboard driver
  180.  
  181. Keyboard_Remove_Driver();
  182.  
  183. } // end main
  184.  
  185.  
  186.  
  187.