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

  1. // THESE ARE ROUTINES FOR THE MINI DEMO
  2. // Loads 3 x figures (not in world), 1 x object (in world)
  3. // A,B,C keys toggle figures in and out of world
  4.  
  5. /*
  6.  This code is part of the VR-386 project, created by Dave Stampe.
  7.  VR-386 is a desendent of REND386, created by Dave Stampe and
  8.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  9.  Stampre for VR-386.
  10.  
  11.  Copyright (c) 1994 by Dave Stampe:
  12.  May be freely used to write software for release into the public domain
  13.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  14.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  15.  this software or source code into their products!  Usually there is no
  16.  charge for under 50-100 items for low-cost or shareware products, and terms
  17.  are reasonable.  Any royalties are used for development, so equipment is
  18.  often acceptable payment.
  19.  
  20.  ATTRIBUTION:  If you use any part of this source code or the libraries
  21.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  22.  and any other authors in your documentation, source code, and at startup
  23.  of your program.  Let's keep the freeware ball rolling!
  24.  
  25.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  26.  REND386, improving programmer access by rewriting the code and supplying
  27.  a standard API.  If you write improvements, add new functions rather
  28.  than rewriting current functions.  This will make it possible to
  29.  include you improved code in the next API release.  YOU can help advance
  30.  VR-386.  Comments on the API are welcome.
  31.  
  32.  CONTACT: dstampe@psych.toronto.edu
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>  /* for atol(), only for debugging! */
  37. #include <dos.h>
  38.  
  39. #include "config.h"
  40. #include "vr_api.h"
  41. #include "intmath.h"
  42. #include "vrconst.h"
  43.  
  44. extern char *fix_fname(char *fname);
  45.  
  46. char *figname[3] = {"metalman.fig", "metalman.fig", "metalman.fig"} ;
  47.  
  48. OBJECT *figs[3] = {NULL,NULL,NULL};     // roots of figures
  49.  
  50.                     // map hue of objects on loading
  51. SURFACEPAIR figmaps[3][6] = {
  52.  0x800,0x100, 0x900,0x200, 0xa00,0x300, 0xb00,0x400, 0xc00,0x500, 0xd00,0x600,
  53.  0x800,0xf00, 0x900,0xe00, 0xa00,0xd00, 0xb00,0xc00, 0xc00,0xb00, 0xd00,0xa00,
  54.  0x800,0xb00, 0x900,0xa00, 0xa00,0x900, 0xb00,0x800, 0xc00,0x700, 0xd00,0x600
  55.                 };
  56.                             // 2000000L == 30 degrees
  57. POSE figpose[3] = {-1500, 0, -3000, 0, -2000000L,  2000000L,
  58.                0, 0, -3000, 0,        0L,        0L,
  59.             1500, 0, -3000, 0,  2000000L, -2000000L   };
  60.  
  61. BOOL fig_in_world[3] = {1,1,1};
  62.  
  63. minidemo_load()
  64. {
  65.   int i;
  66.   OBJECT *obj;
  67.   FILE *fig;
  68.  
  69.   for(i=0;i<3;i++)
  70.     {
  71.       if(!(fig = fopen(figname[i],"r"))) continue;
  72.       obj = load_figure_as_object(fig, default_objlist, NULL, 0, 1, 1, 1);
  73.       if (obj)
  74.     {
  75.       figs[i] = obj;
  76.       objlist_remap_surface(default_objlist, &(figmaps[i][0]), 6, MAP_HUE_MASK, MAP_HUE_MASK);
  77.       set_object_pose(figs[i], &figpose[i]);
  78.       update_object(figs[i]);
  79.       if(fig_in_world[i])
  80.           add_objlist_to_world(default_objlist);
  81.       else
  82.           merge_objlists(default_objlist, inactive_object_list);
  83.     }
  84.       fclose(fig);
  85.     }
  86. }
  87.  
  88.  
  89. toggle_figure(int i)
  90. {
  91.   if(i>2) return;
  92.   fig_in_world[i] = !fig_in_world[i];
  93.   if(fig_in_world[i])
  94.      do_for_all_child_objects(figs[i], add_object_to_world);
  95.   else
  96.      do_for_all_child_objects(figs[i], remove_object_from_world);
  97.   world_changed++;
  98. }
  99.  
  100.  
  101. /*************** MINI DEMO MENU **************/
  102.  
  103. static char *minimenu[] = {
  104.     "figure A",
  105.     "figure B",
  106.     "figure C",
  107.     "Quit",
  108.     NULL
  109. };
  110.  
  111.  
  112. BOOL process_minidemo_keys(unsigned c)    // processes quit, etc
  113. {
  114.   int i, j;
  115.  
  116.   switch (c)
  117.     {
  118.     case 'Q':
  119.     case ESC:
  120.         popmsg("Really quit?");
  121.         i = get_response(1);
  122.         if (toupper(i)=='Y') running = 0;
  123.         else restore_screen();
  124.         break;
  125.     case 'A':
  126.     case 'B':
  127.     case 'C':
  128.         toggle_figure(c-'A');    // figure toggle
  129.         break;
  130.     case 'X':
  131.         {
  132.           process_a_key(menu(minimenu));  // mini menu callup
  133.           restore_screen();
  134.           break;
  135.         }
  136.     default:
  137.         return FALSE;
  138.     }
  139.   return TRUE;
  140. }
  141.  
  142.