BBS: Inland Empire Archive Date: 03-21-93 (03:44) Number: 356 From: RICH GELDREICH Refer#: NONE To: ALL Recvd: NO Subj: Solid5 6/8 Conf: (2) Quik_Bas

'Page 6 of SOLID5.BAS begins here.ShadowXHigh(s) = XHigh: ShadowYHigh(s) = YHighIFXHigh < 0ORXLow > 319 OR YLow > 199 OR YHigh < 0THENEXITSUBIFYHigh > 199THENYHigh = 199IFYLow < 0THENYLow = 0'Initialize the edge listFORa = YLowTOYHigh EdgeList(a).Low = 32767 EdgeList(a).High = -32768NEXT'Enter the lines into the edge listFORa = 0TOMaxLines P1 = lines(a).P1 P2 = lines(a).P2 DrawLine (Points(P1).XShadow), (Points(P1).YShadow), (Points(P2_ ).XShadow), (Points(P2).YShadow), EdgeList()'LINE ((Points(P1).XShadow), (Points(P1).YShadow))-((Points(P2)_.XShadow), (Points(P2).YShadow)), 0NEXT'Fill the polygonEdgeFill EdgeList(), YLow, YHigh, 3ENDSUBSUBEdgeFill (EdgeList()ASEdgeType, YLow, YHigh, C)FORa = YLowTOYHighLINE(EdgeList(a).Low, a)-(EdgeList(a).High, a), CNEXTENDSUB'This routine initializes the data required by the fast Lambert shading'algorithm. It calculates the point which is both perpendicular'and a constant distance from each polygon and stores it. This point'is then rotated with the rest of the points. When it comes time for'shading, the normal to the polygon is looked up in a simple lookup'table for maximum speed.SUBFindNormalsFORa = 0TOMaxPolys P1 = Polys(a).P1: P2 = Polys(a).P2: P3 = Polys(a).P3'find the vectors of 2 lines inside the polygonax! = Points(P2).XObject - Points(P1).XObject ay! = Points(P2).YObject - Points(P1).YObject az! = Points(P2).ZObject - Points(P1).ZObject bx! = Points(P3).XObject - Points(P2).XObject by! = Points(P3).YObject - Points(P2).YObject bz! = Points(P3).ZObject - Points(P2).ZObject'find the cross product of the 2 vectorsnx! = ay! * bz! - az! * by! ny! = az! * bx! - ax! * bz! nz! = ax! * by! - ay! * bx!'normalize the vector so it ranges from -1 to 1M! = SQR(nx! * nx! + ny! * ny! + nz! * nz!)IFM! <> 0THENnx! = nx! / M!: ny! = ny! / M!: nz! = nz! / M!'store the vector for later rotation(notice that it is scaled'up by 128 so it can be stored as an integer variable)Polys(a).WorldXN = nx! * 128 + Points(P1).XObject Polys(a).WorldYN = ny! * 128 + Points(P1).YObject Polys(a).WorldZN = nz! * 128 + Points(P1).ZObjectNEXTENDSUB'Draws a polygon to the screen. Simply finds the start and stop X'coordinates for each scan line within the polygon and uses the'LINE command for filling.SUBPolyFill (x1, y1, x2, y2, x3, y3, C)'for QB 4.5 guys'find lowest and high X & Y coordinatesIFy1 < y2THENYLow = y1ELSEYLow = y2IFy3 < YLowTHENYLow = y3IFy1 > y2THENYHigh = y1ELSEYHigh = y2IFy3 > YHighTHENYHigh = y3IFx1 < x2THENXLow = x1ELSEXLow = x2IFx3 < XLowTHENXLow = x3IFx1 > x2THENXHigh = x1ELSEXHigh = x2IFx3 > XHighTHENXHigh = x3IFYLow < 0THENYLow = 0IFYHigh > 199THENYHigh = 199IFXLow < XLow(s)THENXLow(s) = XLowIFXHigh > XHigh(s)THENXHigh(s) = XHighIFYLow < YLow(s)THENYLow(s) = YLowIFYHigh > YHigh(s)THENYHigh(s) = YHigh'Continued on page 7--- 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