home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / mini / minimain.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  6KB  |  229 lines

  1. // This is the main program of the VR-386 port of
  2. // the REND386 V5.0 demo program.  It may be used as
  3. // a template for your own software.  Some changed
  4. // to INIT.C may also be needed.
  5.  
  6. // 9/1/94 by Dave Stampe
  7.  
  8. // THIS IS FOR THE MINI-PROGRAM DEMO
  9.  
  10.  
  11. /*
  12.  This code is part of the VR-386 project, created by Dave Stampe.
  13.  VR-386 is a desendent of REND386, created by Dave Stampe and
  14.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  15.  Stampre for VR-386.
  16.  
  17.  Copyright (c) 1994 by Dave Stampe:
  18.  May be freely used to write software for release into the public domain
  19.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  20.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  21.  this software or source code into their products!  Usually there is no
  22.  charge for under 50-100 items for low-cost or shareware products, and terms
  23.  are reasonable.  Any royalties are used for development, so equipment is
  24.  often acceptable payment.
  25.  
  26.  ATTRIBUTION:  If you use any part of this source code or the libraries
  27.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  28.  and any other authors in your documentation, source code, and at startup
  29.  of your program.  Let's keep the freeware ball rolling!
  30.  
  31.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  32.  REND386, improving programmer access by rewriting the code and supplying
  33.  a standard API.  If you write improvements, add new functions rather
  34.  than rewriting current functions.  This will make it possible to
  35.  include you improved code in the next API release.  YOU can help advance
  36.  VR-386.  Comments on the API are welcome.
  37.  
  38.  CONTACT: dstampe@psych.toronto.edu
  39. */
  40.  
  41.  
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <math.h>
  46. #include <ctype.h>   /* toupper() */
  47. #include <string.h>
  48. #include <mem.h>     /* memmove() */
  49. #include <dos.h>
  50. #include <alloc.h>   /* coreleft */
  51.  
  52. #include "pointer.h"
  53. #include "vr_api.h"
  54. #include "intmath.h"
  55. #include "pcdevice.h"
  56. #include "splits.h"
  57. #include "oldtasks.h"
  58. #include "vrconst.h"
  59.  
  60. #include "f3dkitd.h"  /* for load_dac_colors() */
  61.  
  62.  
  63. BOOL running = 0;
  64. BOOL in_graphics = 0;
  65.  
  66. /************* STEREOSCOPIC DATA ***************/
  67.  
  68. extern STEREO default_stereo;
  69. extern WORD stereo_type;
  70.  
  71. /************ OPTIONS FLAGS ***************/
  72.  
  73. extern int use_ht;
  74.  
  75. // KEEP AROUND FOR CONFIG EVEN THOUGH NOT USED
  76. extern int have_ptr;
  77. extern int have_glove;
  78.  
  79. extern int use_BW;
  80. extern int swap_eyes;
  81. extern int use_glove;
  82.  
  83. //TASK *tasklist = NULL;
  84.  
  85.  
  86. int mouse_nav = 0;    // use mouse as joystick
  87. extern use_keyjoy;    // use keys as joystick
  88.  
  89. int flymode = 1;    // ALWAYS IN FLYMODE FOR MINI DEMO
  90.  
  91. // some options
  92.  
  93. int animatemode = 1;
  94. int do_horizon = 1;
  95. int show_location = 1; /* if set, we display the current location on-screen */
  96. int show_compass = 1; /* if set, we display the 3-D compass on-screen */
  97. int show_framerate = 1; /* if set, we display the frames/second rate */
  98. int do_screen_clear = 1; /* by default, we clear the screen on each frame */
  99. int use_frame = 0; /* if set, draw a "frame" */
  100.  
  101.  
  102.  
  103. // some test values
  104.  
  105. unsigned hcolors[20] = { 0xaf, 0xae, 0xad, 0xac, 0x79, 0x7a, 0x7b, 0x7c };
  106.  
  107. test_h()
  108. {
  109.  set_horizon(8, hcolors, 48);
  110. }
  111.  
  112. /************8 MINI DEMO CODE ************/
  113.  
  114.  
  115. LIGHT *std_lights[3];  // default lights for the world
  116. LIGHT *amb_light;      // copied from WPARSE.C (not in MINIDEMO)
  117. LIGHT * light1;
  118. LIGHT * light2;
  119.  
  120. void create_default_lights()
  121. {
  122.   POSE p = {1000, 15000, -5000, 0, 0, 0};
  123.   std_lights[0] = amb_light = create_light(NULL,AMBIENT_LIGHT,64);
  124.   std_lights[1] = light1 = create_light(NULL,POINT_LIGHT,64);
  125.   position_pointlight(light1,&p);
  126.   std_lights[2] = light2 = create_light(NULL,POINT_LIGHT,0);
  127.   p.x = -4000;
  128.   position_pointlight(light2,&p);
  129. }
  130.  
  131.  
  132. static void title_screen() // MINI DEMO: SIMPLE TITLE
  133. {
  134.   clrscr();
  135.   printf(" Mini VR-386 DEMO PROGRAM \n\n");
  136. }
  137.  
  138. static void wait_for_title()
  139. {
  140.  printf("\nPress a key to start...\n");
  141.  getch();
  142. }
  143.  
  144.  
  145.  
  146. /********** CLOSE PROGRAM ***********/
  147.  
  148. static char *closing_msg[] = {
  149.     "",
  150.     NULL };
  151.  
  152.  
  153. void wrap(void) /* end program */
  154. {
  155.     int i;
  156.     exit_handler();
  157.     for (i = 0; closing_msg[i]; ++i)
  158.        fprintf(stderr, "%s\n", closing_msg[i]);
  159. }
  160.  
  161.  
  162.  
  163.  
  164. /************** MAIN PROGRAM ***************/
  165.  
  166.  
  167. refresh_display()
  168. {
  169.   update_body_links();
  170.   screen_refresh(current_camera);
  171.  
  172.   position_changed = 0;
  173.   world_changed = 0;
  174.   display_changed = 0;
  175. }
  176.  
  177.  
  178. void main(int argc, char *argv[])
  179. {
  180.   int i;
  181.   long t;
  182.  
  183.   if (getenv("REND386"))                     // start up path
  184.     strcpy(loadpath, getenv("REND386"));
  185.  
  186.   title_screen();              // title screen
  187.  
  188.   preload_initialize(argc, argv);
  189.  
  190.   create_default_lights();   // WE'LL USE DEFAULTS, BUT BRING OUT OF WPARSE
  191.  
  192.   read_input_files(argc, argv);     // get any files to be loaded
  193.  
  194.   atexit(wrap);
  195.  
  196.   minidemo_load();
  197.  
  198.   load_memory_report();
  199.  
  200.   wait_for_title();
  201.  
  202.   video_initialize();
  203.  
  204.   device_initialize();
  205.  
  206.   test_h();  // TEST MULTI HORIZON
  207.  
  208.   running = 1;
  209.   while (running)    // THE EXECUTE LOOP
  210.     {
  211.         // process any keys (do BEFORE joystick_process)
  212.        key_process();
  213.         // mouse joy device mode
  214.        joy_set_mode( ((mouse_nav!=0)?MJOY_ENABLE:0) | ((flymode!=0)?MJOY_VELOCITY:0) );
  215.         // navigate
  216.        joystick_process();
  217.         // menu, object selection: do AFTER joy (mouse counters)
  218.        mouse_process();
  219.         // head tracker
  220.        if (use_ht) head_tracker_process(0);
  221.         // gloves, 3D pointers
  222.  
  223.         // update screen if needed
  224.        if (position_changed || display_changed || world_changed)
  225.          refresh_display();
  226.      }
  227. }
  228.  
  229.