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

  1. /* COMPLETELY rewritten by Dave Stampe Dec. 1993, */
  2. /* used to be render.c, now split off to uservid.c and this file */
  3.  
  4. // This code is the refresh-screen call.  All the other stuff was
  5. // moved to uservid.c
  6. // Also has Dave's axis-compass (much improved) and the new
  7. // prerender/postrender support (implemented in USCREEN.C)
  8.  
  9. /*
  10.  This code is part of the VR-386 project, created by Dave Stampe.
  11.  VR-386 is a desendent of REND386, created by Dave Stampe and
  12.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  13.  Stampre for VR-386.
  14.  
  15.  Copyright (c) 1994 by Dave Stampe:
  16.  May be freely used to write software for release into the public domain
  17.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  18.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  19.  this software or source code into their products!  Usually there is no
  20.  charge for under 50-100 items for low-cost or shareware products, and terms
  21.  are reasonable.  Any royalties are used for development, so equipment is
  22.  often acceptable payment.
  23.  
  24.  ATTRIBUTION:  If you use any part of this source code or the libraries
  25.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  26.  and any other authors in your documentation, source code, and at startup
  27.  of your program.  Let's keep the freeware ball rolling!
  28.  
  29.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  30.  REND386, improving programmer access by rewriting the code and supplying
  31.  a standard API.  If you write improvements, add new functions rather
  32.  than rewriting current functions.  This will make it possible to
  33.  include you improved code in the next API release.  YOU can help advance
  34.  VR-386.  Comments on the API are welcome.
  35.  
  36.  CONTACT: dstampe@psych.toronto.edu
  37. */
  38.  
  39.  
  40.  
  41. /* Contact:  dstampe@sunee.waterloo.edu or broehl@sunee.waterloo.edu or*/
  42.  
  43. #include <stdio.h>
  44. #include <dos.h>
  45. #include <stdlib.h>    /* labs */
  46.  
  47. #include "f3dkitd.h"
  48.  
  49. #include "vr_api.h"
  50. #include "intmath.h"
  51. #include "splits.h"
  52.  
  53. #define MAIN_VGA  1  /* for multi-VGA only */
  54. #define LEFT_VGA  2
  55. #define RIGHT_VGA 4
  56. #define ALL_VGA   7
  57.  
  58. #define MONOSCOPIC 0 /* stereo types */
  59. #define SWITCHED   1
  60. #define SPLITLR    3
  61. #define SEPARATE   5
  62.  
  63. extern struct Screeninfo *screeninfo;
  64.  
  65. extern int swap_eyes;
  66.  
  67. extern int show_location, show_compass, show_framerate;  // options
  68. extern int use_glove;
  69.  
  70. extern void user_draw_line(int x1, int y1, int x2, int y2, int color);
  71.  
  72.  
  73.  
  74. //////////////////////////////////////////
  75. ///  THESE ROUTINES LET YOU CONTROL HOW THE
  76. ///  SCREEN IS CLEARED AND WHAT IS DISPLAYED
  77. ///  THE ARGUMENTS ARE:
  78. ///  v : the view being draw.  left/right eye views are different
  79. ///  vpage: the video page being drawn
  80. ///  isfirst, islast:  1 if this is the first/last access to the
  81. ///                    video page.  Useful for toggling screen
  82. ///               clears etc. when several views are on the
  83. ///               same page
  84. ///  whicheye:  0 for left eye/mono, 1 for right eye view
  85. ///
  86.  
  87.     // This is called before drawing objects.  It should
  88.     // at least clear the screen
  89.  
  90. void prerender_process(VIEW *v, WORD vpage, WORD isfirst, WORD whicheye)
  91. {
  92.   extern LIGHT *std_lights[3];
  93.   setup_lights(std_lights,3);
  94.   horizon(v,vpage);   // clear window anyhoo
  95. }
  96.  
  97.  
  98.     // This is called after drawing objects.  It can be used
  99.     // to put up status, etc.
  100.     // lots of if() stuff, but just because we're supporting
  101.     // so many stereo types
  102.  
  103. void postrender_process(VIEW *v, WORD vpage, WORD islast, WORD whicheye)
  104. {
  105.   status_on_screen();
  106.  
  107.   if(islast)
  108.     {
  109.       coord_ref(screeninfo->xmax-70, screeninfo->ymin+70,35,v,15,13,10,0);
  110.       status_on_screen();
  111.     }
  112.  
  113.   if (show_framerate && islast)    // display the frame rate
  114.     {
  115.       char c[69];
  116.       sprintf(c,"Frames/sec: %d",get_ticks_per_second()/last_render_time());
  117.       user_text(screeninfo->xmin+5,screeninfo->ymax-20,15,c);
  118.     }
  119.  
  120.   if (stereo_type==SPLITLR && islast )
  121.     {
  122. //      extern int highest_color;          // split-screen line for windows
  123. //      user_draw_line(splitlx1, splitly1, splitlx2, splitly2, highest_color);
  124.     }
  125.  
  126.   if(stereo_type==SEPARATE || stereo_type==SWITCHED)  // eye labels
  127.     {
  128.       if(whicheye==LEFT_EYE)
  129.       user_text(screeninfo->xmin+20,screeninfo->ymin+10,0,"L");
  130.       else
  131.       user_text(screeninfo->xmax-30,screeninfo->ymin+10,0,"R");
  132.     }
  133.  
  134. }
  135.  
  136.  
  137. int status_on_screen(void)
  138. {
  139.   char buff[100];
  140.   AREA *a, *what_area();
  141.   char *area_name(AREA *);
  142.   POSE p;
  143.   BOOL was_visible = cursor_hide();
  144.  
  145.   if (show_location == 0) return 0;
  146.  
  147.   get_camera_worldpose(current_camera,&p);
  148.  
  149.   sprintf(buff, "Pos(x,z): %ld,%ld", p.x, p.z);
  150.   shadowprint(2,3,15,buff);
  151.   sprintf(buff, "Not in any area");
  152.   a = what_area(global_world_root, body_pose->x, body_pose->y, body_pose->z);
  153.   if (a)
  154.     {
  155.       char *p = area_name(a);
  156.       if (p)
  157.     {
  158.       sprintf(buff, "Area: %s", p);
  159.       shadowprint(2,15,15,buff);
  160.     }
  161.     }
  162.  
  163.   if (use_glove)
  164.     {
  165.       char *c = get_glove_gesture_name();
  166.       if (c)
  167.     {
  168.       int sl;
  169.       sprintf(buff,"Glove: %s",c);
  170.       sl = strlen(buff)<<3;
  171.       shadowprint(300-sl,3,15,buff);
  172.     }
  173.     }
  174.   if(was_visible) cursor_show();
  175.   return 0;
  176. }
  177.  
  178.