home *** CD-ROM | disk | FTP | other *** search
- __ __ __
- )/ ) ) |
- (__/ __ ( _ __ __ ` _ |
- ) / ) ) ) ) / \) / ) )/ ) ) / \) |
- ( (__/ ( (__/( (__/( (__/ ( ( ( (__/(_ __|__
- ___) ___)
-
- Copyright 1989 Jason Harper
-
- Permission is granted to freely redistribute this work as long as the program
- and this documentation file remain together and intact.
-
- POLYGONIA I,
- first in a series of programs designed to explore the use of the Apple IIgs's
- unique fill mode graphics for real-time animation of 3D objects. The current
- version of the graphics algorithms only handle objects that fit entirely on
- the screen and do not decrease in apparent size with distance: future editions
- of Polygonia will handle true perspective views and boundary clipping, and
- (hopefully) will run faster.
-
- SYSTEM REQUIREMENTS:
- Should run on any IIgs with 512K available memory (built-in plus expansion
- card minus RAMdisk). No particular System version is required.
-
- Will NOT produce proper results on a monitor or other video device hooked up
- to an Apple Video Overlay Card (VOC). This is due to what I consider to be a
- major design flaw in the VOC. If you have a VOC installed, and it isn't
- practical for you to connect your monitor to the built-in video output rather
- than the VOC's output, you may be able to get adequate results by connecting a
- normal RCA-to-RCA video cable between the IIgs's composite video output jack
- and the VOC's video input jack. This causes the VOC to genlock with the
- built-in video, which the animation is synchronized with.
-
- USAGE:
- Polygonia I is mostly a 'sit back and watch'-type program. There are only
- three keys that have any effect while it is running:
-
- ESC: exits the program, returning to the program selector you ran it from.
-
- TAB: steps to the next of the six included 3D objects. After the last, TAB
- cycles back to the first one again.
-
- CapsLock: turns off fill mode graphics, so you only see what the program is
- actually drawing (basically, just the left edges of each differently colored
- area) rather than apparently solid objects created by fill mode. It is this
- ability to display a contigious row (up to the full width of the screen) of
- pixels of the same color by drawing only the leftmost pixel that makes this
- sort of animation possible on the IIgs. Pressing CapsLock again restores fill
- mode graphics.
-
- Every 10 seconds, the animation's average speed in frames per second is
- calculated and displayed in the lower left corner of the screen. The absolute
- maximum speed an animation can run at is 60 FPS, the rate at which the image
- on the monitor is refreshed. It is doubtful that the animation techniques
- used in Polygonia can ever reach that goal except for tiny, trivial objects.
- It would be quite possible to record the data generated by the animation
- routines and play them back later at a full 60 FPS, but there would be no
- possibility of any control over the animation other than moving it to
- different places on the screen: individual objects couldn't respond to user
- input or other external control.
-
- THE OBJECTS:
- Object # of vertices # of polygons Average # of edges per polygon
- ------ ------------- ------------- ------------------------------
- Cube 8 6 4
-
- Tetrahedra 10 16 3
-
- Dodecahedron 20 15 4.67
- The graphics algorithms can't really handle the zero-thickness areas created
- by the hole in this object, so an occasional incorrect frame is to be expected.
-
- XYZ axes 47 42 4.14
-
- Spaceship 132 94 4.77
-
- Towers of Hanoi:
- Base only 23 17 3.29
- Each disk 16 12 4
- Total 103 77 3.84
- For those of you who are unfamilar with the Towers of Hanoi puzzle, the rules
- are as follows: there is a base with three pegs, and an arbitrary number of
- disks of different sizes. All the disks start on one peg, in decreasing order
- of size. The object of the puzzle is to move all of the disks onto another
- peg in the same order. Only one disk can be moved at a time, and no disk may
- ever be placed on top of a smaller disk.
-
- HOW IT WORKS:
- Each object to be drawn is represented by a list of points specified by X, Y,
- and Z coordinates, plus a list of polygons specified by the points that form
- their boundary and a color. Each polygon is constructed so that its border
- points are in clockwise order when viewed from the outside of the object: if
- the points end up in counterclockwise order, then the polygon is facing away
- from the viewer and can be quickly skipped. Colors are independantly
- specified for even and odd rows of pixels, so it is possible to form
- additional dithered colors that are distinguishable from the 15 pure colors
- (the 16th color has no color of its own in fill mode, it gets the color of the
- pixel to its left and is used to fill horizontal rows of pixels with minimal
- effort). For each frame to be displayed, the following steps are taken:
-
- 1. A transformation matrix is generated from the individual rotation, scaling,
- and translation transformations needed to put the object on the screen in the
- desired position and orientation.
- 2. Each of the points in the object's point list is multiplied by the
- transformation matrix. Building a single transformation matrix and applying
- it to all the points is far more efficient in general than applying each
- individual rotation, scaling, etc. separately to each point.
- 3. For each polygon in the object's list:
- A. The polygon's area is computed from the coordinates of its points. If
- the result is negative, the polygon is facing away from the viewer, and
- all further processing of it can be skipped.
- B. For each edge (pair of adjacent points) of the polygon, an entry in the
- Edge Table (ET) is created giving the information needed to draw the
- line, including starting horizontal position, slope, and ending vertical
- position. The ET is divided into 200 separate lists, one for each
- possible starting vertical position, so that information doesn't have
- to be stored with each edge.
- 4. For each of the 200 rows of pixels on the screen:
- A. All entries in the ET list corresponding to this scanline are moved
- into the Active Edge Table (AET), being placed in ascending order of
- their current horizontal position.
- B. Each edge in the AET is examined to see if the display changes at that
- horizontal position (there is no possibility of any change at points
- other than on a polygon edge). Most of the time, this can be done by
- simply comparing the depth of the edge that the display is currently
- 'in' with the edge being processed: the new edge is either further
- away and thus ignored, or closer and therefore becomes the current 'in'
- edge. Occasionally the whole list of polygons that currently have
- edges in the AET has to be searched to find the closest one. When a
- change to a newly-colored edge is detected, it is NOT immediately drawn
- to the screen: the edge processing generally takes longer than 1/60th
- second, so there would be considerable flicker as the new frame slowly
- replaces the old. Instead, the new color and the screen position at
- which it starts are saved in a list for later use.
- C. After all the AET entries are processed, they are updated to be correct
- for the next scanline. Each edge's slope is added to its current
- horizontal position: positive for lines that slant to the right, and
- negative for those that slant to the left. Any edge which reaches its
- ending vertical position is deleted from the AET. The AET is re-sorted
- to maintain the ascending order of horizontal positions.
- 5. Now that all the color changes in the frame have been generated, they are
- drawn to the screen all at once (to eliminate flicker). The program waits
- until the video scan just reaches the bottom of the screen, then uses the
- previous frame's change list to erase all of its color changes, then uses the
- change list just generated to draw all of the new color changes. This can
- hopefully always be done before the video scan reaches the top of the screen
- on its next pass. For fastest possible processing, the generated change lists
- are actually machine language code that carries out the changes, rather than
- just data for the program to interpret. It was rather challenging to come up
- with a way to generate the change list code so that it can be used both for
- drawing the changes when the list is for the current frame, then later for
- erasing the changes when the next frame is drawn. The change lists run in
- 8-bit native mode (there are seldom changes in adjacent bytes, so 16-bit mode
- would be inefficient) with the data bank register pointing to bank $E1 where
- the graphics screen resides, and contain code like this for each byte changed:
- LDA dp
- STA absolute
- The 'dp' address in the load instruction is the new value for the byte: to
- draw the changes the list is executed with the direct page set up so that each
- byte contains a value equal to its address, and to erase the changes a direct
- page containing all zeros is used. The 'absolute' operand in the store
- instruction is the offset into bank $E1 where the byte is to go.
-
- FOR FURTHER READING:
- Fundamentals of Interactive Computer Graphics
- James D. Foley & Andries Van Dam
- Addison-Wesley Systems Programming Series
- ISBN 0-201-14468-9
- Covers many aspects of 2D and 3D computer graphics, including the scanline
- algorithm used in Polygonia.
-
- Computer Graphics: A Programming Approach
- Steven Harrington
- McGraw-Hill
- ISBN 0-07-026753-7
- This book covers fewer topics than the previous one, but tends to give more
- concrete examples of using them: fewer things are "left as an exercise for the
- reader". The scanline algorithm is only mentioned in passing, but other
- details of Polygonia such as 3D coordinate transformations are covered.
-
- FOR FURTHER VIEWING:
- As far as I know, there have only been two programs prior to Polygonia I that
- use the IIgs's fill mode graphics. Both are freely distributable, and
- probably available wherever you found Polygonia. They are available on
- CompuServe, currently in Library 11 of the APPRODUCTIVITY Forum: finding them
- on other systems is up to you.
-
- Cubination (author unknown): the first known fill mode program, displays a
- rotating icosahedron (20-sided polyhedron) that moves diagonally around the
- screen, bouncing off the edges. Faster than Polygonia I, but less flexible as
- it is playing back a recorded series of frames rather than creating them as
- needed: the object can only rotate around a single axis, and can only appear
- at the same size it was recorded at. Filename is CUBINA.BNY on CompuServe.
-
- FillMaze (also by Jason Harper): a 3D maze walkthru. Very fast (about 55
- FPS), because the lines forming the left edges of each solid-colored area were
- laid out in advance to fall on byte boundaries, with easy-to-calculate integer
- slopes.
-
- THE END:
- Jason Harper
- CompuServe: 76703,4222
- Internet: 76703.4222@compuserve.com
-