home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilsf / graphtext / 3D_Prog / text0000.txt < prev   
Encoding:
Text File  |  1995-03-22  |  27.2 KB  |  663 lines

  1. Archive-name: 3d-programmer-info
  2. Version: $Id: .header,v 1.8 1994/05/23 15:55:59 pat Exp pat $
  3.  
  4.                       O                                O
  5.  
  6.  ---+  +---- F A Q ------------------+  +------- F A Q ---------------+  +---
  7.  %[%|  |X$HOOR$H\[[8@DoooDDDDD8@@[%[%|  |X$HOOR$H\[[8@DoooDDDDD8@@[%[%|  |X$H
  8.  [[%|  |$C$OOR$H\%[8DooooDDDD8D@@[[[%|  |$C$OOR$H\%[8DooooDDDD8D@@[[[%|  |$C$
  9.  [[%|  |X$HHRR$H@[            88@@[[%|  |X$HHRR            DDDD88@@[[%|  |X$H
  10.  [[[|  |$$$HRR$H@%[@8ooooD   888@[[[[|  |$$$HRR$H@%[@8o   DDDD888@[[[[|  |$$$
  11.  [[[|  |X$$H            /   /  88[[[[|  |X$          /   /    D888[[[[|  |X$$
  12.  [%[|  |XC$H    \%[@8DDD   DD   @[[%[|  |XC    $H\%[@   DDDD   88@[[%[|  |XC$
  13.  [[%|  |XC$H    \%%@8DD   DDDD   @[[%|  |XC    $H\%%   DDDDDD   8@@[[%|  |XC$
  14.  [%[|  |X$$H    \%%@88DDD   D8   @[%[|  |X$    $H\%%@8   DDD8   8@@[%[|  |X$$
  15.  [%[|  |CX$H    \%%[88DDD88  D   @[%[|  |CX    $H\%%[88D  88D   8@@[%[|  |CX$
  16.  [%[|  |X$CH    \%[[@888D8D8  |  @[%[|  |X$   _$H\%[[@888  88   88@[%[|  |X$C
  17.  [%[|  |XXCH    |  [@888D888  | @@[%[|  |XX  |  H\@[[@888  8   88@@[%[|  |XXC
  18.  [%[|  |XC$$    \  \       |  |88@[%[|  |XC  \  \       |  |  8888@[%[|  |XC$
  19.  [%[|  |XX$HOR$HH@  [@88888  8D8@@[%[|  |XX$HOR  H@[%[@8  @8888D8@@[%[|  |XX$
  20.  [%[|  |X$CHOR$H\@%  @@@@Y  8888@@[%[|  |X$CHOR$  @%%[Y  @8888888@@[%[|  |X$C
  21.  [%[|  |CX$$OR$HH@%%      .d8D88@@[%[|  |CX$$OR$H      .d@@888D88@@[%[|  |CX$
  22.  [[[|  |X$$HOR$HH@%%[[@@@@88D8D88@[[[|  |X$$HOR$HH@%%[[@@@@88D8D88@[[[|  |X$$
  23.  [%[|  |CX$HOR$HH\%[%[@@@@888D88@@[%[|  |CX$HOR$HH\%[%[@@@@888D88@@[%[|  |CX$
  24.  ---+  +--------------- F A Q -------+  +------------------ F A Q ----+  +---
  25.  
  26. Contents:
  27. 1) General references for 3-d graphics questions.
  28. 2) How do I define an object?
  29. 3) How do I define space?
  30. 4) How do I define position?
  31. 5) How do I define orientation?
  32. 6) How do I define a velocity?
  33. 7) Drawing three-dimensional objects on a two-dimensional screen.
  34. 8) Vector Math - Dot Product and Cross-Product.
  35. 9) Matrix Math
  36. 10) Collisions.
  37. 11) Perspective.
  38. 12) Z-Buffering & the Painters Algorithm & BSP-Trees.
  39. 13) Shading.
  40. 14) 3-space clipping.
  41. 15) 3-d scanning.
  42. 16) Publically available source-code.
  43. 17) Books on the topics.
  44. 18) Other forums.
  45. 19) Current Contents of Archive ftp.csh.rit.edu::/pub/3dfaq
  46.  
  47. Last update:
  48.      23May94
  49.  
  50. What's new?
  51.  
  52.      Description of Z-Buffering, Painter's Algorithm, and BSP-trees.
  53.  
  54. 1) General references for 3-d graphics questions.
  55.  
  56.      Well, this FAQ is just getting off the ground.  Hopefully it will
  57. touch on most of the bases you need to get started for now, and
  58. hopefully it will expand at least as fast as you need it too.  But...
  59. regardless, things you'll want to locate for more help are Matrix
  60. Algebra books, Physics books talking about Eulerian motion, and some
  61. books on the Graphics Hardware you want to program for.  The code
  62. examples included in this FAQ will most likely be in C with pseudo-code
  63. in comments.
  64.  
  65.      One of the most popular references, (and one of my favorites), is:
  66.           Computer Graphics: Principles and Practice
  67.           ------------------------------------------
  68.           Foley, van Dam, Feiner, and Hughes
  69.           Addison Wesley -- Reading, Massachusetts
  70.           (c) 1990.  ISBN 0-201-12110-7
  71.  
  72.      But, you'll also want to definitely check out the FAQ for
  73. comp.graphics.  That FAQ touches mainly on 2-D needs, but some 3-D
  74. aspects are reviewed there, too.
  75.  
  76. 2) How do I define an object?
  77.  
  78.      There are lots of ways to define objects.  One of the most commonly
  79. used is the OFF (Object File Format).  The OFF toolkit and a library of
  80. objects are available via anonymous ftp from gatekeeper.dec.com -- XXX
  81. ??? (I can't find it anymore.  I found it here once about 2 years ago,
  82. but I haven't found it since).  The format provides easy methods for
  83. extensions and a base set of things you can expect for each object.  The
  84. toolkit is a bit bulky, but the file format (in ascii) is easy enough to
  85. parse by hand.
  86.  
  87.      The OFF.aoff file contains information about the object.  The most
  88. important one there is the location of the surface specification file
  89. (usually object name.geom).  This file also contains other attributes
  90.                -
  91. and file names relevant to this object.
  92.  
  93.      The OFF surface specification begins with the number of points, the
  94. number of polygons and the number of segments.
  95.  
  96.         npts nplys nsegs
  97.  
  98. This line is followed by the floating point coordinates for the points
  99. that make up the object.
  100.  
  101.         x1 y1 z1
  102.         x2 y2 z2
  103.         x3 y3 z3
  104.            .
  105.         x(npts) y(npts) z(npts)
  106.  
  107. Then, it gets a bit more complicated.  The following lines begin with a
  108. number to indicate the number of vertices in this polygon.  That number
  109. is followed by that many numbers, one for each vertex.  These are given
  110. in an order specified in the .aoff (usually conter-clockwise).  So, for
  111. example, a triangle and a pentagon which share a side are shown below.
  112.  
  113.         3       1 3 4
  114.         5       2 4 3 6 7
  115.  
  116. Here is some quick and dirty sample code to read in the .geom file:
  117.  
  118. struct polygon {
  119.     int nvert;          /* Number of vertices in this polygon */
  120.     int *verts;         /* Vertices in this polygon */
  121. };
  122.  
  123. struct object {
  124.     int npts;           /* The number of points */
  125.     int npolys;         /* The number of polygons */
  126.     int nsegs;          /* The number of segments */
  127.     double *point x,*point y,*point z;
  128.                  -        -        -
  129.     struct polygon *polys;
  130. };
  131.  
  132. int
  133. read geom file( char *geom file, struct object *obj )
  134.     -    -                -
  135. {
  136.     FILE *fp;
  137.     int i,j;
  138.  
  139.     if (!(fp = fopen(geom file,"r")))           /* Open the .geom file */
  140.                          -
  141.         return -1;
  142.  
  143.                                                 /* Get header information */
  144.     fscanf(fp,"%d %d %d",&obj.npts,&obj.npolys,&obj.nsegs);
  145.  
  146.         /*
  147.         ** Allocate room for the points.
  148.         */
  149.     obj.point x = (double *)malloc(obj.npts*sizeof(double));
  150.              -
  151.     obj.point y = (double *)malloc(obj.npts*sizeof(double));
  152.              -
  153.     obj.point z = (double *)malloc(obj.npts*sizeof(double));
  154.              -
  155.  
  156.     for (i=0;i<obj.npts;++i)
  157.         fscanf(fp,"%lf %lf %lf",&obj.point x[i],
  158.                                           -
  159.                                 &obj.point y[i],
  160.                                           -
  161.                                 &obj.point z[i]);
  162.                                           -
  163.  
  164.         /* Allocate room for the polygons.  */
  165.     obj.polys = (struct polygon *)malloc(obj.npolys*sizeof(struct polygon));
  166.  
  167.     for (i=0;i<obj.npts;++i) {
  168.             /* See how many vertices this has */
  169.         fscanf(fp,"%d",&obj.polys[i].nvert);
  170.  
  171.             /* Allocate room for vertices */
  172.         obj.polys[i].verts = (int *)malloc(obj.npolys*sizeof(int));
  173.  
  174.             /* Get each vertex */
  175.         for (j=0;j<obj.polys[i].nvert;++j)
  176.             fscanf(fp,"%d",&obj.polys[i].verts[j]);
  177.     }
  178.  
  179. }
  180.  
  181. 3) How do I define space?
  182.  
  183.      There are several things to consider when picking a coordinate
  184. system.  Most important of these is how you intend to handle objects.
  185. If your objects are defined in terms of <x,y,z> triplets, it will
  186. require a fair bit of work on reading them in to turn them into
  187. spherical coordinates.  If you're looking to this FAQ for information on
  188. how to define the space your objects will be in, I'd strongly suggest
  189. using rectangular coordinates and some derivative of the OFF-format.
  190.  
  191.      For starters, let me just throw in that while our universe may be
  192. infinite in all directions, that doesn't make for good programming.  We
  193. have to limit ourselves to small enough numbers that we can multiply
  194. them together without overflowing them, we can divide them without
  195. crashing our systems, and we can add them without accidentally flipping
  196. a sign bit.
  197.  
  198.      Now, the fun begins.  The simplest form of defining the Universe is
  199. to flat out say that the Universe stretches over these coordinates, say
  200. in the bounding box of <-65536, -65536, -65536> to <65536, 65536,
  201. 65536>.  This is often referred to as a Universal Coordinate system or
  202. an Absolute Coordinate system.  Then, each object in the Universe will
  203. be centered about some coordinate in that range.  This includes your
  204. viewpoint.  Several strategies are available for dealing with the edge
  205. of the Universe.  One can make the Universe wrap around so that an
  206. object leaving the cube at < X, Y, 65536> will re-appear in the Universe
  207. at < X, Y, -65536>.  Or, one can make objects bounce or stop at the edge
  208. of the Universe.  And, given any approach, one can have the edge of the
  209. Universe be transparent or opaque.
  210.  
  211.      In an Absolute Coordinate system, all objects must be shown from
  212. the position of your viewpoint.  This involves lots of interesting math
  213. that we'll get into later.  But, in general, an objects position with
  214. respect to you is it's absolute position - your absolute position (with
  215. all kinds of hell breaking loose if you can see past the edge of the
  216. Universe).  Then, after this position is calculated, it must be rotated
  217. based on your orientation in the Universe.
  218.  
  219.      Another possibility for defining space is a Relative Coordinate
  220. system or a View-Centered Coordinate system.  In this sort of system,
  221. the Viewpoint is always at coordinates <0,0,0> and everything else in
  222. the Universe is based relatively to this home position.  This causes
  223. funky math to come into play when dealing with velocities of objects,
  224. but... it does wonders for not having to deal with the 'edge of the
  225. Universe'.  This is the Schroedinger's cat method of the 'edge of the
  226. Universe'.... in the truest sense of out of sight is out of mind.  Small
  227. provisions have to be made if objects aren't to wrap around.  But... a
  228. Relative Coordinate system can be used to give the illusion of infinite
  229. space on a finite machine.  (Yes, even your 486/66DX is finite).
  230.  
  231.      I'll leave spherical coordinates to a later version if people think
  232. they'll be of use...
  233.  
  234. 4) How do I define position?
  235.  
  236.      Position in an Absolute Coordinate system is easy.  Each object has
  237. three coordinates.  These are often stored in a data-type called a
  238. vector to abstract further the notion that these numbers belong
  239. together.
  240.  
  241.         typedef struct {
  242.  
  243.                 long x;
  244.                 long y;
  245.                 long z;
  246.         } VECT;
  247.  
  248. Usually, each object in the Universe is defined about its center with
  249. each coordinate on its surface being centered at its own <0,0,0>.  This
  250. helps tremendously in rotating the object, and I would highly recommend
  251. this.  Then, the object as a whole is given a position in space.  When
  252. it comes time to draw this object, its points' coordinates get added on
  253. to its position.
  254.  
  255.      In a Relative Coordinate system, position is also fairly straight
  256. forward.  The view-point always has position VECT={ 0, 0, 0 };.  Other
  257. objects follow the same sort of system that they would in Absolute
  258. Coordinate systems.
  259.  
  260. 5) How do I define orientation?
  261.  
  262.      Orientation can be quite tricky.  I interchange some of the terms
  263. here quite often.  In 3-space, orientation must be defined be two-and-
  264. a-half angles.  "Two and a half?" you say.  Well, almost everyone uses
  265. three because two just isn't enough, but if you want to be technical,
  266. one of those angles only has to range from 0 - 180 degrees (0 - PI/2
  267. radians).
  268.  
  269.      But, taking that for granted now.... you have to pick an
  270. orientation for your view.  I personally prefer to have the X-axis run
  271. >from left to right across the center of my screen.  I also like to have
  272. the Y-axis run from the bottom of my screen; and I also like to have the
  273. Z-axis running from me straight into my screen.  With some tweaking of
  274. plus and minus signs and a bit of re-ordering, all of the math here-in
  275. can be modified to reflect any orientation of the coordinate system.
  276. Some people prefer to have the Y-axis heading into the screen with the
  277. Z-axis going vertically.  It's all a matter of how you want to define
  278. stuff.
  279.  
  280.      Given that you've agreed with me that Z can go into the screen,
  281. what 3-angles do you need?  (Here's where I stand the biggest chance of
  282. mucking up the terms.)  You need roll, pitch, and yaw.  (I often mix up
  283. roll and yaw and such... so if you can follow along without getting
  284. locked into my terminology, future FAQ's will correct it.)
  285.  
  286.      Look at your monitor as you're reading this.  Now tilt your head so
  287. that your right ear is on your right shoulder.  This change in
  288. orientation is roll (or yaw... but I call it roll).
  289.  
  290.      Ok, now sit up straight again. Now bring your chin down to meet
  291. your chest.  (Hmmm... LOOK BACK NOW!!!, whew... glad you heard me.)
  292. That motion was pitch.
  293.  
  294.      Ok, now look over your right shoulder keeping your head vertical to
  295. see who's behind you.  (LOOK BACK AGAIN!!.)  Ok... that was yaw (or
  296. roll, but I call it yaw).
  297.  
  298.      That's the basics.  Now, what do I do with them?  Well, here's
  299. where a nice book on Matrix Arithmetic will help you out.  You have to
  300. use these three angles to make a Transformation matrix.  [See the
  301. section on Matrix Math].  Here is a typical method of doing these
  302. transformations: [Note, if you don't have Z going into your screen
  303. you'll have to munge these considerably].
  304.  
  305.         typedef double matrix[4][4];
  306.  
  307.         double sr,sp,sy,cr,cp,cy;
  308.         matrix mr, mp, my;      /* individual transformations */
  309.         matrix s;               /* final matrix */
  310.  
  311.         sr = sin( roll );     cr = cos( roll );
  312.         sp = sin( pitch );    cp = cos( pitch );
  313.         sy = sin( yaw );      cy = cos( yaw );
  314.  
  315.                                 /* clear all matrixes
  316.                                 ** [See the section on Matrix Math]
  317.                                 */
  318.         identity( &mr ); identity( &mp ); identity( &my );
  319.                                 /* prepare roll matrix */
  320.         mr[0][0] = mr[1][1] = cr;
  321.         mr[1][0] = - (mr[0][1] = sr);
  322.  
  323.                                 /* prepare pitch matrix */
  324.         mp[1][1] = mp[2][2] = cp;
  325.         mp[1][2] = - (mp[2][1] = sp);
  326.  
  327.                                 /* prepare yaw matrix */
  328.         my[0][0] = my[2][2] = cy;
  329.         my[0][2] = - (my[2][0] = sy);
  330.  
  331.         multiply( &mr, &my, &s );
  332.         multiply( &s, &mp, &s );
  333.  
  334. 6) How do I define a velocity?
  335.  
  336. Sticky question.  I'll get to it in the next rev.
  337.  
  338. 7) Drawing three-dimensional objects on a two-dimensional screen.
  339.  
  340.      Modified from comp.graphics FAQ:
  341.  
  342.      "There are many ways to do this.  Some approaches map the
  343.      viewing rectangle onto the scene, by shooting rays through
  344.      each pixel center and assigning color according to the object
  345.      hit by the ray.  Other approaches map the scene onto the
  346.      viewing rectangle, by drawing each object into the region,
  347.      keeping track of which object is in front of which.
  348.  
  349.      The mapping mentioned above is also referred to as a
  350.      'projection', and the two most popular projections are
  351.      perspective projection and parallel projection.  For example,
  352.      to do a parallel projection of a scene onto a viewing
  353.      rectangle, you can just discard the Z coordinate, and 'clip'
  354.      the objects to the viewing rectangle (discard portions that
  355.      lie outside the region).  To do a perspective projection,
  356.      dividing each the x and the y by some multiple or the Z-depth
  357.      is the usual approach.
  358.  
  359.      For details on 3D rendering, the Foley, van Dam, Feiner and
  360.      Hughes book, reading.  Chapter 6 is 'Viewing in 3D', and
  361.      chapter 15 is 'Visible-Surface Determination'.  For more
  362.      information go to chapter 16 for shading, chapter 19 for
  363.      clipping, and branch out from there."
  364.  
  365. 8) Vector Math - Dot Product and Cross-Product.
  366.  
  367.      Adding and subtracting vectors is as easy as subtracting their
  368. respective parts:
  369.  
  370.         <A,B,C> + <D,E,F> = <A+D, B+E, C+F>
  371.         <A,B,C> - <D,E,F> = <A-D, B-E, C-F>
  372.  
  373.      Scaling vectors is as simple as multiplying each part by a
  374. constant:
  375.  
  376.         S * <A,B,C> = <S*A, S*B, S*C>
  377.  
  378.      The Dot-Product of two vectors is simply the sum of the products of
  379. their respective parts:
  380.  
  381.         <A,B,C> . <D,E,F> = A*D + B*E + C*F
  382.  
  383. Note that this value is not a vector.
  384.  
  385.      The Cross-Product of two vectors is a bit more complex (it is the
  386. determinant of the matrix with the direction vector as the first row,
  387. the first vector as the second row, and the second vector as the third
  388. row):
  389.  
  390.         <A,B,C> X <D,E,F> = <B*F - C*E, C*D - A*F, A*E - B*D>
  391.  
  392. Note that:
  393.  
  394. <A,B,C> X <D,E,F> = -1 * ( <D,E,F> X <A,B,C> )
  395.         -and-
  396. (<A,B,C> X <D,E,F>) . <A,B,C> = (<A,B,C> X <D,E,F>) . <D,E,F> = 0
  397.  
  398.      More later.
  399.  
  400. 9) Matrix Math
  401.  
  402.      The identity matrix is a square matrix (same number of rows as
  403. columns) with all elements {i,j} given by:
  404.  
  405.                   { 1.0   if i == j
  406.         m[i][j] = {
  407.                   { 0.0   otherwise
  408.  
  409.      Multiplication of matrices:
  410.  
  411.     if X is a matrix that is m rows and n columns (an m-by-n (or mxn) matrix)
  412.     and Y is a matrix that is n rows and r columns (nxr), then the product
  413.     X * Y ==> m[i][j] = sum{ a=0, a<n, X[i][a] * Y[a][j] };
  414.  
  415. As you can see in this example, the result is a matrix with m rows and r
  416. columns (an mxr) matrix.  The most usual case in basic 3-d graphics is
  417. multiplication of 3x3 or 4x4 matrices to each other.
  418.  
  419.      Some important things to remember about matrix multiplication: (The
  420. following assume X and Y and Z are matrices and I is an identity matrix)
  421.  
  422.     X * Y rarely equals Y * X.  but,
  423.     X * ( Y * Z )  equals ( X * Y ) * Z
  424.  
  425.     X * I = I * X = X
  426.  
  427.     if (X * Y = I) then (Y * X = I)
  428.  
  429.      Multiplication of a Matrix and a Vector is simply a special case of
  430. multiplying two matrixes.  It just so happens that a vector is a matrix
  431. with only one column.  So, in order to multiply an mxn matrix by a
  432. vector, you have to have an nx1 matrix ("an n-vector" or "a vector in
  433. n").  The result is a vector in m.  As a quick example:
  434.  
  435.     [ a b ]   [ g ]   [ a*g + b*h ]
  436.     [ c d ] x [ h ] = [ c*g + d*h ]
  437.     [ e f ]           [ e*g + f*h ]
  438.  
  439. 10) Collisions.
  440.  
  441.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  442. feel free to send me a paragraph for this section.
  443.  
  444. 11) Perspective.
  445.  
  446. (Message nova:2746)
  447. From: Raul Deluth Miller <rockwell@nova.umd.edu>
  448.  
  449.      Perspective is easy: realize that the viewpoint isn't on the
  450. surface of the screen but is some distance back.  Then,
  451.  
  452.      [a] convert to a relative coordinate system centered around the
  453. viewpoint, oriented so that x and y are like this:
  454.                  y
  455.                  |
  456.  
  457.              ----+----x
  458.                  |
  459.  
  460. and z is the distance into the screen.  Now, divide your coordinates by
  461. z.
  462.  
  463.      That's all.
  464.  
  465.      Ok, sure, you don't really have to call your directions x y and z,
  466. but that's just changing the description which fits the math.  And,
  467. sure, you have to decide what to do about things that are "the other
  468. direction from the screen" -- but that's really something different.
  469.  
  470.      And, ok, you have to decide how many game units the viewpoint is,
  471. behind the screen [this is something you add to the z coordinate before
  472. dividing].  And, ok, maybe you want to scale things a bit to make it
  473. look nicer.  But none of that is really all that hard to deal with.
  474.  
  475.      What's annoying is that you don't want to do division for every
  476. pixel that you draw on the screen.  That means, for instance, that you
  477. might have a line where both ends are off the screen but part of the
  478. line [in the middle] are visible.  However, that's related to the
  479. problem of detecting collisions.  Or, better yet, clipping.  Yeah,
  480. that's it take a look at the section on clipping...
  481. Raul D. Miller             n =: p*q               NB. prime p, q, e
  482. <rockwell@nova.umd.edu>                           NB. public e, n, y
  483.                            y =: n&|&(*&x)^:e 1
  484.                            x -: n&|&(*&y)^:d 1    NB. 1 < (d*e) +.&<: (p,q)
  485.  
  486. 12) Z-Buffering & the Painters Algorithm & BSP-Trees.
  487.  
  488. There are several methods available for displaying polygons in a 3-d
  489.  
  490. object so as to assure that what's behind is behind and what's in front
  491. is in front.  Each, however, has its pros and cons.  With each of these
  492. methods, it is often useful to implement backface culling.  Backface
  493. culling is simply not rendering surfaces which aren't facing you.
  494.  
  495.      The Painter's Algorithm is probably the most intuitive for the
  496. beginner, one of the easiest to implement, and the hardest to get right.
  497. The Painter's Algorithm, quite simply, is Paint the from back to front.
  498. Once it has been determined which polygons will be drawn, it is
  499. necessary to sort them from furthest away to closest.  Then, starting
  500. with the furthest polygon and moving to the closest, draw them.
  501.  
  502.      The tricky part of the Painter's Algorithm is determining when one
  503. polygon is closer or farther than another.  The closest to satisfactory
  504. method I've found uses this criteria -- Surface A is further away then
  505. surface B if:
  506.         1) The furthest point of A is further away than the furthest
  507.             point of B.
  508.         2) B faces you more directly than A.
  509.         3) The closest point of A is further than the closest point of B.
  510.         4) Surface B is more "important" than surface A.
  511. These are to be taken in order until a decision is reached.  But, I've
  512. yet to find good enough criteria to work well on most objects that
  513. people design.  If you keep these criteria in mind when making the
  514. objects, it can help.  But, if you're using 3rd party objects, I'd
  515. suggest a different method.
  516.  
  517.      Z-Buffering is a buzzword that's finally come down to reality.
  518. It's been replaced by 'texture-mapping' and 'bump-mapping' and 'realtime
  519. raytracing' as the 'what's fancy' buzzword.  Z-buffering is costly in
  520. terms of memory and processing time, but gives beautiful results.  If
  521. you've got some freedom with your memory usage and a bit of processor
  522. time to spare, and you're ok with filling your own polygons, then Z-
  523. buffering may be for you.
  524.  
  525.      To Z-buffer, one keeps a 2d-array of numbers (shorts or ints
  526. usually) the same dimensions as the viewport.  As each <X,Y,Z> point is
  527. prepared for display, the final value is compared to the Z value already
  528. in the <X,Y> position in the Z-buffer array.  If the new Z is less than
  529. the one already in the buffer, the pixel-color is placed in the Screen-
  530. Buffer at position <X,Y> and the new Z is copied into position <X,Y> of
  531. the Z-Buffer.
  532.  
  533.      The expense of Z-Buffering is having to set each element to the
  534. MAX Z VALUE after each frame and keeping track of the Z-value for every
  535.    - -
  536. pixel in the Screen Buffer and every pixel in the polygon you're
  537. drawing.  In most applications, it is unnecessary to keep track of the
  538. Z-values of any more than the vertices of a polygon.
  539.  
  540.      And, my favorite of the bunch (but the nastiest to store in an
  541. object file, is BSP-trees.  BSP-tree stands for Binary Space Partition
  542. tree.  They are based the idea that surfaces of most objects don't
  543. change positions relative to each other.  Objects whose surfaces change
  544. relative positions cannot be (to my knowledge) easily used with BSP-
  545. trees.
  546.  
  547.      The first step in using BSP-trees is to break up your object into a
  548. 'good' object.  But, I can't think of a way to describe a 'good' object
  549. without just telling you how to make one.  So, here's a general
  550. algorithm for making a BSP-tree object from ye average object:
  551.     1) Pick a surface to call the root node.
  552.     2) Compare every other surface in the set of surfaces to the
  553.  
  554.         root node.
  555.  
  556.     3) If a surface is In-Front-Of the root node, then put it in
  557.         the 'Front Heap'.
  558.        If a surface is Behind the root node, then put it in the
  559.         'Back Heap'.
  560.        If neither of the above is true, chop up the surface into
  561.         smaller surfaces that are all either In-Front-Of or Behind
  562.         the root node.  (This is the tricky bit).
  563.     4) Repeat these steps with the 'Front Heap' and the 'Back Heap'.
  564. As an interesting note, I can see no advantage at all to trying to keep
  565. a relatively balanced tree.
  566.  
  567.      Now comes the interesting bit.  Now that the object is a 'good'
  568. BSP-tree object, it is time for the drawing algorithm.  This is fairly
  569. straight- forward.
  570.     1) Compare the root node with you.
  571.     2) If you are In-Front-Of the root node,
  572.         draw 'Root->Back', then the Root surface, then 'Root->Front'.
  573.        If you are Behind the root node,
  574.         draw 'Root->Front', then the Root surface (unless you're
  575.         backface culling), then 'Root->Back'.
  576.  
  577.      I fully admit that I didn't believe BSP-trees would work when I
  578. first read about them in Foley-van Dam, nor did I believe they would
  579. work after seeing them work for me.  Now, three months later, I fully
  580. believe they work, and I can even say I understand why.  I may soon
  581. attempt an explanation here, but suffice it for now to say, 'they can be
  582. grokked'.
  583.  
  584. 13) Shading.
  585.  
  586.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  587. feel free to send me a paragraph for this section.
  588.  
  589. 14) 3-space clipping.
  590.  
  591.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  592. feel free to send me a paragraph for this section.
  593.  
  594. 15) 3-d scanning.
  595.  
  596.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  597. feel free to send me a paragraph for this section.
  598.  
  599. 16) Publically available source-code.
  600.  
  601.      Well, I've started a collection at ftp.csh.rit.edu::/pub/3dfaq/src.
  602. Feel free to upload relevant stuff (that I can't find on archie in under
  603. twenty minutes).  Some other sites of interest:
  604.     stereograms:
  605.         ftp.comlab.ox.ac.uk::pub/Documents/3d
  606.         http://enigma.phys.utk.edu/stereo/index.html
  607.  
  608.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  609. feel free to send me a paragraph for this section.
  610.  
  611. 17) Books on the topics.
  612.  
  613. Computer Graphics: Principles and Practice Foley, van Dam, Feiner, and
  614.  
  615.      Hughes; Addison Wesley -- Reading, Massachusetts; (c) 1990.  ISBN
  616.      0-201-12110-7.
  617.  
  618.      I highly reccomend this book for the person seriously interested in
  619.      understanding Computer Graphics concepts for 2-D image-generation
  620.      and 3-D representation.  As a warning though, if you're struggling
  621.      to follow vector math and such, you might not spend the $60-$80
  622.      bucks on this one yet.
  623.  
  624. Programming in 3 Dimensions Christopher D. Watkins and Larry Sharp;
  625.      Barnes & Noble.
  626.  
  627.      I've never seen this book.  I've got an add for it in front of me.
  628.      (Sorry, no ISBN number listed).  I would guess it's a very low-
  629.      density version of some of the 3-D things from Foley.  The book
  630.      boasts sample source code on MS/PC-DOS floppy included.  "This one
  631.      is for all graphics enthusiasts who want a detailed look at 3-D
  632.      graphics and modeling.  Also features discussions of popular ray
  633.      tracinge methods and computer animation." [sic]
  634.  
  635. Computer Graphics Handbook: Geometry and Mathematics, Michael E.
  636.      Mortenson.  ISBN 0-8311-1002-3
  637.  
  638.      I've never seen this one, but it comes net-recommended.
  639.  
  640.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  641. feel free to send me a paragraph for this section.
  642.  
  643. 18) Other forums.
  644.  
  645.      Sorry... This is a FAQ in-progress.  Will do more later.  Please
  646. feel free to send me a paragraph for this section.
  647.  
  648. 19) Current Contents of Archive ftp.csh.rit.edu::/pub/3dfaq
  649.  
  650.    2 -rw-r--r--    1 pat      member    219 Apr  2 20:40 README
  651.   16 -rw-r--r--    1 pat      member   7787 Mar 28 19:11 DoomTechniques.gz
  652.   10 -rw-r--r--    1 pat      member   4243 May 23 12:34 bsp.gz
  653.   14 -rw-r--r--    1 pat      vr       6266 Apr  2 20:38 imath.gz
  654.  
  655.   22 -rw-r--r--    1 pat      vr      11262 Apr  2 20:43 imath.tar.gz
  656.  
  657. -- 
  658. To find out more about the random service, send mail to help@rANdom.PenIt.fo.
  659. Due to the double-random, any mail replies to this message will be randomized,
  660. and a random id will be allocated automatically. You have been warned.
  661. Please report any problems, inappropriate use etc. to admin@ranDoM.pIneT.fum.
  662.  
  663.