samples/JamesH/Shadows
shadows.abs
114 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.
; 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 quitGraphics3D 800,600,0,2SetBuffer BackBuffer(); camera on a pivot so it can orbit the scenepivot=CreatePivot()camera=CreateCamera(pivot)PositionEntity camera,0,9,-20PointEntity camera,pivotCameraClsColor camera,110,150,210AmbientLight 70,70,85; the sun - a directional light that slowly swings across the skysun=CreateLight(1)RotateEntity sun,50,20,0LightShadows sun; a lantern - a point light casting its own shadowslantern=CreateLight(2)LightColor lantern,255,170,80LightRange lantern,14LightShadows lanternlamp=CreateSphere(8)ScaleEntity lamp,.25,.25,.25EntityColor lamp,255,200,120EntityFX lamp,1 ; full-bright: it is the light, it casts no shadowShadowQuality 2; groundground=CreatePlane()tex=LoadTexture("ground.bmp")ScaleTexture tex,8,8EntityTexture ground,tex; a ring of pillarsFor 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,185Next; something with curves in the middleteapot=LoadMesh("teapot.x")If teapot FitMesh teapot,-2,0,-1.5,4,3,3,True EntityColor teapot,180,60,50Else teapot=CreateSphere(16) PositionEntity teapot,0,1.5,0 ScaleEntity teapot,1.5,1.5,1.5 EntityColor teapot,180,60,50EndIf; a bouncing ballball=CreateSphere(16)EntityColor ball,70,120,230; a cube that ignores shadows completely: it casts none and none fall on itghost=CreateCube()PositionEntity ghost,4,1,-4EntityColor ghost,240,240,120EntityShadows ghost,False,FalsesunShadows=True : lanternShadows=True : quality=2 : paused=FalseWhile 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" FlipWendEnd
