i threw this togher in five too show you guys roughly how im doing it. the benefit of how im doing it here is that if you put a solid object in the light map ie a pole it will cause the light too split up...
also too do it this way i would probably use a reduced res light map maybe 128*128 or something then scale it up for speed.
let me know if you guys think there are other ways of doing it cheers.
the code is seriously unoptimised it can run much much faster.
#Include "Tinyptc_ext.Bi"
#Include "Windows.Bi"
Option Explicit
Const XRes = 640
Const YRes = 480
Dim Shared As Double WndOrgX = XRes/2
Dim Shared As Double WndOrgY = YRes/2
RANDOMIZE TIMER
Type TimerType
Frequency As LARGE_INTEGER
LiStart As LARGE_INTEGER
LiStop As LARGE_INTEGER
LlTimeDiff As LONGLONG
MDuration As Double
End Type
Declare Sub MyLine( byval x1 as integer, byval y1 as integer, byval x2 as integer, byval y2 as integer, ByVal Col As Integer )
Declare Sub PtcOpen()
Declare Sub StartTimer( TempTimer As TimerType Ptr )
Declare Sub DestroyTimer( TempTimer As TimerType Ptr )
Declare Function NewTimer() As TimerType Ptr
Declare Function GetTimerMs( TempTimer As TimerType Ptr ) As Double
Declare Function GetTimerSec( TempTimer As TimerType Ptr ) As Double
Dim Shared As Double Col1 = 0,Col2 = 0, Col3 = 0, mx = 0, my = 0
Dim Shared As Double TimerVal
Dim Shared As Double angle
Dim Shared Zoom As Integer
Dim Shared As Integer Buffer( XRes * YRes )
Dim Shared As Integer LightMap( Xres * Yres )
Dim Shared As TimerType Ptr FrameTimer, DemoTimer
Dim Shared As Integer LightMapX, LightMapY
FrameTimer = NewTimer()
DemoTimer = NewTimer()
PtcOpen()
While ( GetAsyncKeyState( VK_ESCAPE ) <> -32767 )
Dim As Integer X,Y
Dim As Integer PreXorCol
StartTimer( FrameTimer )
For x = 0 To Xres - 1
For y = 0 To Yres - 1
Next
Next
Dim As Integer PreX,PreY,Pre1Y,Pre1X
Dim As Integer ArrayIndex
PreX = LightMapX / 2
For y=0 To Yres - 1
PreY = ( ( y - LightMapY / 2 ) ^ 2 )
Pre1Y = ( ( Y / 12 ) And 1 )
For x=0 To Xres - 1
PreXorCol = 255*( ( ( X / 12 ) And 1 ) Xor Pre1Y )
Col1 = PreXorCol
Col2 = PreXorCol
Col3 = PreXorCol
ArrayIndex = x + (y*Xres-1)
Lightmap( ArrayIndex ) =255-Sqr( ( ( x - PreX ) ^ 2 ) + PreY )/1.2
Col1 += LightMap( ArrayIndex )
if Col1 > 255 Then Col1=255
if Col1 < 0 Then Col1 = 0
Col2 = Col1
Col3 = Col1
Buffer( ArrayIndex ) = Rgb(Col1,Col2,Col3)
Next
Next
TimerVal = GetTimerMs( DemoTimer )/4
LightMapX = (Yres)+Sin( TimerVal/320*3.14 ) * 450
LightMapY = (Xres)+Cos( TimerVal/320*3.14 ) * 450
Ptc_Update( @Buffer(0) )
do
Loop While ( GetTimerMs( FrameTimer ) <= 1000.0/60.0 )'60fps Clamp
Wend
DestroyTimer( FrameTimer )
DestroyTimer( DemoTimer )
Sub PtcOpen()
Ptc_AllowClose(0)
Ptc_SetDialog(1,"NinosFirstTunnel"+CHR$(13)+"FullScreen",0)
Ptc_SetFlip(1)
If ( Ptc_Open( "Tunnel", XRes, YRes ) = 0 ) Then
End - 1
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'infamous line algorythm found years ago some where in google world'
'ported From c '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub MyLine( byval x1 as integer, byval y1 as integer, byval x2 as integer, byval y2 as integer, ByVal Col As Integer )
dim i, deltax, deltay, numpixels as integer
dim d, dinc1, dinc2 as integer
dim x, xinc1, xinc2 as integer
dim y, yinc1, yinc2 as integer
'If X1 < 1 Then X1 = 1
'If X1 > Xres Then X1 = Xres-1
'If X2 < 1 Then X2 = 1
'If X2 > Xres Then X2 = Xres-1
'If Y1 < 1 Then Y1 = 1
'If Y1 > Yres Then Y1 = Yres-1
'If Y2 < 1 Then Y2 = 1
'If Y2 > Yres Then Y2 = Yres-1
'calculate deltaX and deltaY
deltax = abs(Cast(integer,x2 - x1))
deltay = abs(Cast(integer,y2 - y1))
'initialize
if ( deltax >= deltay ) then
'If x is independent variable
numpixels = deltax + 1
d = ( 2 * deltay ) - deltax
dinc1 = deltay shl 1
dinc2 = ( deltay - deltax ) shl 1
xinc1 = 1
xinc2 = 1
yinc1 = 0
yinc2 = 1
else
'if y is independent variable
numpixels = deltay + 1
d = ( 2 * deltax ) - deltay
dinc1 = deltax shl 1
dinc2 = ( deltax - deltay ) shl 1
xinc1 = 0
xinc2 = 1
yinc1 = 1
yinc2 = 1
endif
'move the right direction
if ( int(x1) > int(x2) ) then
xinc1 = -xinc1
xinc2 = -xinc2
endif
if ( int(y1) > int(y2) ) then
yinc1 = -yinc1
yinc2 = -yinc2
endif
X = Cast(Integer,X1)
Y = Cast(Integer,Y1)
'draw the pixels
For I = 1 To NumPixels
If Y > 2 And Y < Yres - 2 Then
If X > 2 and X < Xres - 2 Then
Buffer( Y*Xres+X ) = Col
End If
End If
If ( d < 0 ) Then
d = d + dinc1
x = x + xinc1
y = y + yinc1
Else
d = d + dinc2
x = x + xinc2
y = y + yinc2
EndIf
Next
End Sub
Function NewTimer() As TimerType Ptr
Dim As TimerType Ptr TempTimer
TempTimer = CAllocate( SizeOf( TimerType ) )
QueryPerformanceFrequency( @TempTimer->Frequency )
NewTimer = TempTimer
End Function
Sub StartTimer( TempTimer As TimerType Ptr )
QueryPerformanceCounter( @TempTimer->LiStart )
End Sub
Function GetTimerMs( TempTimer As TimerType Ptr ) As Double
QueryPerformanceCounter( @TempTimer->LiStop )
TempTimer->LlTimeDiff = TempTimer->LiStop.QuadPart - TempTimer->LiStart.QuadPart
TempTimer->MDuration = Cast( Double, TempTimer->LlTimeDiff ) * 1000.0 / Cast( Double , TempTimer->Frequency.QuadPart )
GetTimerMs = TempTimer->MDuration
End Function
Function GetTimerSec( TempTimer As TimerType Ptr ) As Double
QueryPerformanceCounter( @TempTimer->LiStop )
TempTimer->LlTimeDiff = TempTimer->LiStop.QuadPart - TempTimer->LiStart.QuadPart
TempTimer->MDuration = Cast( Double, TempTimer->LlTimeDiff ) * 1000.0 / Cast( Double , TempTimer->Frequency.QuadPart )
GetTimerSec = TempTimer->MDuration/1000.0
End Function
Sub DestroyTimer( TempTimer As TimerType Ptr )
If ( TempTimer ) Then
DeAllocate( TempTimer )
EndIf
End Sub