Non, regarde le code plus bas.
En revanche c'est une lumiere omnidirectionnelle, je te laisse le plaisir de le faire pour un faisceau d'une torche ^^
Code : Tout sélectionner
InitSprite() : InitSprite3D() : InitKeyboard()
OpenScreen(800,600,32,"")
Structure vertex
sx.f
sy.f
sz.f
rhw.f
Color.l
specular.l
tu.f
tv.f
EndStructure
Structure PB_Sprite3D
Texture.l
Vertice.vertex[4]
Width.w
Height.w
EndStructure
Structure COMPLEX_MAP2D
*SpritePtr.PB_Sprite3D ;Pointeur du sprite3D
Sprite3DID.l
EndStructure
Global Dim Map.COMPLEX_MAP2D(13,10) ; peut etre remplacer par allocate memory pour des perfs optimales
Procedure RGBA(Red,Green,Blue,Alpha)
ProcedureReturn RGB(Blue,Green,Red) + Alpha << 24
EndProcedure
Procedure Distance(x1,y1,x2,y2)
Protected Result.f
Result = Sqr( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )
ProcedureReturn Result
EndProcedure
Procedure CreateGround(x,y,SpriteID)
SPR3DID=CreateSprite3D(#PB_Any,SpriteID)
Map(x,y)\SpritePtr = IsSprite3D(SPR3DID)
Map(x,y)\Sprite3DID = SPR3DID
EndProcedure
;/ CREATION DU SPRITE 2D
Enumeration
#FLOOR
EndEnumeration
CreateSprite(#FLOOR,64,64,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(#FLOOR))
Box(0,0,64,64,RGB($CE,$CE,$CE))
Box(2,2,60,60,RGB($7E,$A8,$B4))
For i = 0 To 200
R = Random(10)-Random(10)
Plot(Random(60)+2,Random(60)+2,RGB(126+R,168+R,80+R))
Next
StopDrawing()
For y = 0 To 10
For x = 0 To 13
CreateGround(x,y,#FLOOR)
Next
Next
Global AmbientLight = 0
Global PointLight.POINT
Repeat
ExamineKeyboard()
PointLight\x = 256 + 100 * Cos(ElapsedMilliseconds()/500)
PointLight\y = 256 + 100 * Sin(ElapsedMilliseconds()/500)
Start3D()
For y = 0 To 10
For x = 0 To 13
;/
; INTERPOLATION DE LA LUMIERE SUIVANT LA DISTANCE ENTRE LE POINT LUMINEUX ET LES VERTICES
V0_DIST = Distance(PointLight\x,PointLight\y,x*64,y*64)
If V0_DIST<255
AmbientLight = 255 - V0_DIST
Map(x,y)\SpritePtr\Vertice[0]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
Else
AmbientLight = 0
Map(x,y)\SpritePtr\Vertice[0]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
EndIf
;/
V1_DIST = Distance(PointLight\x,PointLight\y,x*64+64,y*64)
If V1_DIST<255
AmbientLight = 255 - V1_DIST
Map(x,y)\SpritePtr\Vertice[1]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
Else
AmbientLight = 0
Map(x,y)\SpritePtr\Vertice[1]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
EndIf
;/
V2_DIST = Distance(PointLight\x,PointLight\y,x*64,y*64+64)
If V2_DIST<255
AmbientLight = 255 - V2_DIST
Map(x,y)\SpritePtr\Vertice[2]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
Else
AmbientLight = 0
Map(x,y)\SpritePtr\Vertice[2]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
EndIf
;/
V3_DIST = Distance(PointLight\x,PointLight\y,x*64+64,y*64+64)
If V3_DIST<255
AmbientLight = 255 - V3_DIST
Map(x,y)\SpritePtr\Vertice[3]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
Else
AmbientLight = 0
Map(x,y)\SpritePtr\Vertice[3]\Color = RGBA(AmbientLight,AmbientLight,AmbientLight,255)
EndIf
;/
DisplaySprite3D(Map(x,y)\Sprite3DID,x*64,y*64)
Next
Next
Stop3D()
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
Circle(PointLight\x-3,PointLight\y-3,6,RGB(255,0,0))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)