home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / BGICLA.ZIP / DISPLAY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  1.6 KB  |  54 lines

  1. /*************************************************************************
  2.     Listing 2 - DISPLAY.CPP
  3.  
  4.     Written by: Kevin D. Weeks, April 17, 1990
  5.     Released to the Public Domain.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <math.h>
  11. #include "display.hpp"
  12.  
  13.  
  14. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  15.     Constructor - as coded, this constructor relies on the initgraph()
  16.     function provided with the BGI to detect the display type and
  17.     initialize it to the highest graphics mode. once this has been
  18.     accomplished, the scaling factors for the virtual world are
  19.     determined. the default virtual_size is 1000.
  20. */
  21. Graphics_Display::Graphics_Display(char *path, const int world_size)
  22. {
  23.     int     mode;
  24.     int     ret_code;
  25.     int     x_aspect, y_aspect;
  26.  
  27.     driver = DETECT;
  28.     // initialize graphics driver
  29.     initgraph(&driver,&mode,path);
  30.     if ((ret_code = graphresult()) != grOk)
  31.     {
  32.         printf("Error initializing graphics: %s\n\a",grapherrormsg(ret_code));
  33.         exit(1);
  34.     }
  35.  
  36.     // set up virtual world
  37.     virtual_size = (double)world_size;
  38.     getaspectratio(&x_aspect,&y_aspect);
  39.     aspect_ratio = (float)x_aspect / 10000.0;
  40.     max_x = getmaxx() + 1;
  41.     max_y = getmaxy() + 1;
  42.     x_scale = ((float)max_x / virtual_size) * aspect_ratio;
  43.     y_scale = ((float)max_y / virtual_size);
  44. }
  45.  
  46. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  47.     this function (not a method) rounds a floating point number off to the
  48.     nearest whole number.
  49. */
  50. double  round(double value)
  51. {
  52.     return floor(value + 0.5);
  53. }
  54.