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'sLINEcommand 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!DEFINTA-ZDECLARESUBCullPolygons ()DECLARESUBDrawLine (xs%, ys%, xe%, ye%, EdgeList()ASANY)DECLARESUBDrawObject ()DECLARESUBDrawShadows ()DECLARESUBEdgeFill (EdgeList()ASANY, YLow%, YHigh%, C%)DECLARESUBFindNormals ()DECLARESUBPolyFill (x1%, y1%, x2%, y2%, x3%, y3%, C%)DECLARESUBRotatePoints ()DECLARESUBShadePolygons ()CONSTTrue = -1, False = 0TYPEEdgeType'for fast polygon rasterizationLowASINTEGERHighASINTEGERENDTYPETYPEPointType XObjectASINTEGER'original cooridinateYObjectASINTEGERZObjectASINTEGER'rotated coodinatedXWorldASINTEGERYWorldASINTEGERZWorldASINTEGERXViewASINTEGER'rotated & translated coordinateYViewASINTEGERXShadowASINTEGER'coordinates projected onto the ground planeYShadowASINTEGERENDTYPETYPEPolyType P1ASINTEGER'3 points which make up the polygon(they _point P2ASINTEGER' to the point list array)P3ASINTEGERCulledASINTEGER'True if plane not visibleZCenterASINTEGER'Z center of polygonZOrderASINTEGER'Used in the shell sort of the ZCentersIntensityASINTEGER'Intensity of polygonWorldXNASINTEGER'Contains the coordinates of the pointWorldYNASINTEGER' which is both perpendicular and a constantWorldZNASINTEGER' distance from the polygonNormalXASINTEGER'Normal of polygon -128 to 128NormalYASINTEGER' (used for fast Lambert shading)NormalZASINTEGERENDTYPETYPELineType P1ASINTEGER'Used for shadow projectionP2ASINTEGERENDTYPEDIMSHAREDEdgeList(199)ASEdgeTypeDIMSHAREDSineTable(359 + 90)ASLONG'cos(x)=sin(x+90)DIMSHAREDR1, R2, R3, ox, oy, ozDIMSHAREDMaxPoints, MaxPolys, MaxLinesDIMSHAREDlines(100)ASLineTypeDIMSHAREDPolys(100)ASPolyTypeDIMSHAREDPoints(100)ASPointTypeDIMSHAREDlx(256), ly(256), lz(256)'lookup tables for Lambert _shadingDIMSHAREDs, XLow(1), XHigh(1), YLow(1), YHigh(1)DIMSHAREDShadowXLow(1), ShadowXHigh(1), ShadowYLow(1), ShadowYHigh(1)DIMSHAREDlx, ly, lz'Continued on page 2--- MsgToss 2.0b * Origin: Computer Co-Op - Voorhees, NJ | Ted Hare (1:266/29)

Echo Basic Postings

**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