46569 (565967), страница 2
Текст из файла (страница 2)
'fill in the drawing points tmp. x as the value going in the x dir etc
For i = 0 To shape. NumPoints
tmp (i). X = shape. Points (i). X + 75
tmp (i). Y = shape. Points (i). Y + 75
Next i
'Draw solid polygons
'calculate light value (ambient + Max * (normal of plane * light position)
Colr = 100 + 200 * (shape. Normal. Z)
'Fill object as solid
PicBox. FillStyle = 0
'Choose the color (this way makes a shade of yellow)
PicBox. FillColor = RGB (Colr, Colr, Colr / 2)
'draw the polygon
Polygon PicBox. hdc, tmp (0), shape. NumPoints + 1
'draw rest of objects transparently
PicBox. FillStyle = 1
ElseIf View = "TOP" Then
'creat lppoints for the win func call
ReDim tmp (shape. NumPoints) As POINTAPI
'fill in the drawing points tmp. x as the value going in the x dir etc
For i = 0 To shape. NumPoints
tmp (i). X = shape. Points (i). X + 75
tmp (i). Y = shape. Points (i). Z + 75
Next i
'Draw solid polygons
'calculate light value (ambient + Max * (normal of plane * light position)
Colr = 100 + 200 * (shape. Normal. Y)
'Fill object as solid
PicBox. FillStyle = 0
'Choose the color (this way makes a shade of yellow)
PicBox. FillColor = RGB (Colr, Colr, Colr / 2)
'draw the polygon
Polygon PicBox. hdc, tmp (0), shape. NumPoints + 1
'draw rest of objects transparently
PicBox. FillStyle = 1
ElseIf View = "SIDE" Then
'creat lppoints for the win func call
ReDim tmp (shape. NumPoints) As POINTAPI
'fill in the drawing points tmp. x as the value going in the x dir etc
For i = 0 To shape. NumPoints
tmp (i). X = shape. Points (i). Z + 75
tmp (i). Y = shape. Points (i). Y + 75
Next i
'Draw solid polygons
'calculate color value (ambient + Max * (normal of plane * light position)
Colr = 100 + 200 * (shape. Normal. X)
'Fill object as solid
PicBox. FillStyle = 0
'Choose the color (this way makes a shade of yellow)
PicBox. FillColor = RGB (Colr, Colr, Colr / 2)
'draw the polygon
Polygon PicBox. hdc, tmp (0), shape. NumPoints + 1
'draw rest of objects transparently
PicBox. FillStyle = 1
End If
End Function
Private Function VisiblePlane (shape As Verticies, CameraX As Integer, CameraY As Integer, CameraZ As Integer)
'this function takes the normal of the plane and returns True if visible FALSE if
'not visible
'Camera is the spot the object is being viewed from
'Find the dot product
D = (shape. Normal. X * CameraX) + (shape. Normal. Y * CameraY) + (shape. Normal. Z * CameraZ)
'return true if object is visible
VisiblePlane = D >= 0
End Function
Private Function FindNormals ()
'This function finds the normal of each plane
For i = 0 To NumObjectSides
'Find the normal vector
With Sides (i)
' * * * * * * * *
Nx = (. Points (1). Y - Points (0). Y) * (. Points (. NumPoints). Z - Points (0). Z) - (. Points (1). Z - Points (0). Z) * (. Points (. NumPoints). Y - Points (0). Y)
Ny = (. Points (1). Z - Points (0). Z) * (. Points (. NumPoints). X - Points (0). X) - (. Points (1). X - Points (0). X) * (. Points (. NumPoints). Z - Points (0). Z)
Nz = (. Points (1). X - Points (0). X) * (. Points (. NumPoints). Y - Points (0). Y) - (. Points (1). Y - Points (0). Y) * (. Points (. NumPoints). X - Points (0). X)
'Normalize the normal vector (make length of 1)
Length = Sqr (Nx ^ 2 + Ny ^ 2 + Nz ^ 2)
. Normal. X = Nx / Length
. Normal. Y = Ny / Length
. Normal. Z = Nz / Length
End With
Next i
End Function
Private Function CreateTables ()
'Create cosine and sine lookup table
For i = 0 To 359
CosAng (i) = Cos (i * (3.14159265358979/180)) 'convert degrees to radians
SinAng (i) = Sin (i * (3.14159265358979/180)) 'convert degrees to radians
Next i
End Function
Main Interface