home *** CD-ROM | disk | FTP | other *** search
- This is the source for the X-Sharp 3-D animation package, as
- presented in the Graphics Programming column in Dr. Dobb's Journal,
- as of the April 1992 issue. A couple of bugs in the code from the
- April 1992 column are fixed in this archive. The code has been tested
- with Borland C++ 3.0 and TASM 3.0. To make X-Sharp, run K.BAT.
-
- Unpack this archive with PKZIP -d; the ball generation code belongs
- in the .\BALL subdirectory, and, because it has some of the same
- filenames as the main directory, problems will result without -d.
-
- Files in this archive:
-
- POLYGON.H - polygon & 3-D header file
- MAKEFILE - Borland Make makefile
- INITFIX.C - initializes fixed-point data
- GENCOS.C - generates cosine table for fixed-point look-up
- FILLCNVX.C - fills a convex polygon
- APPROT.C - appends rotations in X, Y, and Z
- DRAW.ASM - draws the scanned-out pixels of a convex polygon in mode X
- MODE.ASM - initializes the screen to mode X (320x240, 256 colors)
- XSHARP15 - ID file for the X-Sharp version
- LINKRESP - TLINK response file
- MOVEPOLY.C - updates the position and orientation of a polygon-based object
- SHOWPAGE.ASM - selects the video page that's visible
- SCAN.ASM - scans out an edge of a convex polygon
- FILLRECT.ASM - fills a rectangle with a solid color in mode X
- TURBOC.CFG - Borland C++ 3.0 configuration file. Uses 3.0-specific
- options, which must be changed for 2.0 and earlier
- DRAWPOBJ.C - draws a polygon-based object
- README - this file
- INITBALL.C - initializes the ball-shaped object
- K.BAT - remakes X-Sharp, producing XS.EXE
- BALVERT0.INC - include file that defines ball-shaped object
- COSTABLE.INC - include file for fixed-point cosines between 0 and 90 degrees
- XSHARP.C - main() for this animation
- INITCUBE.C - initializes the cube-shaped objects
- OLIST.C - object list initialization, handling, and sorting
- FIXED.ASM - fixed point arithmetic routine (some are 386-dependent)
- XFPROJ.C - transforms and projects polygon-based objects
- BALL - subdirectory; see below
-
- The subdirectory .\BALL contains the source code and executable for
- the program GENBALL, which creates the vertex and face lists for a
- ball made from rectangular faces (BALVERT0.INC was created by GENBALL).
- Remake GENBALL by running K.BAT in the .\BALL directory. See the
- 12/29/91 log entry for details.
-
- Note that this code uses 386-specific instructions.
-
- Comments and questions may be directed to me in the following ways:
-
- Bix: graphic.disp or graphic.pgms conferences or Bixmail (mabrash)
- MCI mail (mabrash)
- M&T Online programming.graphics conference (mabrash)
- U.S. Mail (7 Adirondack Street, South Burlington, VT 05403)
-
- Bix is the best way to get hold of me.
-
- This material may be used freely; it is provided free of charge, as
- are responses to questions and comments, within reason. Should the
- spirit move you, a contribution to the Vermont Assocation for the
- Blind and Visually Impaired, sent care of Dr. Dobb's Journal, myself,
- or directly to VABVI, would be appreciated, and would motivate me to
- keep enhancing X-Sharp.
-
- Vermont Association for the Blind and Visually Impaired
- 37 Elmwood Avenue
- Burlington, VT 05401
-
- Dr. Dobb's Journal
- 411 Borel Avenue, Suite 100
- San Mateo, CA 94403-3522
-
- ----------------------
- Michael Abrash 1/12/92
-
-
- ******************
- * Log of changes *
- ******************
-
- **********************************************************************
- Begin entry for 1/5/92
-
- ----------
- Altered ConcatXforms to add in the translation element from matrix #1
- only when multiplying by the fourth column of matrix #2, because only
- the fourth column has a 1 at the bottom. This fixes a bug in earlier
- versions that showed up when a world->view transformation involving
- translation was used.
-
- ----------
- Removed setting of non-existent element XformToWorld[3][3] in INITCUBE.C
- and INITBALL.C.
-
- **********************************************************************
- Begin entry for 12/29/91
-
- ----------
- Converted XformVec and ConcatXforms to assembly language, reducing
- transformation and concatenation time to 5% or less of total time.
-
- ----------
- Converted sin() and cos() calls to calls to the assembly language
- function CosSin(), which performs a table look-up. Changed angle
- representations from radians to tenths of degrees to facilitate table
- look-up and to maximize accuracy.
-
- ----------
- Put all the assembly language functions in fixed.asm, replacing
- l4.c and l9.asm.
-
- ----------
- Deleted one cube from the animation, and substituted a ball. The
- ball has a radius of 25, slightly larger than the cube it replaces.
- It has 6 bands of 12 facets each, for a total of 72 faces,
- approximately doubling the number of polygons in the animation, and
- has 62 vertices, increasing the number of vertices by more than 50%.
- Added INITBALL.C to initialize the ball, and added a call to
- InitializeBalls() to create the ball in main(). Only one ball is
- created, but more balls could easily be added, and the size of and
- number of bands in the ball(s) could easily be changed.
-
- The program GENBALL, in .\BALL, generates all vertex and face info
- for a generic ball (it doesn't generate the color info, which varies
- from instance to instance). The number of bands of faces and the
- size of the ball are prompted for when GENBALL is run. The output of
- GENBALL with 6 bands and a radius of 25 is in BALVERT0.INC, and is
- included in INITBALL.C, which initializes a ball for use in the
- animation program. To change the size, just regenerate BALVERT0.INC
- by running GENBALL with bands = 6 and the desired radius. To change
- the number of bands, run GENBALL with the desired number of bands and
- radius, and then change the Colors array in INITBALL.C to have one
- color entry for each face in the new ball. (The number of faces is
- shown as a define at the top of the output file from GENBALL.)
- Additional balls may be added by changing NUM_BALLS, and by adding a
- new entry to each array at the top of GENBALL.C.
-
- ----------
- Changed object list from an array to a linked list that is sorted
- in back-to-front order after each set of moves, so drawing the list
- in order performs proper hiding of objects.
-
- ----------
- Renamed source files more meaningfully, and renamed executable XS.EXE.
-
- ----------
- Added a center (0,0,0) point to each object, which is transformed into
- view space each time the object is transformed. This is used for
- Z-sorting objects for drawing precedence purposes, and can also be
- used for collision detection and the like.
-
- End entry for 12/29/91
- **********************************************************************
-