Public Const PC_EXPLICIT = &H2 ' Match to system palette index.
Public Const PC_NOCOLLAPSE = &H4 ' Do not match color existing entries.
' GetDeviceCaps constants.
Global Const RASTERCAPS = 38 ' Raster device capabilities.
Global Const RC_PALETTE = &H100 ' Has palettes.
Global Const NUMRESERVED = 106 ' # reserved entries in palette.
Global Const SIZEPALETTE = 104 ' Size of system palette.
#If Win32 Then ' 32-bit VB.
Type BITMAP ' 24 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Global Const BITMAP_SIZE = 24
Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Declare Function ResizePalette Lib "gdi32" (ByVal hPalette As Integer, ByVal NumEntries As Integer) As Integer
Declare Function SetPaletteEntries Lib "gdi32" (ByVal hPalette As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function GetPaletteEntries Lib "gdi32" (ByVal hPalette As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Integer, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Integer, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Declare Function GetNearestPaletteIndex Lib "gdi32" (ByVal hPalette As Integer, ByVal crColor As Long) As Integer
#Else ' 16-bit VB.
Type BITMAP ' 14 bytes
bmType As Integer
bmWidth As Integer
bmHeight As Integer
bmWidthBytes As Integer
bmPlanes As String * 1
bmBitsPixel As String * 1
bmBits As Long
End Type
Global Const BITMAP_SIZE = 14
Declare Function GetDeviceCaps Lib "GDI" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Declare Function ResizePalette Lib "GDI" (ByVal hPalette As Integer, ByVal NumEntries As Integer) As Integer
Declare Function SetPaletteEntries Lib "GDI" (ByVal hPalette As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function GetPaletteEntries Lib "GDI" (ByVal hPalette As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function GetSystemPaletteEntries Lib "GDI" (ByVal hdc As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, lpPaletteEntries As PALETTEENTRY) As Integer
Declare Function RealizePalette Lib "User" (ByVal hdc As Integer) As Integer
Declare Function GetBitmapBits Lib "GDI" (ByVal hBitmap As Integer, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function SetBitmapBits Lib "GDI" (ByVal hBitmap As Integer, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function GetObject Lib "GDI" (ByVal hObject As Integer, ByVal nCount As Integer, lpObject As Any) As Integer
Declare Function GetNearestPaletteIndex Lib "GDI" (ByVal hPalette As Integer, ByVal crColor As Long) As Integer
Sub TraceRay(depth As Integer, px As Single, py As Single, pz As Single, Vx As Single, Vy As Single, Vz As Single, r As Integer, G As Integer, B As Integer)
Dim i As Integer
Dim best_i As Integer
Dim best_dist As Single
Dim dist As Single
If Objects.Count < 1 Then Exit Sub
' Find the object that's closest.
best_dist = INFINITY
best_i = -1
For i = 1 To Objects.Count
dist = Objects.Item(i).RayDistance( _
px, py, pz, Vx, Vy, Vz)
If best_dist > dist Then
best_dist = dist
best_i = i
End If
Next i
' If we hit nothing, return the background color.
If best_i < 1 Then
r = BackR
G = BackG
B = BackB
Exit Sub
End If
' Compute the color at that point.
Objects.Item(best_i).HitColor depth, Objects, r, G, B
' This is a problem for some values of LightKdist.