BBS: Inland Empire Archive Date: 03-21-93 (03:40) Number: 351 From: RICH GELDREICH Refer#: NONE To: ALL Recvd: NO Subj: Solid5 1/8 Conf: (2) Quik_Bas
Here's the solid 3-D program I've been talking about! Page 1 of 8.
'Page 1 of SOLID5.BAS begins here.
'Shaded 3-D animation with shadows [solid5.bas] for QB4.5/PDS
'By Rich Geldreich 1992
'Notes...
' This version uses some floating point math in the initialization
'code for shading, but after initialization floating point math is not
'used at all.
' The shading imploys Lambert's Law to determine the intensity of
'each visible polygon. Three simple lookup tables are calculated at
'initialization time which are used to eliminate multiples and
'divides in the main animation code.
' The hidden face detection algorithm was made by Dave Cooper.
'It's fast, and does not require any multiples and divides under most
'cases. The "standard" way of detecting hidden faces, by finding the
'dot product of the normal of each polygon and the viewing vector,
'was not just good (or fast) enough for me!
' The PolyFill routine is the major bottleneck of this program.
'QB's LINE command isn't as fast as I would like it to be... On my
'286-10, the speed isn't that bad (after all, this is all-QB!). On a
'386 or 486, this thing should fly... [hopefully]
' The shadows are calculated by projecting a line with the light
'source's vector through each of the points on the solid. Where this
'line hits the ground plane(which has a constant Y coordinate) is
'where the new shadow point is plotted.
' This program is 100% public domain- but of course please give
'some credit if you use anything from this program. Thanks!
DEFINT A-Z
DECLARE SUB CullPolygons ()
DECLARE SUB DrawLine (xs%, ys%, xe%, ye%, EdgeList() AS ANY)
DECLARE SUB DrawObject ()
DECLARE SUB DrawShadows ()
DECLARE SUB EdgeFill (EdgeList() AS ANY, YLow%, YHigh%, C%)
DECLARE SUB FindNormals ()
DECLARE SUB PolyFill (x1%, y1%, x2%, y2%, x3%, y3%, C%)
DECLARE SUB RotatePoints ()
DECLARE SUB ShadePolygons ()
CONST True = -1, False = 0
TYPE EdgeType 'for fast polygon rasterization
Low AS INTEGER
High AS INTEGER
END TYPE
TYPE PointType
XObject AS INTEGER 'original cooridinate
YObject AS INTEGER
ZObject AS INTEGER 'rotated coodinated
XWorld AS INTEGER
YWorld AS INTEGER
ZWorld AS INTEGER
XView AS INTEGER 'rotated & translated coordinate
YView AS INTEGER
XShadow AS INTEGER 'coordinates projected onto the ground plane
YShadow AS INTEGER
END TYPE
TYPE PolyType
P1 AS INTEGER '3 points which make up the polygon(they _
point
P2 AS INTEGER ' to the point list array)
P3 AS INTEGER
Culled AS INTEGER 'True if plane not visible
ZCenter AS INTEGER 'Z center of polygon
ZOrder AS INTEGER 'Used in the shell sort of the ZCenters
Intensity AS INTEGER 'Intensity of polygon
WorldXN AS INTEGER 'Contains the coordinates of the point
WorldYN AS INTEGER ' which is both perpendicular and a constant
WorldZN AS INTEGER ' distance from the polygon
NormalX AS INTEGER 'Normal of polygon -128 to 128
NormalY AS INTEGER ' (used for fast Lambert shading)
NormalZ AS INTEGER
END TYPE
TYPE LineType
P1 AS INTEGER 'Used for shadow projection
P2 AS INTEGER
END TYPE
DIM SHARED EdgeList(199) AS EdgeType
DIM SHARED SineTable(359 + 90) AS LONG 'cos(x)=sin(x+90)
DIM SHARED R1, R2, R3, ox, oy, oz
DIM SHARED MaxPoints, MaxPolys, MaxLines
DIM SHARED lines(100) AS LineType
DIM SHARED Polys(100) AS PolyType
DIM SHARED Points(100) AS PointType
DIM SHARED lx(256), ly(256), lz(256) 'lookup tables for Lambert _
shading
DIM SHARED s, XLow(1), XHigh(1), YLow(1), YHigh(1)
DIM SHARED ShadowXLow(1), ShadowXHigh(1), ShadowYLow(1), ShadowYHigh(1)
DIM SHARED lx, ly, lz
PRINT "QuickBASIC/PDS 3-D Solid Animation": PRINT "By Rich Geldreich _
1992"
PRINT : PRINT "Keys: [Turn NUMLOCK on]"
PRINT "Left.....................Angle 1 -"
'Continued on page 2
--- MsgToss 2.0b
* Origin: Computer Co-Op - Voorhees, NJ | Ted Hare (1:266/29)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET