home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / FGL112B.ZIP / USER04.DOC < prev    next >
Text File  |  1992-10-05  |  12KB  |  296 lines

  1.  
  2.  
  3. Chapter 4
  4.  
  5. Coordinate Systems
  6. 40  Fastgraph User's Guide
  7.  
  8.  
  9. Overview
  10.  
  11.      Fastgraph uses three coordinate systems to perform text and graphics
  12. output.  These coordinate systems are character space, screen space, and
  13. world space.  The world space coordinate system is not available with
  14. Fastgraph/Light.
  15.  
  16.  
  17. Character Space
  18.  
  19.      The coordinate system used for displaying characters is called character
  20. space.  Fastgraph uses character space for displaying characters in both text
  21. and graphics video modes.  It can be thought of as a grid of rows and
  22. columns, with each cell in the grid holding one character.  Each cell is
  23. identified by its unique (row,column) integer coordinates.  The rows and
  24. columns are numbered starting at zero; the origin is always the upper left
  25. corner of the screen.  For example, in the 80-column by 25-row text modes (2,
  26. 3, and 7), the (row,column) coordinates of the screen corners are shown in
  27. the following diagram.
  28.  
  29.                             (0,0)           (0,79)
  30.  
  31.  
  32.                             (24,0)         (24,79)
  33.  
  34. The number of rows and columns depends on the video mode, as shown in the
  35. following table.  For graphics modes, the table also includes the width and
  36. height in pixels of a character cell.
  37.  
  38.  
  39.                        Mode  No. of  No. of Char. Char.
  40.                       Number Columns Rows   Width Height
  41.  
  42.                          0     40     25
  43.                          1     40     25
  44.                          2     80     25
  45.                          3     80     25
  46.                          4     40     25    8     8
  47.                          5     40     25    8     8
  48.                          6     80     25    8     8
  49.                          7     80     25
  50.                          9     40     25    8     8
  51.                         11     80     25    9     14
  52.                         12     40     25    8     8
  53.                         13     40     25    8     8
  54.                         14     80     25    8     8
  55.                         15     80     25    8     14
  56.                         16     80     25    8     14
  57.                         17     80     30    8     16
  58.                         18     80     30    8     16
  59.                         19     40     25    8     8
  60.                         20     40     25    8     8
  61.                         21     40     50    8     8
  62.                         22     40     30    8     8
  63.                         23     40     60    8     8
  64.  
  65.                                             Chapter 4:  Coordinate Systems  41
  66.  
  67.  
  68.      Fastgraph includes two routines, fg_getmaxx and fg_getmaxy, that
  69. respectively return the maximum column and row numbers in text modes.
  70. Example 4-1 demonstrates these two routines in a text mode.  The program uses
  71. fg_getmaxx and fg_getmaxy to obtain the maximum column and row numbers in
  72. mode 3.  It then displays these values (79 and 24).
  73.  
  74.                                  Example 4-1.
  75.  
  76.                     #include <fastgraf.h>
  77.                     #include <stdio.h>
  78.                     void main(void);
  79.  
  80.                     void main()
  81.                     {
  82.                        int max_col;
  83.                        int max_row;
  84.                        int mode;
  85.  
  86.                        mode = fg_getmode();
  87.                        fg_setmode(3);
  88.  
  89.                        max_col = fg_getmaxx();
  90.                        max_row = fg_getmaxy();
  91.  
  92.                        fg_setmode(mode);
  93.                        fg_reset();
  94.  
  95.                        printf("Last col = %d\n",max_col);
  96.                        printf("Last row = %d\n",max_row);
  97.                     }
  98.  
  99.  
  100.  
  101. Screen Space
  102.  
  103.      Screen space is one of two available coordinate systems in graphics
  104. modes.  It uses the physical device coordinates.  Screen space can be thought
  105. of as a grid of rows and columns, with each unit in the grid holding one
  106. pixel.  Each pixel is identified by its unique (x,y) integer coordinates.
  107. The rows and columns are numbered starting at zero; the origin is always the
  108. upper left corner of the screen.  For example, in the 320 by 200 graphics
  109. modes, the (x,y) coordinates of the screen corners are shown in the following
  110. diagram.
  111.  
  112.                             (0,0)          (319,0)
  113.  
  114.  
  115.                             (0,199)      (319,199)
  116.  
  117.      The Fastgraph routines fg_getmaxx and fg_getmaxy return the maximum x
  118. and y screen coordinates when used in graphics modes, as shown in example
  119. 42  Fastgraph User's Guide
  120.  
  121. 4-2.  The program uses fg_getmaxx and fg_getmaxy to obtain the maximum x and
  122. y coordinates in the standard CGA four-color graphics mode (mode 4).  It then
  123. displays these values (319 and 199).
  124.  
  125.                                  Example 4-2.
  126.  
  127.                       #include <fastgraf.h>
  128.                       #include <stdio.h>
  129.                       void main(void);
  130.  
  131.                       void main()
  132.                       {
  133.                          int maxx;
  134.                          int maxy;
  135.                          int mode;
  136.  
  137.                          mode = fg_getmode();
  138.                          fg_setmode(4);
  139.  
  140.                          maxx = fg_getmaxx();
  141.                          maxy = fg_getmaxy();
  142.  
  143.                          fg_setmode(mode);
  144.                          fg_reset();
  145.                          printf("(%d,%d)\n",maxx,maxy);
  146.                       }
  147.  
  148. World Space
  149.  
  150.      World space is the other available coordinate system in graphics modes.
  151. It utilizes user-defined floating point coordinates.  Fastgraph translates
  152. world space coordinates into physical device coordinates (screen space), and
  153. because of this it is somewhat slower than using screen space.  World space
  154. can be thought of as a standard cartesian plane extending from the lower left
  155. corner of the screen.
  156.  
  157.      Any program that uses world space coordinates must first initialize
  158. Fastgraph's internal world space parameters.  The Fastgraph routine fg_initw
  159. is provided for this purpose.  The fg_initw routine has no arguments and must
  160. be called before any other routine that uses world space coordinates.
  161.  
  162.      The next step in using world space is to use the Fastgraph routine
  163. fg_setworld to define the world space coordinates of the screen edges.  The
  164. fg_setworld routine has four floating-point arguments -- the minimum x
  165. coordinate (left edge), the maximum x coordinate (right edge), the minimum y
  166. coordinate (bottom edge), and the maximum y coordinate (top edge).  For
  167. example, if you define the world space coordinates with the statement
  168.  
  169.                        fg_setworld(-10.0,10.0,0.0,2.5);
  170.  
  171. the (x,y) coordinates of the screen corners would be defined as shown in the
  172. following diagram.
  173.  
  174.                             (-10.0,2.5) (10.0,2.5)
  175.  
  176.                             (-10.0,0.0) (10.0,0.0)
  177.  
  178.                                             Chapter 4:  Coordinate Systems  43
  179.  
  180.  
  181. Fastgraph includes a routine fg_getworld that returns the world space
  182. extremes as defined in the most recent call to fg_setworld.
  183.  
  184.      Example 4-3 uses fg_setworld and fg_getworld to illustrate an
  185. interesting application of world space.  This program calls another routine
  186. named redraw (not shown) that erases the screen and draws a certain image
  187. using world space coordinates.  The program draws the image, waits for a
  188. keystroke, reduces the world space by a factor of two in each direction, and
  189. then draws the image again.  This produces a zoom effect in which the image
  190. appears twice as large as it was originally.
  191.  
  192.                                  Example 4-3.
  193.  
  194.               #include <fastgraf.h>
  195.               #include <stdio.h>
  196.               #include <stdlib.h>
  197.               void main(void);
  198.               void redraw(void);
  199.  
  200.               void main()
  201.               {
  202.                  int new_mode, old_mode;
  203.                  double xmin, xmax, ymin, ymax;
  204.  
  205.                  old_mode = fg_getmode();
  206.                  new_mode = fg_automode();
  207.  
  208.                  if (new_mode == 0) {
  209.                     printf("This program requires graphics.\n");
  210.                     exit(1);
  211.                     }
  212.  
  213.                  fg_setmode(new_mode);
  214.                  fg_initw();
  215.  
  216.                  fg_setworld(0.0,40.0,0.0,30.0);
  217.                  redraw();
  218.                  fg_waitkey();
  219.  
  220.                  fg_getworld(&xmin,&xmax,&ymin,&ymax);
  221.                  fg_setworld(0.0,xmax*0.5,0.0,ymax*0.5);
  222.                  redraw();
  223.                  fg_waitkey();
  224.  
  225.                  fg_setmode(old_mode);
  226.                  fg_reset();
  227.               }
  228.  
  229. 44  Fastgraph User's Guide
  230.  
  231.  
  232. Conversion Routines
  233.  
  234.      It is often necessary to convert coordinates between character space,
  235. screen space, and world space.  Fastgraph includes eight conversion routines,
  236. four for x coordinates and four for y coordinates, to perform such
  237. conversions.  These routines return the translated coordinate as their
  238. function value.
  239.  
  240.      The fg_xalpha and fg_yalpha routines convert screen space coordinates to
  241. character space.  The fg_xalpha routine converts a screen space x coordinate
  242. to the character space column that contains the coordinate.  Similarly, the
  243. fg_yalpha routine converts a screen space y coordinate to the character space
  244. row that contains the coordinate.
  245.  
  246.      The fg_xconvert and fg_yconvert routines convert character space
  247. coordinates to screen space.  The fg_xconvert routine converts a character
  248. space column to the screen space coordinate of its leftmost pixel.
  249. Similarly, the fg_yconvert routine converts a character space row to the
  250. screen space coordinate of its top (lowest-numbered) pixel.
  251.  
  252.      The fg_xscreen and fg_yscreen routines convert world space coordinates
  253. to screen space.  The fg_xscreen routine translates x coordinates, while the
  254. fg_yscreen routine translates y coordinates.  Conversely, the fg_xworld and
  255. fg_yworld routines convert screen space coordinates to world space.  The
  256. fg_xworld routine translates x coordinates, while the fg_yworld routine
  257. translates y coordinates.
  258.  
  259.  
  260. Summary of Coordinate Routines
  261.  
  262.      This section summarizes the functional descriptions of the Fastgraph
  263. routines presented in this chapter.  More detailed information about these
  264. routines, including their arguments and return values, may be found in the
  265. Fastgraph Reference Manual.
  266.  
  267.      FG_GETMAXX returns the maximum x coordinate in screen space when used in
  268. a graphics mode.  It returns the maximum column number in character space
  269. when used in a text mode.
  270.  
  271.      FG_GETMAXY returns the maximum y coordinate in screen space when used in
  272. a graphics mode.  It returns the maximum row number in character space when
  273. used in a text mode.
  274.  
  275.      FG_GETWORLD returns the current world space limits, as defined in the
  276. most recent call to fg_setworld.
  277.  
  278.      FG_INITW initializes Fastgraph's internal parameters for world space.
  279. This routine must be called once, before any other routine that uses world
  280. coordinates.
  281.  
  282.      FG_SETWORLD defines the world space coordinates that correspond to the
  283. physical edges of the screen.
  284.  
  285.      FG_XALPHA and FG_YALPHA convert screen space coordinates to character
  286. space.
  287.                                             Chapter 4:  Coordinate Systems  45
  288.  
  289.      FG_XCONVERT and FG_YCONVERT convert character space coordinates to
  290. screen space.
  291.  
  292.      FG_XSCREEN and FG_YSCREEN convert world space coordinates to screen
  293. space.
  294.  
  295.      FG_XWORLD and FG_YWORLD convert screen space coordinates to world space.
  296. 46  Fastgraph User's Guide