Is there then a way to make light1, light2 ,light3......... the name of the type from a function so i could just call Delete Light1, or would i be better off just creating a new type for every light without a function & then Delete it when needed.
Here is the test i have been playing with anyway. I hope to be able to use it for lighting from explosions, bullets & the like in an asteroids clone i am working on.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;Fakelight test
;
;Author: Robert Hogg
;Date : 24\4\2010
;
;Fklightentity(entity,fx(2 or 3),ambient_R,ambient_G,ambient_B,) sets entitys ambient light color
; & lighting effects. Fx 2 Dxlights &
; fake. Fx 3 fake lights only.
;
;create_st_fklight(X,Y,Z,R,G,B,Range) creates a static fakelight.
;
;create_dy_fklight(Parent,R,G,B,Range) creates a dynamic light that needs to be parented to an
; entity. Move the parent entity to affect fakelights position.
; Will eventualy be able to change the r,g,b values & the range.
;
;Update_fklightentity() must be called at the end of a loop to reset entitys light effects.
;
;update_st_fklights() must be called to update all static lights
;
;update_dy_fklights() must be called to update dynamic lights
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AppTitle "Fakelight Test"
Graphics3D 640,480,16,2
Global lighton
cube=CreateCube()
PositionEntity cube,0,0,0
cone=CreateCone(20)
PositionEntity cone,-5,0,0
cyl=CreateCylinder(20)
PositionEntity cyl,5,0,0
camera=CreateCamera()
PositionEntity camera,0,5,-15
piv=CreatePivot()
PositionEntity piv,EntityX(cube),EntityY(cube),EntityZ(cube)
sphere = CreateSphere(20,piv)
PositionEntity sphere,0,0,10
light = CreateLight()
RotateEntity light,90,0,0
fklightentity(cube,2,100,100,100)
fklightentity(cone,3,100,100,100)
fklightentity(cyl,3,100,100,100)
fklightentity(sphere,3,100,100,100)
;create_st_fklight(0,-15,0,0,255,0,5)
;create_st_fklight(-15,0,0,0,0,255,5)
;create_st_fklight(15,0,0,255,0,0,5)
;create_st_fklight(0,0,-15,200,255,0,5)
create_st_fklight(0,2,10,255,0,255,2)
create_st_fklight(-10,2,0,0,255,255,2)
create_st_fklight(0,2,-10,255,255,255,2)
create_st_fklight(10,2,0,255,255,0,2)
piv1=CreatePivot()
PositionEntity piv,EntityX(cube),EntityY(cube),EntityZ(cube)
lightsphere = CreateSphere(20,piv1)
EntityColor lightsphere,0,100,255
PositionEntity lightsphere,0,0,-11
EntityFX lightsphere,1
;fklightentity(lightsphere,3,100,100,100)
create_dy_fklight(light1,lightsphere,0,100,255,5)
lighton = True
If lighton Then ShowEntity light
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyDown(1)
If KeyHit (57)
lighton= Not lighton
If lighton Then ShowEntity light Else HideEntity light ; turns light on & off
EndIf
PointEntity camera,cube
TurnEntity cube,1,1.5,2
TurnEntity cone,.5,.1,0
TurnEntity cyl,-.5,-.1,0
TurnEntity piv,0,1,0
TurnEntity piv1,.5,0,0
Update_fklightentity()
update_st_fklights()
update_dy_fklights()
UpdateWorld
RenderWorld
Text 0,0,"The cube is lit with both fake & DXlights."
Text 0,12,"Press space to turn on & off DXLight."
Flip
Wend
End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Type fklightentity
Field entity
Field fx%
Field ambientr%
Field ambientg%
Field ambientb%
End Type
Function fklightentity(entity,fx%,ambientr,ambientg,ambientb)
Light.fklightentity = New fklightentity
Light\entity=entity
LightMesh Light\entity,-255,-255,-255
EntityFX Light\entity,fx%
Light\ambientr=ambientr
Light\ambientg=ambientg
Light\ambientb=ambientb
LightMesh Light\entity,Light\ambientr,Light\ambientg,Light\ambientb
End Function
Function Update_fklightentity()
For Light.fklightentity = Each fklightentity
LightMesh Light\entity,-255,-255,-255
LightMesh Light\entity,Light\ambientr,Light\ambientg,Light\ambientb
Next
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Type fklight
Field light_piv
Field entity
Field light
Field red#
Field green#
Field blue#
Field range#
Field x#
Field y#
Field z#
End Type
Function create_st_fklight(x#,y#,z#,r#,g#,b#,range#)
light_fake.fklight = New fklight
light_fake\light_piv = CreatePivot()
light_fake\x=x#
light_fake\y=y#
light_fake\z=z#
light_fake\red#=r#
light_fake\green#=g#
light_fake\blue#=b#
light_fake\range#=range#
End Function
Function update_st_fklights()
For light_fake.fklight = Each fklight
PositionEntity light_fake\light_piv,light_fake\x#,light_fake\y#,light_fake\z#
For Light.fklightentity = Each fklightentity
If (Light.fklightentity <> Null) Then
TFormPoint 0,0,0,light_fake\light_piv,Light\entity
LightMesh Light\entity,light_fake\red,light_fake\green,light_fake\blue,light_fake\range,TFormedX(),TFormedY(),TFormedZ()
End If
Next
Next
End Function
Type dyfklight
Field light_piv
Field entity
Field light
Field red#
Field green#
Field blue#
Field range#
Field x#
Field y#
Field z#
End Type
Function create_dy_fklight(Name$,parent,r#,g#,b#,range#)
dylight_fake.dyfklight = New dyfklight
dylight_fake\light_piv = CreatePivot(parent)
dylight_fake\red#=r#
dylight_fake\green#=g#
dylight_fake\blue#=b#
dylight_fake\range#=range#
End Function
Function update_dy_fklights()
For dylight_fake.dyfklight = Each dyfklight
For Light.fklightentity = Each fklightentity
If (Light.fklightentity <> Null) Then
TFormPoint 0,0,0,dylight_fake\light_piv,Light\entity
LightMesh Light\entity,dylight_fake\red,dylight_fake\green,dylight_fake\blue,dylight_fake\range#,TFormedX(),TFormedY(),TFormedZ()
End If
Next
Next
End Function
|