home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER04.DOC < prev    next >
Text File  |  1993-10-02  |  12KB  |  309 lines

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