; Shadows - ArcBasic extension sample ; ; LightShadows makes a light cast real-time shadows ; EntityShadows chooses what casts and receives them ; ShadowQuality sets how sharp and smooth they are ; ; Keys: S sun shadows on/off L lantern shadows on/off ; Q shadow quality Space pause the sun ; Left/Right orbit camera Escape quit Graphics3D 800,600,0,2 SetBuffer BackBuffer() ; camera on a pivot so it can orbit the scene pivot=CreatePivot() camera=CreateCamera(pivot) PositionEntity camera,0,9,-20 PointEntity camera,pivot CameraClsColor camera,110,150,210 AmbientLight 70,70,85 ; the sun - a directional light that slowly swings across the sky sun=CreateLight(1) RotateEntity sun,50,20,0 LightShadows sun ; a lantern - a point light casting its own shadows lantern=CreateLight(2) LightColor lantern,255,170,80 LightRange lantern,14 LightShadows lantern lamp=CreateSphere(8) ScaleEntity lamp,.25,.25,.25 EntityColor lamp,255,200,120 EntityFX lamp,1 ; full-bright: it is the light, it casts no shadow ShadowQuality 2 ; ground ground=CreatePlane() tex=LoadTexture("ground.bmp") ScaleTexture tex,8,8 EntityTexture ground,tex ; a ring of pillars For i=0 To 7 p=CreateCylinder(12) ScaleEntity p,.5,3,.5 PositionEntity p,Sin(i*45)*7,3,Cos(i*45)*7 EntityColor p,210,200,185 Next ; something with curves in the middle teapot=LoadMesh("teapot.x") If teapot FitMesh teapot,-2,0,-1.5,4,3,3,True EntityColor teapot,180,60,50 Else teapot=CreateSphere(16) PositionEntity teapot,0,1.5,0 ScaleEntity teapot,1.5,1.5,1.5 EntityColor teapot,180,60,50 EndIf ; a bouncing ball ball=CreateSphere(16) EntityColor ball,70,120,230 ; a cube that ignores shadows completely: it casts none and none fall on it ghost=CreateCube() PositionEntity ghost,4,1,-4 EntityColor ghost,240,240,120 EntityShadows ghost,False,False sunShadows=True : lanternShadows=True : quality=2 : paused=False While Not KeyHit(1) If KeyHit(31) sunShadows=Not sunShadows LightShadows sun,sunShadows EndIf If KeyHit(38) lanternShadows=Not lanternShadows LightShadows lantern,lanternShadows EndIf If KeyHit(16) quality=(quality+1) Mod 4 ShadowQuality quality EndIf If KeyHit(57) Then paused=Not paused If KeyDown(203) Then TurnEntity pivot,0,1.5,0 If KeyDown(205) Then TurnEntity pivot,0,-1.5,0 t#=MilliSecs()/1000.0 If Not paused Then TurnEntity sun,0,.3,0 PositionEntity lantern,Sin(t*40)*4.5,2.5,Cos(t*40)*4.5 PositionEntity lamp,EntityX(lantern),EntityY(lantern),EntityZ(lantern) PositionEntity ball,-4,1+Abs(Sin(t*150))*3,3 RenderWorld Color 255,255,255 Text 10,10,"SHADOWS (ArcBasic extension)" If sunShadows Then s$="on" Else s$="off" If lanternShadows Then l$="on" Else l$="off" Text 10,30,"S sun shadows: "+s$ Text 10,45,"L lantern shadows: "+l$ Text 10,60,"Q shadow quality: "+quality+" of 3" Text 10,75,"Space pause sun Left/Right orbit Esc quit" Text 10,580,"The yellow cube uses EntityShadows ghost,False,False" Flip Wend End