# Solid5 6/8

``` 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.
IF XHigh < 0 OR XLow > 319 OR YLow > 199 OR YHigh < 0 THEN EXIT SUB
IF YHigh > 199 THEN YHigh = 199
IF YLow < 0 THEN YLow = 0

'Initialize the edge list
FOR a = YLow TO YHigh
EdgeList(a).Low = 32767
EdgeList(a).High = -32768
NEXT

'Enter the lines into the edge list
FOR a = 0 TO MaxLines
P1 = lines(a).P1
P2 = lines(a).P2
NEXT

'Fill the polygon
EdgeFill EdgeList(), YLow, YHigh, 3

END SUB

SUB EdgeFill (EdgeList() AS EdgeType, YLow, YHigh, C)
FOR a = YLow TO YHigh
LINE (EdgeList(a).Low, a)-(EdgeList(a).High, a), C
NEXT
END SUB

'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.
SUB FindNormals
FOR a = 0 TO MaxPolys
P1 = Polys(a).P1: P2 = Polys(a).P2: P3 = Polys(a).P3

'find the vectors of 2 lines inside the polygon
ax! = 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 vectors
nx! = ay! * bz! - az! * by!
ny! = az! * bx! - ax! * bz!
nz! = ax! * by! - ay! * bx!

'normalize the vector so it ranges from -1 to 1
M! = SQR(nx! * nx! + ny! * ny! + nz! * nz!)
IF M! <> 0 THEN nx! = 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).ZObject
NEXT
END SUB

'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.
SUB PolyFill (x1, y1, x2, y2, x3, y3, C) 'for QB 4.5 guys

'find lowest and high X & Y coordinates
IF y1 < y2 THEN YLow = y1 ELSE YLow = y2
IF y3 < YLow THEN YLow = y3
IF y1 > y2 THEN YHigh = y1 ELSE YHigh = y2
IF y3 > YHigh THEN YHigh = y3

IF x1 < x2 THEN XLow = x1 ELSE XLow = x2
IF x3 < XLow THEN XLow = x3
IF x1 > x2 THEN XHigh = x1 ELSE XHigh = x2
IF x3 > XHigh THEN XHigh = x3

IF YLow < 0 THEN YLow = 0

IF YHigh > 199 THEN YHigh = 199

IF XLow < XLow(s) THEN XLow(s) = XLow
IF XHigh > XHigh(s) THEN XHigh(s) = XHigh

IF YLow < YLow(s) THEN YLow(s) = YLow
IF YHigh > YHigh(s) THEN YHigh(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