home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / rec / games / programm / 5164 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  36.6 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!netnews.upenn.edu!dsinc!ub!toz!cyberman
  2. From: cyberman@toz.buffalo.ny.us (Cyberman)
  3. Newsgroups: rec.games.programmer
  4. Subject: R.G.P. FAQ 0.0.2
  5. Message-ID: <gate.3P67VB1w165w@toz.buffalo.ny.us>
  6. Date: 22 Dec 92 18:40:25 GMT
  7. Lines: 1004
  8. X-Maildoor: WaflineMail 1.00r
  9.  
  10.  
  11.  
  12. ---
  13.  * Blue Wave/QWK v2.11 *
  14.  
  15. This document will be made available by mail request at a later
  16. date (mail server difficulties).
  17.  
  18. There are currently 2 FAQ's
  19.  
  20. RGP.FAQ - rec.games.programmer General Frequently
  21. RGP.IBM - rec.games.ibm relevant FAQ
  22.  
  23. This was done so that someone who is looking for more general
  24. information will be able to find game programing information
  25. without being inundated by IBM or other computer-SPECIFIC
  26. information.  Game source available on the net are NOT part of
  27. this FAQ.
  28.  
  29. The current Editor is Cyberman@toz.buffalo.ny.us
  30.  
  31. Changes from 0.0.1
  32.  
  33. Mod format information removed this will be in a seperate archive
  34. to avoid any legal tangles.  Several other modifications (a Mac
  35. addition).
  36.  
  37. --------------------------------------------------------------------------------
  38. REC.GAMES.PROGRAMMER     General FAQ     Contents
  39. --------------------------------------------------------------------------------
  40. LEGAL
  41.  
  42. This document is FREE! (so are dumb looks) It is for your self
  43. enlightenment.  No warranty is provided for this information.
  44. The accuracy of the information contained herein is subject to
  45. conjecture.  Therefore the editors and contributers will take NO
  46. liability for improper use, misuse, or abuse of this information,
  47. and any damage to ANYTHING or ANYONE whether physical, financial,
  48. etc. in no way, shape, or form can be attributed to this document.
  49. Use this information at you OWN risk.
  50.  
  51. The above statement is to keep those who contributed and the
  52. editor free from personal injury for being nice.
  53.  
  54. Special thanks to:
  55. andrean@cs.utexas.edu (Andre A. Nurwono)
  56. roberts@brahms.amd.com (Dave Roberts)
  57. sean@stat.tamu.edu (Sean Barrett)
  58. Cyberman@toz.buffalo.ny.us (Cyberman)
  59. (and anyone else I forgot to mention for that matter)
  60.  
  61. If you wish to contribute CODE be sure it's something you DO NOT
  62. wish to COPYRIGHT!
  63.  
  64. All contributions and suggestions should be sent to me at:
  65. Cyberman@toz.buffalo.ny.us
  66. place in subject header
  67.  
  68. RGP.FAQ.*
  69. where * is any of the following
  70.     SUGGESTION      - to suggest Adding an area (I recommend that
  71.                         you send the information if you want it
  72.                         added)
  73.     ADD             - an addition (ie TBA's [see KEY for what TBA
  74.                         means])
  75.     EDIT            - for a correction somewhere (it is suggested
  76.                         contributers do there own editing)
  77.     FLAME           - complaints - I'll read these but be sure to
  78.                         be tasteful in you commentary.  You may or
  79.                         may NOT get a reply.
  80.  
  81. For now I'm going to use my personal mail account.  So please be
  82. careful.
  83.  
  84. Format:
  85. There are several categories and each category contains it's
  86. relevant questions as suggested.
  87.  
  88. Key:
  89. TBA - To Be Added
  90.  
  91. [Frequently Asked Questions about terminology]
  92. Q1.1    What are .MOD files?
  93. Q1.2    What is a pixel?
  94. Q1.3    What is a bitmap?
  95. Q1.4    What is flicker?
  96. Q1.5    What is snow?
  97. Q1.6    What is a frame buffer?
  98. Q1.7    What is a Sprite?
  99. Q1.8    What is vertical/horizontal retrace?
  100.  
  101. [Frequently Asked Questions about Animation]
  102. Q2.1    How do I make sprites on my xxx?
  103. Q2.2    What about collision detection?             TBA
  104. Q2.3    What about bitmap scaling?                  TBA
  105. Q2.4    What is perspective mapping?                TBA
  106. Q2.5    What about 3d objects and manipulation?
  107.  
  108. [Frequently Asked Questions about Map Generation]
  109. Q3.1    How do I generate a maze?
  110. Q3.2    How do I generate a landscape/terrain?      TBA
  111. Q3.3    How do I generate a hex map?                TBA
  112. Q3.4    What about random number generators?
  113.  
  114. [Frequently Asked Questions about Libraries and support software]
  115. Q4.1    What is there for the IBM compatible?
  116. Q4.2    "    "  "     "   "   Amiga?                TBA
  117. Q4.3    "    "  "     "   "   Atari?                TBA
  118. Q4.4    "    "  "     "   "   Macintosh?            TBA
  119. Q4.5    "    "  "     "   "   Sun/Sparc?
  120. Q4.6    "    "  "     "   "   X?                    TBA
  121.  
  122. Note 1: Fixing snow and flicker
  123. Note 2: 2 Part Tutorial on 3d graphics
  124.  
  125. --------------------------------------------------------------------------------
  126. REC.GAMES.PROGRAMMER     General FAQ     Terminology
  127. --------------------------------------------------------------------------------
  128.  
  129. Q1.1    What are .MOD files?
  130.     A .MOD file is a file generated for the Amiga.  A tracker is
  131.     used to play the MOD.  A mod consists of digitized sound and
  132.     sequencing information to play music.  Here is a BRIEF and
  133.     incomplete text file that is somewhat informative on the
  134.     subject.
  135.  
  136.     SEE ALSO - Mod Format specification file.  (Modform.zoo)
  137.  
  138. Q1.2    What is a Pixel?
  139.  
  140.     Pixel is short for Picture Element.  It is a single dot
  141.     address on a grid used to display images in television and on
  142.     computers.
  143.  
  144. Q1.3    What is a bitmap?
  145.  
  146.     A bitmap aka bitimage is the representation of an image in
  147.     the form of a sequence of bits.  For example most graphic
  148.     modes on computers represent the pixels using a BITMAP.
  149.  
  150. Q1.4    What is flicker?
  151.     Flicker is a noticeable pulse or change in an image.  This
  152.     can be on a CRT (Cathode Ray Tube) or other type display
  153.     device.  The cause is that the refresh rate of the CRT is
  154.     lower than the persistance of vision of the person observing
  155.     it.
  156.  
  157.     Another form of flicker is due to rapid drawing of data on
  158.     the screen.  What happens is that the data is drawn out of
  159.     syncronization with the horizontal and vertical scan.  So
  160.     your image apears to fade in and out of visability.
  161.  
  162.     SEE ALSO fixing snow and Flicker
  163.  
  164. Q1.5    What is SNOW?
  165.  
  166.     Snow are small specals appearing on the screen that look like
  167.     SNOW falling (hence the name).
  168.  
  169.     Snow is caused by a number of things.  One of which is when
  170.     one is writting to the screen while the display card is
  171.     scanning that address of the screen, this causes a conflict
  172.     and can produce random specals.
  173.  
  174.     Another cause of snow is an improperly connected monitor this
  175.     can damage the monitor.  Noise from an electro magnetic
  176.     source can interfer with your monitor as well.
  177.  
  178.     SEE ALSO fixing snow and Flicker
  179.  
  180. Q1.6    What is a frame buffer?
  181.  
  182.     Memory that contains image data that is translated to the image
  183.     on your screen.  A frame buffer does not have to be visible.
  184.  
  185. Q1.7    What is a Sprite?
  186.  
  187.     A sprite is an image usually moveable about the screen.
  188.     Common information stored in a sprite are, width, height,
  189.     position, and image data.
  190.  
  191. Q1.8    What is vertical/horizontal retrace?
  192.  
  193.     Most monitors are what is called a RASTER display.  This
  194.     means that an image is represented by setting the intensity
  195.     of a grid of dots on the display.  Each dot is called a
  196.     pixel.  In order to display the grid a CRT sweeps an electron
  197.     beam across the display surface sending pulses corresponding
  198.     to the intensity of the pixel.  However the stream of video
  199.     information is almost always represented left to right top to
  200.     bottom.  This mean that the beam must scan across the screen
  201.     and then move BACK to start a line.  This is called
  202.     Horizontal retrace.
  203.  
  204.     Vertical retrace is when the beam finishes painting the
  205.     screen from top to bottom again the beam must be moved to the
  206.     top of the screen.
  207.  
  208.     The horizontal sweep is controlled by an electric field the
  209.     vertical sweep is controlled usually magnetic field.
  210.  
  211. --------------------------------------------------------------------------------
  212. REC.GAMES.PROGRAMMER     General FAQ     Animation
  213. --------------------------------------------------------------------------------
  214.  
  215. [Frequently Asked Questions about Animation]
  216. Q2.1    How do I make sprites on my xxx?
  217.  
  218.     This, unfortunately, is a rather complex problem and its
  219.     implementation is often computer-specific, however some of it
  220.     can be addressed in the general FAQ.
  221.  
  222.     Sprites require one to copy pixels to the display in a
  223.     certain area of the screen.  There are various issues that
  224.     must be addressed about this.
  225.  
  226.     Getting and Putting an image: getting means you copy a
  227.     section of a screen (bitmap) to a buffer, putting means you
  228.     dump a buffer of data (bitmap) to a screen location.  These
  229.     are often used for less sophisticated sprite animation.
  230.  
  231.     The problem with this technique is put destroys the
  232.     background information.  So if you want a background at all,
  233.     there must be a way to "overlay" an image onto it without
  234.     creating a large area around the sprite to disappear. An old
  235.     way of "fixing" this is to copy the background of an image
  236.     before you destroy it, then put the background back after you
  237.     move it.
  238.  
  239. Q2.2    What about collision detection?                 TBA
  240. Q2.3    What about bitmap scaling?                      TBA
  241. Q2.4    What is perspective mapping?
  242.     What is it?  Basically it takes an image and "pastes" it in
  243.     3d perspective onto a surface.  This is much faster than
  244.     rendering surfaces in real time.  Article 7716 of r.g.p
  245.     written by Joshua C. Jensen (sl8nl@cc.usu.edu) is an example
  246.     of this technique (implemented in Turbo Pascal).
  247.  
  248. Q2.5    What about 3d objects and manipulation?
  249.  
  250.     Note 2 is a pair of tutorials on this subject.
  251.  
  252. --------------------------------------------------------------------------------
  253. REC.GAMES.PROGRAMMER     General FAQ     Map Generation
  254. --------------------------------------------------------------------------------
  255.  
  256. Q3.1    How do I generate a maze?
  257.     This is a VERY frequently asked question in rgp so we have
  258.     a unoffical maze FAQ.  It's is now posted WITH the RGP Faq.
  259.  
  260. Q3.2    How do I generate a landscape/terrain?      TBA
  261. Q3.3    How do I generate/use a hex map?
  262.     Well this has discussed considerably on rgp.  We haven't a
  263.     FAQ for it until I get permission to use something I
  264.     captured.
  265.  
  266. Q3.4    What about random number generators?
  267.     These are mandatory for making a "new" universe each time a
  268.     program loads.  Usually the ones included in a C compiler
  269.     library are sufficient for most needs.  However sometimes one
  270.     must go the extra mile and use there own random number
  271.     generator.  Currently we have no FAQ on random number
  272.     generators.  (sorry)
  273.  
  274. --------------------------------------------------------------------------------
  275. REC.GAMES.PROGRAMMER     General FAQ     Libraries and support software
  276. --------------------------------------------------------------------------------
  277.  
  278. Q4.1    What is there for the IBM and Compatibles?
  279.     There is quite a bit but for now we will have an UNOFFICIAL
  280.     list.  We are currently compiling a much better list.  This
  281.     will have to do tell then.
  282.  
  283.     contributed by
  284. andrean@cs.utexas.edu (Andre A. Nurwono)
  285. ==========
  286.  --------
  287.  Graphics
  288.  --------
  289.  
  290. *.  Executable
  291.     File(s) : TWEAK06.ZIP
  292.     Who     : Robert Schmidt (robert@solan.unit.no)
  293.     When    : 1992
  294.     What    : A program to experiment w/ VGA registers, very useful
  295.           if you want to define new modes (like mode X & 360x400 modes)
  296.     Where   : simtel & mirrors
  297.  
  298. *.  Executable, (source code)
  299.     File    : SPRITE.ZIP
  300.     Who     : Billy Dalrymple
  301.     When    : 1989
  302.     What    : A sprite editor, produces sprites w/ mask in files.
  303.           info available for $10
  304.           source code available for $25
  305.     Where   : I forget
  306.  
  307. *.  Executable, Source Code
  308.     File(s) : VGA.ZIP
  309.     Who     : wardt@a.cs.okstate.edu
  310.     When    : 1992
  311.     What    : A sprite editor, includes full source (.ASM & .C)
  312.     Where   : I forget
  313.  
  314. *.  Source Code, Library
  315.     File(s) : DDJ****.ZIP, XSHARP**.ZIP
  316.     Who     : M. Abrash
  317.     When    : Aug-Dec 1991, Jun-Aug 1992
  318.     What    : Mode X introduction. Sources to do animation,
  319.           polygon plotting, anti-aliasing, etc, on Mode X.
  320.     Where   : SIMTEL and mirrors,
  321.           ftp.mv.com (Official DDJ site) in pub/ddj
  322.  
  323. *.  Source Code
  324.     File(s) : article 7198 of rec.games.programmer
  325.     Who     : Frederick J. Haab (otto@nevada.edu)
  326.     When    : 26 Jun 92 00:17:52 GMT
  327.     What    : Scrolling in mode 13h, C program
  328.     Where   : USENET archives
  329.  
  330. *.  Source Code
  331.     File(s) : article 7716 of rec.games.programmer
  332.     Who     : Joshua C. Jensen (sl8nl@cc.usu.edu)
  333.     When    : 30 Jul 92 00:02:36 GMT
  334.     What    : Bitmap manipulation (scaling + perspective), Turbo Pascal
  335.           source w/ inline assembly.
  336.     Where   : USENET archives
  337.  
  338. *.  Source Code
  339.     File(s) : VESAVGA.ZIP
  340.     Who     : Randy Buckland
  341.     When    : 6/18/92
  342.     What    : .ASM & .C source to provide fast routines for VESA VGA modes.
  343.     Where   : garbo
  344.  
  345. *.  Sprite Library, Code
  346.     File(s) : STK110.LZH
  347.     Who     : Jari Karjala
  348.     When    : 1991 (v 1.1)
  349.     What    : Sprite library & toolkit for Hi-Res EGA, BW
  350.           includes C source, demo & good docs.
  351.     Where   : simtel & mirrors
  352.  
  353. *.  Sprite Library, Source Code
  354.     File    : SPRITES.ZIP
  355.     Who     : Marius Kjeldahl
  356.     When    : 1991
  357.     What    : Sprite library for VGA mode $13
  358.           includes TPU, .PAS source.
  359.           (shareware, $69 ?)
  360.     Where   : garbo
  361.  
  362. *.  Sprite Library, Toolkit
  363.     File(s) : WGT_SPR2.ZIP, WGT_TC21.ZIP, WGT_TP2.ZIP
  364.     Who     :
  365.     When    : 1992
  366.     What    : Shareware Sprite toolkit for VGA mode $13
  367.               includes TPU (WGT_TP2.ZIP), example programs for usage
  368.           Nag-shareware program
  369.     Where   : wuarchive, if somebody hasn't erased it yet
  370.  
  371. *.  I'm sure there's TONS more, but I can't search for all of them.
  372.     Any corrections / additions is great.
  373.  
  374.  -------------
  375.  Sound & Music
  376.  -------------
  377.  
  378. *.  Documentation
  379.     File(s) : Article 6077 of rec.games.programmer
  380.     Who     : Jeffrey S. Lee (jlee@smylex.uucp)
  381.     When    : 25 Feb 92 15:02:02 GMT
  382.     What    : Programming the AdLib/Sound Blaster FM Music Chips
  383.     Where   : usenet archives, also at the SB project site
  384.           (tybalt.cco.caltech.edu), & SB mailserver
  385.           (listserv@porter.geo.brown.edu)
  386.  
  387. *.  Executable, Runtime Library
  388.     File(s) : MODTECH.ZIP
  389.     Who     : Mark J. Cox (M.J.H.Cox@bradford.ac.uk)
  390.     When    : 1991
  391.     What    : TSR Library to play .MOD files in the background
  392.           Supports PC Speaker, SB, DisneySS, LPT DACs, etc
  393.     Where   : ftp.brad.ac.uk in /misc/msdos/mp
  394.  
  395. *.  Library
  396.     File(s) : MODOBJ.ZIP
  397.     Who     : Mark J. Cox (M.J.H.Cox@bradford.ac.uk)
  398.     When    : 1992
  399.     What    : .OBJ file w/ routines to play .MOD files in the background
  400.           Supports PC Speaker, SB, DisneySS, LPT DACs, etc
  401.           Includes examples in TC & TP
  402.           (shareware, $30)
  403.     Where   : ftp.brad.ac.uk in /misc/msdos/mp
  404.  
  405. *.  Source code
  406.     File(s) : NH10SRC.ZIP
  407.     Who     :
  408.     When    :
  409.     What    : Eliminate noise on sound samples, incl. .C source
  410.     Where   : SB project site & mailserv site
  411.  
  412. *.  Source code, Executable
  413.     File(s) : SB_OSC.ZIP
  414.     Who     :
  415.     When    :
  416.     What    : SB input scope / oscillator. Incl. .ASM source
  417.     Where   : SB project site & mailserv site
  418.  
  419. *.  Source code, Executable
  420.     File(s) : SBDAC.ZIP
  421.     Who     : Jeff Bird (cejjb@marlin.jcu.edu.au)
  422.     When    : 12 Feb 92
  423.     What    : SB DAC programming using DMA. Incl. .ASM & .C source
  424.     Where   : I forget (probably on SB project sites too)
  425.  
  426. *.  Library Source
  427.     File(s) : ???Xlib40???
  428.     Who     : Themie Gouthas (and company)
  429.     When    : 17 Nov 92
  430.     What    : mode X library for game, to many feature to mention
  431.     Where   : pub/MSDOS_UPLOADS@wuarchive.wustl.edu
  432.  
  433. ==========
  434.  
  435. Q4.2    "    "  "     "   "   Amiga?                TBA
  436.  
  437. Q4.3    What is there for the Atari?
  438.  
  439. from warwick@cs.uq.oz.au
  440.  
  441.     AMS library - Atari Machine Specific library
  442.       - C++ classes for Sprites, Screen, Joysticks, Double buffering, etc.
  443.       - beta testing now
  444.       - contact: warwick@cs.uq.oz.au
  445.  
  446. Q4.4    "    "  "     "   "   Macintosh?
  447.  
  448. from jmunkki@vipunen.hut.fi
  449.  
  450. *. Source code
  451.     Files   : Arashi_Source.cpt.bin
  452.     Who     : ???
  453.     When    : ???
  454.     What    : source code for an arcade quality game, vector
  455.         graphics, multichannel sound, (no sprites)
  456.     Where   : pub/mac/think-c/code@ics.uci.edu
  457.  
  458. Q4.5    "    "  "     "   "   Sun/Sparcs?
  459.  
  460.     contributed by
  461. andrean@cs.utexas.edu (Andre A. Nurwono)
  462. ==========
  463.  --------
  464.  Graphics
  465.  --------
  466. *.  Library
  467.     What    : Standard PIXRECT library
  468.           Bitmap manipulation routines for frame buffer.
  469.  
  470.  -------------
  471.  Music & Audio
  472.  -------------
  473. *.  Source code
  474.     File(s) : tracker.tar.Z
  475.     Who     :
  476.     When    :
  477.     What    : .MOD file player through the audio device. Works on SPARCS
  478.           w/ audio devices.
  479.     Where   :
  480.  
  481. *.  Source code
  482.     File(s) : csound.tar.Z
  483.     What    : FFT & signal processor
  484.  
  485. *.  Source code
  486.     What    : MixView
  487. ==========
  488.  
  489. Q4.6    "    "  "     "   "   X                     TBA
  490.  
  491.     Additions are welcome.
  492.  
  493. --------------------------------------------------------------------------------
  494. END OF FAQ
  495.  
  496. --------------------------------------------------------------------------------
  497. REC.GAMES.PROGRAMMER     General FAQ     NOTES
  498. --------------------------------------------------------------------------------
  499.  
  500. --------------------------------------------------------------------------------
  501. NOTE 1: contributed by
  502. --------------------------------------------------------------------------------
  503. sean@stat.tamu.edu (Sean Barrett)
  504.  
  505. There are two things that qualify as flicker.  Well, hell, to make it
  506. simpler, let's call it three.  At the end of this list I'll give a
  507. rough definition of the problem.
  508.  
  509. 1)    You move a shape by erasing it and plotting it in a new position,
  510. and there is a screen refresh during the time it is erased, resulting in
  511. the background showing through.
  512.  
  513. 2)    You're using CGA and you try to write anywhere on the screen
  514. during retrace, causing "noise" (due to DMA problems, I guess?).
  515.  
  516. 3)    You're moving a shape by some sort of "one-pass" technique in which
  517. the screen memory is never set to the background temporarily, so (1)
  518. can't happen, but the screen area the shape is in is refreshed during
  519. the draw, so half of it gets displayed at the old location, and half
  520. at the new.
  521.  
  522. I think a general rule would be that flicker occurs when a pixel on
  523. the screen is displayed with a color other than the "correct" or
  524. "intended" pixel value, as compared to an ideal "intended" case.  (Thus,
  525. if you're simulating something moving, you shouldn't see the background;
  526. if you're trying to simulate something moving and turning on and off
  527. simultaneously, then you can should see it; it's all a question of
  528. intent.)
  529.  
  530. Back to the above problems.
  531.  
  532. Now, so far as I know, there are only two solutions to #2.  Only redraw
  533. during the vertical retrace (blank), or don't support CGA.  So I'm going
  534. to forget about this problem.
  535.  
  536. You can handle #1, as I suggested in #3, by simply making sure you never
  537. write to the screen a value you don't want displayed.  Below I'll put a
  538. list of ways I can think of to do this for bitmapped graphics--i.e.,
  539. how to avoid the erase-redraw cycle.
  540.  
  541. If you really want to handle #3, then things get funky, and more power
  542. to you.  I don't personally believe it's a problem.  If it's periodic,
  543. so this one shape when you move it horizontally in the middle of the
  544. screen is always split with the top half leading the bottom half by
  545. a pixel, it's a problem; but if it just happens randomly once in a while
  546. I doubt it's noticeable.  In general, though, the solutions require
  547. paying attention to where the screen refresh is in some way.  My main
  548. point, the reason I'm posting this whole thing, is that *solving problem
  549. #1 does not require messing with knowing what section of the screen
  550. is being refreshed.*  As far as I know, the methods to combatting #3
  551. are to redraw everything during vertical refresh (same as #2, but
  552. overkill) or drawing your shapes from top to bottom lagging about half
  553. the time of a screen refresh behind the refresh, or some such.
  554.  
  555. Solutions to #1 that don't require timing considerations, e.g., how
  556. never to write a wrong pixel to the screen.
  557.  
  558.   o    Don't use raw bitmaps, use sprite hardware.
  559.  
  560.   o    Use hardware page flipping: display one screen, draw a new
  561.     screen "off-screen" and when it's finished, direct the
  562.     display hardware to display the new one.  This can get messy
  563.     for fast animation because you have to keep track of where
  564.     sprites were the last two frames to erase and update them.
  565.  
  566.   o    Use software page flipping; display one screen, draw a new
  567.     screen "off-screen" and when it's finished, copy the new
  568.     screen into screen memory.
  569.  
  570.   o    Use techniques such as "store" sprites which overwrite the
  571.     background.  Generally an out-of-date technique now, though;
  572.     only works for mono-color backgrounds.  You simply write the
  573.     sprite onto the screen; the sprite has enough border around
  574.     it to overwrite its previous image.  This is gross, very
  575.     fast, and flicker-free except when shapes get on top of each
  576.     other, at which point you get massive flicker.
  577.  
  578.   o    Use scratch-pad calculations, a variant of software page flipping.
  579.     Copy the section of the screen off that you need to update,
  580.     update it offscreen, and put it back on the screen.  A lengthy
  581.     time ago I posted a discussion of how to do this effectively
  582.     for XOR-style graphics for 8-bit type machines--you can xor
  583.     a single image onto the screen that both erases and replots
  584.     in a new place the old sprite.  And you can calculate the
  585.     image to do it on the fly, without additional memory, if you
  586.     set up your shape tables, and it's faster than the normal
  587.     draw shape with XOR to erase, draw shape with XOR to plot cycle
  588.     because it only reads and writes screen memory once.
  589.  
  590. Performance enhancements for bit blitting:
  591.  
  592.   o    Unroll loops.
  593.  
  594.   o    Write a custom bit blit for each shape, dedicated to that shape.
  595.     Cuts your memory accessing down if the machine has an
  596.     "immediate" operand mode that's faster than an index-addressed
  597.     one.
  598.  
  599. Memory performance enhancements for techniques that require many copies
  600. of shapes or large routines (such as pre-shifted shape tables):
  601.  
  602.   o    If you're only using some of your shapes at any point in time
  603.     (e.g. if you can divide your display up into "scenes"; for a
  604.     certain period of time only these shapes are used), calculate
  605.     the "larger" derived tables on the fly when the scene starts
  606.     up.  For large games (this is rec.games.programmer, not
  607.     rec.graphics.programmer, right?) that have to access the disk
  608.     anyway to change scenes, this is no big time loss.  Also, if
  609.     you write the code right then while you're idling the processor
  610.     before starting work on the next display, you can do this stuff
  611.     then.
  612.  
  613. --------------------------------------------------------------------------------
  614. NOTE 2: contributed by
  615. --------------------------------------------------------------------------------
  616. sean@stat.tamu.edu (Sean Barrett)
  617.  
  618. 3D graphics: Using matrices and vectors        Part 1
  619.  
  620.  
  621. -  Allows you to independently rotate objects and move the camera
  622.    anywhere.
  623. -  Does not discuss clipping.
  624. -  Algorithm uses 9 multiplies, 2 divides, and 9 additions per point,
  625.    plus overhead per independently located object.
  626. -  Part 2 gives the derivation for these formulas.
  627.  
  628.  
  629. Assume a right-handed universe, with x horizontal, y
  630. depth, and z vertical, and a screen display unit with
  631. x horizontal to the right and y vertical downward.
  632.  
  633.  
  634. The following are the rotation matrices:
  635.  
  636.     Rx(t)            Ry(t)            Rz(t)
  637. __                  __  __                  __  __                  __
  638. | 1    0      0    0 |    | cos(t) 0 -sin(t) 0 |    |  cos(t) sin(t) 0 0 |
  639. | 0  cos(t) sin(t) 0 |    |    0   1    0    0 |    | -sin(t) cos(t) 0 0 |
  640. | 0 -sin(t) cos(t) 0 |    | sin(t) 0  cos(t) 0 |    |    0        0    1 0 |
  641. | 0    0      0    1 |  |    0   0    0    1 |  |    0      0    0 1 |
  642. --                  --  --                  --  --                  --
  643.    rotate about x       rotate about y       rotate about z
  644.  
  645.  
  646. The following is the translation matrix:
  647.  
  648.   T(a,b,c)
  649. __       __
  650. | 1 0 0 a |
  651. | 0 1 0 b |
  652. | 0 0 1 c |
  653. | 0 0 0 1 |
  654. --       --
  655.  
  656. Let each object be a collection of points or lines.  If lines, they
  657. are drawn as lines connecting two 3D points, which can each be
  658. individually transformed.  So this derivation just handles converting
  659. individual points in three-space into pixel coordinates.
  660.  
  661. ---- BEGIN FORMULAS ----
  662.  
  663. If d is the distance from the eye to the window, h is the width
  664. of the window, v is the height of the window (use the sizes
  665. of the actual display if you don't know what else, but this is
  666. actually referring to the virtual camera's window); num_x
  667. is the number of pixels on the display in the x direction, num_y
  668. the number of pixels in the y direction, and (center_x,center_y)
  669. the location of the center of the display;
  670.  
  671. let scale_x = d/h*number_of_x_pixels, scale_y = d/v*number_of_y_pixels.
  672.  
  673. Then let S be defined as
  674. __                           __
  675. | scale_x center_x    0     0 |
  676. |   0        1        0     0 |
  677. |   0     center_y -scale_y 0 |
  678. |   0        0        0     1 |
  679. --                           --
  680.  
  681. Let the camera be located at (cx,cy,cz).  Let the vector E be pointing
  682. in the direction the camera is facing, the vector D be pointing to
  683. the right (along the camera's x axis), and the vector F be pointing
  684. up (along the camera's z axis); and let D, E, and F be of length 1.
  685. Then define the following matrices:
  686.  
  687.    matrix J        matrix C
  688. | Dx Dy Dz 0 |  | 1 0 0 -cx |
  689. | Ex Ey Ez 0 |  | 0 1 0 -cy |
  690. | Fx Fy Fz 0 |  | 0 0 1 -cz |
  691. | 0  0  0  1 |  | 0 0 0  1  |
  692.  
  693. and let N = S*J*C.
  694.  
  695.  
  696. Let each object i be at location cix, ciy, ciz, and let the matrix
  697. which holds the current rotation for that object be O(i).  To rotate
  698. the object around the q axis by n degrees, let new O(i) = Rq(n) * O(i).
  699. To rotate the object about *its* q axis, let new O(i) = O(i) * Rq(n)
  700. (I think.  I haven't looked at this closely, so it's probably wrong).
  701.  
  702. Let Otemp(i) be O(i) with the rightmost column of zeros replaced by
  703. cix, ciy, and ciz, or in other words, the product of Temp(i)*O(i) where
  704. Temp(i) is
  705. __         __
  706. | 1 0 0 cix |
  707. | 0 1 0 ciy |
  708. | 0 0 1 ciz |
  709. | 0 0 0  1  |
  710. --         --
  711.  
  712. Now, for each object i let M = N * Otemp(i).
  713.  
  714. Now, for each point P in i, let V = M * P, that is:
  715.  
  716.     Vx = M[0,0]*Px + M[0,1]*Py + M[0,2]*Pz + M[0,3];
  717.     Vy = M[1,0]*Px + M[1,1]*Py + M[1,2]*Pz + M[1,3];
  718.     Vz = M[2,0]*Px + M[2,1]*Py + M[2,2]*Pz + M[2,3];
  719.  
  720. Then the pixel to plot to is:
  721.  
  722.     If Vy>0
  723.         (Vx/Vy, Vz/Vy)
  724.  
  725. Done.
  726.  
  727. -- 2 --
  728.  
  729. 3D graphics: using matrices and vectors        Part 2
  730.  
  731. -  Allows you to independently rotate objects and move the camera
  732.    anywhere.
  733. -  Does not discuss clipping.
  734. -  Algorithm uses 16 multiplies, 2 divides, and 12 adds for each point,
  735.    plus overhead per independently located object.  Also shows how some
  736.    of the calculations are wasted, and reduces it to 9 multiplies and 9
  737.    additions.
  738.  
  739.  
  740. The folowomg is a derivation of some of the math for using 3D
  741. graphics with matrices and vectors.  I don't see any way of
  742. explaining how to use the matrix formulas without all the extra
  743. context, so you'll have to wade through it.  In general, you can
  744. simplify things by multiplying out the matrices and similar
  745. techniques.
  746.  
  747. You have a world described by three dimensional coordinates--it
  748. could be lines or points or polygons, whatever.  You have an
  749. imaginary camera in this world, and you want to draw exactly
  750. what this camera would see.
  751.  
  752. We represent the camera as a point where an "eye" is and a window
  753. through which it's looking--that is, a point for the eye, a vector
  754. from the eye to the center of the window, and another vector to tell
  755. us which way is the up direction on the window.  We can figure out
  756. the sideways direction of the window by taking a cross-product, but
  757. it may be better to represent it explicitly, as discussed far
  758. eventually below.
  759.  
  760. What we want to know is where on our screen we should plot a
  761. particular point.  The solution is to figure out where on the
  762. imaginary window the point would appear to be, and then to map
  763. the window onto our screen.
  764.  
  765. Suppose the eye is at the origin, facing along the X axis, and
  766. the point is in the XY plane so we can only look at two dimensions
  767. for illustration purposes.
  768.  
  769. Y axis
  770.  |                ___---
  771.  |          ___---
  772.  |    ___--- |           Point
  773.  | ---       |
  774. eye----------+------------------  X axis
  775.    ---___    |
  776.          ---_|_
  777.         window ---___
  778.                      ---___
  779.  
  780. Suppose the window ranges from (d,h/2) to (d,-h/2) and the point is at
  781. (a,b).  We want to know where the line from the point to the eye
  782. intersects the window line.  Well, the point is only visible if
  783. it's in front of the eye, so assume a>0.  Now, the two lines are
  784.  
  785.     y = (b/a)*x        (from Point to eye)
  786. and    x = d            (line window is on)
  787.  
  788. So the location of intersection is (d,(b/a)*d).  In other words,
  789. the point appears on our imaginary window with horizontal position
  790. d*b/a if |d*b/a| <= h/2.
  791.  
  792. Thus, the quick and dirty 3d graphics formula for assuming an eyepoint
  793. at the origin, X horizontal, positive to the right, Y vertical, positive
  794. up, and Z depth, positive going into the distance (this is a left-handed
  795. universe, whereas the rest of the derivations will be for a right handed
  796. universe), and screen coordinates sx horizontal, positive to the right
  797. sy vertical, positive down, is:
  798.  
  799.     if (Z>0) then
  800.         sx = x_scale * X / Z + x_center;
  801.         sy = - y_scale * Y / Z + y_center;
  802.     endif
  803.  
  804. where x_center, y_center is the pixel address of the center of the
  805. screen; x_scale is d/h*number_of_pixels_horizontally and y_scale is
  806. d/v*number_of_pixels_vertically; d is the distance between the eye
  807. and the window in the imaginary camera, h and v are the height and
  808. width respectively of the imaginary window.
  809.  
  810. Ok, back to the messy stuff.  Since our eyepoint won't necessarily
  811. be at the origin and facing in the right direction, we need to be
  812. able to handle arbitrary translations and rotations.  In general,
  813. to rotate (a,b) into (a',b') based on a given angle t, we do
  814.  
  815.     a' = cos(t)*a + sin(t)*b;
  816.     b' = cos(t)*b - sin(t)*a;
  817. (or switch the signs depending on which way you want to define as
  818. the positive direction of rotation).
  819.  
  820. Now, to cleanly handle multiple rotations, we want to use matrices
  821. to handle this.  This is the same as
  822.  
  823.     | cos(t) sin(t)|  |a| _ |a'|
  824.     |-sin(t) cos(t)|  |b| - |b'|
  825.  
  826. that is, a 2x2 matrix times a 2x1 matrix gives a 2x1 matrix.  Now
  827. to handle an arbitrary 3D rotation, we need to rotate on any axis:
  828.  
  829.    rotate about x       rotate about y       rotate about z
  830.  
  831. | 1    0      0    |    | cos(t) 0 -sin(t) |    |  cos(t) sin(t) 0 |
  832. | 0  cos(t) sin(t) |    |    0   1   0     |    | -sin(t) cos(t) 0 |
  833. | 0 -sin(t) cos(t) |    | sin(t) 0  cos(t) |    |    0        0    1 |
  834.  
  835. Now, to rotate about a particular point, we have to translate to that
  836. point.  Say we want to rotate about (d,e,f).  Then we subtract (d,e,f)
  837. from our point, rotate, and then add (d,e,f) again.  It would be nice
  838. if we could do that automatically with the matrices, and there is a way
  839. to, a cute trick.  We switch from 3x3 matrices to 4x4 matrices, and use
  840. 4-vectors.  For the rotation matrices, the new elements are all zero,
  841. except the bottom right one which is 1; for example:
  842.  
  843. |  cos(t) sin(t) 0 0 |
  844. | -sin(t) cos(t) 0 0 |
  845. |    0      0    1 0 |
  846. |    0      0    0 1 |
  847.  
  848. Also, all of our vectors have a fourth element, which is always 1.
  849. (In programming this, you can just continue to use three-vectors and
  850. program the 'multiply matrix by vector routine' to pretend there's
  851. one there.)  Now, to do a translation we want:
  852.  
  853.     x' = x + k1;
  854.     y' = y + k2;
  855.     z' = z + k3;
  856.  
  857. It turns out that this does the trick:
  858.  
  859. | 1 0 0 k1 |  | x |
  860. | 0 1 0 k2 |  | y |
  861. | 0 0 1 k3 |  | z |
  862. | 0 0 0 1  |  | 1 |
  863.  
  864.  
  865. Now, let's define some matrix terms so we can compress our notation.
  866. Let Rx(t), Ry(t), and Rz(t) be the 4x4 rotation matrices, and let
  867. T(k1,k2,k3) signify the appropriate matrix as above.  To rotate a point
  868. (a,b,c) theta around the y axis at point (d,e,f), we do the following
  869. in sequence: T(-d,-e,-f), Ry(theta), T(d,e,f).  Now, one nice thing
  870. about matrices is that we can get the effect of sequential application
  871. by multiplying matrices; that is, if U = (a,b,c,1) and V=(a',b',c',1),
  872. then do  T(-d,-e,-f)*U, and take that and do Ry(theta)*that, and take
  873. this and do T(d,e,f)*this, giving V, then this is:
  874.  
  875.     T(d,e,f) * ( Ry(theta) * ( T(-d,-e,-f) * U ) ) ) = V
  876.  
  877. Since matrix operations are associative, this is the same as
  878.  
  879.     T(d,e,f) * Ry(theta) * T(-d,-e,-f) * U = V
  880.  
  881. or, in other words, let M = T(d,e,f)*Ry(theta)*T(-d,-e,-f), then
  882. M is a matrix which performs the rotation we desire.
  883.  
  884. Ok, now to wrap it all up.  Suppose we have a bunch of objects in
  885. 3D we want to display, and the aforementioned camera.  The camera
  886. is at (cx,cy,cz), and we have a vector E pointing in the direction
  887. the camera is aiming, a vector D which shows which way the window
  888. is pointing to the right, and a vector F which points along the window
  889. upward.  These vectors form an orthonormal basis, so to rotate into
  890. the frame of reference for them we use the matrix
  891.  
  892. | Dx Dy Dz |
  893. | Ex Ey Ez |
  894. | Fx Fy Fz |
  895.  
  896. also, we want to use 4x4 matrices and first we want to translate
  897. to cx..cz, so we use
  898.  
  899.    matrix J        matrix C
  900. | Dx Dy Dz 0 |  | 0 0 0 -cx |
  901. | Ex Ey Ez 0 |  | 0 0 0 -cy |
  902. | Fx Fy Fz 0 |  | 0 0 0 -cz |
  903. | 0  0  0  1 |  | 0 0 0  1  |
  904.  
  905. So for an arbitrary point (a,b,c) in three space, the screen coordinates
  906. for it sx, sy are:  let U = (a,b,c,1); let V = J*C*U.  Then
  907.  
  908.     if (Vy>0) then
  909.         sx = scale_x * Vx/Vy + center_x;
  910.         sy = - scale_y * Vz/Vy + center_y;
  911.     endif
  912.  
  913. Generally, we want to store J and C separately.  It is pretty simple
  914. to move the camera, now; if the camera is always moving in the direction
  915. its facing, use the E vector and factor direction in by hand, and
  916. put this into C.  To rotate the camera, just multiply a rotation
  917. matrix on the left by J.
  918.  
  919. Now, to rotate objects properly, keep a separate rotation matrix
  920. for each object.  Then for each point in that object, rotate it and
  921. translate it.  It's simplest to store each object with the origin
  922. as the center of the object.  Then to calculate a point, you multiply
  923. by the rotation matrix and then by the translation to put the objects
  924. center where it should be in world space; because you're doing the
  925. translation second, it's easy to put it into one matrix:
  926.  
  927. translation    rotation
  928. | 1 0 0 l |   | a b c 0 |   | a b c l |
  929. | 0 1 0 m |   | d e f 0 | _ | d e f m |
  930. | 0 0 1 n | * | g h i 0 | - | g h i n |
  931. | 0 0 0 1 |   | 0 0 0 1 |   | 0 0 0 1 |
  932.  
  933. Call this matrix O(q) where q is the object number.
  934.  
  935. Then, for each point in object q, the final multiply is
  936. V = J * C * O(q) * U.
  937.  
  938. Finally, we can move some of the final calculation into a matrix.
  939. We have:
  940.     sx = scale_x * Vx/Vy + center_x;
  941.     sy = -scale_y * Vz/Vy + center_y;
  942.  
  943. If we factor out Vy, we get
  944.     sx = (scale_x * Vx + center_x * Vy)/Vy;
  945.     sy = (-scale_y * Vz + center_y * Vy)/Vy;
  946.  
  947. Suppose from V we calculate V':
  948.     (scale_x*Vx + center_x*Vy, Vy, -scale_y*Vz + center_y*Vz, 1)
  949.  
  950. Then
  951.     sx = V'x / V'y;
  952.     sy = V'z / V'y;
  953.  
  954. Well, to get V', we just multiply V by the matrix
  955.  
  956. | scale_x center_x    0     0 |
  957. |   0        1        0     0 |
  958. |   0     center_y -scale_y 0 |
  959. |   0        0        0     1 |
  960.  
  961. Let us call this matrix S.  Remember, scale_x = d/h*number_of_x_pixels,
  962. scale_y = d/v*number_of_y_pixels, d is distance from eye to window,
  963. h is width of imaginary screen, v is height of imaginary screen.
  964.  
  965. So, now, the basic idea is this.  To minimize calculation, let
  966. N = S * J * C.  For each object q, let M = N * O(q).  For every point
  967. U in q, let V = M * U.  If Vy>0, then that point is at (Vx/Vy,Vz/Vy)
  968. on the screen.
  969.  
  970. In pseudo-code, that's
  971.  
  972. /* matrix_multiply (destination, left_multiplicand, right_multiplicand) */
  973.  
  974. for each time slice do
  975.     if camera has moved then
  976.         matrix_multiply ( N, J, C);
  977.         matrix_multiply ( N, S, N);
  978.     endif
  979.  
  980.     for q an object do
  981.         matrix_multiply( M, N, O[q]);
  982.         for p a point in object q do
  983.             matrix_by_vector_multiply( V, M, U[q][p]);
  984.             do something with  ( V[0]/V[1], V[2]/V[1] );
  985.         endfor
  986.     endfor
  987. endfor
  988.  
  989. In truth, the matrix_by_vector_multiply wastes a bit of time, if you're
  990. trying to tune the code, it'd be worth tuning it.  Normally, it does
  991. this:
  992.  
  993. V0 = M00*U0 + M01*U1 + M02*U2 + M03*U3;
  994. V1 = M10*U0 + M11*U1 + M12*U2 + M13*U3;
  995. V2 = M20*U0 + M21*U1 + M22*U2 + M23*U3;
  996. V3 = M30*U0 + M31*U1 + M32*U2 + M33*U3;
  997.  
  998. However, we know that the bottom row is never used, since V3 is always
  999. 1; furthermore, we know that U3 is 1, so we can just do
  1000.  
  1001. V0 = M00*U0 + M01*U1 + M02*U2 + M03;
  1002. V1 = M10*U0 + M11*U1 + M12*U2 + M13;
  1003. V2 = M20*U0 + M21*U1 + M22*U2 + M23;
  1004.  
  1005. This uses nine multiplies and nine adds, plus the two divides required
  1006. to calculate the screen coordinate.  I believe this is the minimum
  1007. possible for arbitrary 3D graphics.  (You can turn the two divides into
  1008. one divide and two multiplies by calculating 1/Vy and multiplying by
  1009. that, which may be a win on some machines.)
  1010.  
  1011. ---
  1012.  * Blue Wave/QWK v2.11 *
  1013.                        
  1014.