; DebugLightVolume Example
; ------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,5,-12

AmbientLight 50,50,50

; A dark prison yard floor with some crates
floor=CreatePlane()
EntityColor floor,60,70,80

crate1=CreateCube()
PositionEntity crate1,-2,1,2
EntityColor crate1,150,110,70

crate2=CreateCube()
PositionEntity crate2,3,1,4
EntityColor crate2,150,110,70

; A searchlight sweeping the yard
light=CreateLight(3)
PositionEntity light,0,6,3
LightRange light,10
LightConeAngles light,15,35

show=True

While Not KeyDown(1)

    ; Space toggles the volume overlay
    If KeyHit(57) Then show=Not show

    ; Swing the searchlight back and forth
    angle#=angle+1
    RotateEntity light,65,50*Sin(angle),0

    ; DebugLightVolume queues the spot light's current range and cone
    If show Then DebugLightVolume light

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   Space: toggle overlay   Esc: exit"
    If show Then Text 0,20,"The cone matches LightRange 10 and LightConeAngles 15,35" Else Text 0,20,"Overlay off - press Space"

    Flip

Wend

End
