; SetEntityLODDistance Example
; ----------------------------

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

camera=CreateCamera()
PositionEntity camera,0,1,-6

light=CreateLight()
RotateEntity light,45,45,0

; A detailed pickup with a much simpler version
gem=CreateSphere(32)
ScaleMesh gem,0.8,1.2,0.8
EntityColor gem,80,200,255
SimplifyEntityLOD gem,1,0.05

; Where the simpler version takes over, in metres from the camera
switch#=10
SetEntityLODDistance gem,1,switch,camera

wire=True

While Not KeyDown(1)

    ; [ / ] bring the switch nearer or push it further away
    change#=0
    If KeyHit(26) And switch>2 Then change=-2
    If KeyHit(27) And switch<40 Then change=2
    If change<>0
        switch=switch+change
        SetEntityLODDistance gem,1,switch,camera
    EndIf

    ; Space shows the triangles
    If KeyHit(57) Then wire=Not wire
    WireFrame wire

    TurnEntity gem,0,1,0

    ; 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   [ / ] : move the switch   Space: wireframe   Esc: exit"
    Text 0,20,"SetEntityLODDistance gem,1,"+switch+",camera   (EntityLODDistance says "+Int(EntityLODDistance(gem,1,camera))+")"
    Text 0,40,"Camera "+Int(EntityDistance(camera,gem))+" m away: drawing level "+EntityLODLevel(gem,camera)

    Flip

Wend

End
