; Convert the default font to a bitmap font MakeBitmapFont 1,$ffffff ; Create 2 variables that will be used as the worlds size WorldWidth =3000 WorldHeight =3000 ; create a Camera (this camera will attach it self to the ; current surface, in this that example, current surface will ; be the Screen) MyCamera=NewCamera() ; Limit the cameras movement to the inside the world space LimitCamera MyCamera,true LimitCameraBounds MyCamera,0,0,WorldWidth+1,WorldHeight+1 Restart: ; check if the world previously exists, if so, delete it If GetWorldStatus(MyWorld) Then DeleteWorld MyWorld ; Create world MyWorld=NewWorld() ; ReDirect All Drawing to be captured to world buffer #2 CaptureToWorld MyWorld ; Create a list of Constants that will be used to ID the different gfx types ; that were captured into the world buffer ACSet =0 Constant Gfx_Item_Dot =AC(1) Constant Gfx_Item_Line =AC(1) Constant Gfx_Item_Box =AC(1) Constant Gfx_Item_Circle =AC(1) Constant Gfx_Item_Shape =AC(1) Constant Gfx_Item_Max =AC(1) ; max size of a gfx item Size=500 ; NUmber of gfx items to capture Max_Gfx_Items=250 ; Define a type and array to hold the position/type information ; about each item. Just so we can highlight them in this demo. Type tObjectInfo ItemType Coords(4) Radius FillState Colour MediaIndex EndType Dim Items(Max_Gfx_Items) As tObjectInfo ; Set the Capture Z Depth to 100 CaptureDepth 100 ; Capture the Gfx items For lp=0 To Max_Gfx_Items ; Random select a Item Type ot capture into the world buffer ThisGFXitem = Rnd(Gfx_Item_Max-1) ; reset the coords x=0:y=0 x2=x:y2=y col =RndRGB() And $7f7f7f FillState =Rnd(1) radius=0 MediaIndex=0 Select ThisGfxItem Case Gfx_Item_Dot X=Rnd(WorldWidth) Y=Rnd(WorldHeight) ; draw the dot the world buffer DotC X,Y,Col Case Gfx_Item_Line X=Rnd(WorldWidth) Y=Rnd(WorldHeight) X2=x+Rnd(size) Y2=Y+Rnd(size) ; draw the dot the world buffer LineC X,Y,x2,y2,Col Case Gfx_Item_Box X=Rnd(WorldWidth) Y=Rnd(WorldHeight) X2=x+Rnd(size) Y2=Y+Rnd(size) ; draw the dot the world buffer BoxC X,Y,x2,y2,fillstate,Col Case Gfx_Item_Circle X=Rnd(WorldWidth) Y=Rnd(WorldHeight) Radius=Rnd(100) ; draw the dot the world buffer CircleC X,Y,radius,fillstate,Col Case Gfx_Item_Shape Radius=Rnd(100) MediaIndex=GetFreeShape() CreateConvexShape MediaIndex,Radius,RndRange(3,20) X=Rnd(WorldWidth) Y=Rnd(WorldHeight) ; draw/capture the Shape the world buffer DrawShape MediaIndex,X,Y,1 EndSelect ; Store the info about this ITem in array, so we can read it later Items(lp).ItemType =ThisGfxItem Items(lp).Coords(1) =x Items(lp).Coords(2) =y Items(lp).Coords(3) =x2 Items(lp).Coords(4) =y2 Items(lp).Radius =radius Items(lp).FillState =FillState Items(lp).Colour =Col Items(lp).MediaIndex =MediaIndex Next ; Partition The world up into 64 by 64 cells PartitionWorld MyWorld,64 ; Tell PB to return to Immediate drawing mode DrawGFXImmediate Camx#=WorldWidth/2 Camy#=WorldHeight/2 ; ================================================= ; CReate a Memory bank. This Bank is where we'll store the QueryWorldRegion results ; ================================================= ; Create the bank with plenty of space CreateBank 1,1000 ; start of DO/Loop Do ; Tell PB to redirect all GFX drawing commands to the scene buffer CaptureToScene ; Clear the scene buffer ClsScene ;Move the Camera With Arrow Keys CamSpeed#=5 If LeftKey() Then CamX#=CamX#-CamSpeed# If RightKey() Then CamX#=CamX#+CamSpeed# If UpKey() Then CamY#=CamY#-CamSpeed# If DownKey() Then CamY#=CamY#+CamSpeed# ; Calc A region 200*200 around the current camera position x1#=Camx#-100 y1#=Camy#-100 x2#=Camx#+100 y2#=Camy#+100 ; draw this region the user can see it CaptureDepth 1 Box x1#,y1#,x2#,Y2#,0 ; Query World Region check the worlds parition buffer for a list of objects ; that share this region. ; The function returns the number of Items who's BOUNDING BOXES share ; the same region. ; NOTE: Objects are returned in a pre-allocated memory buffer, function ; expected you to pass it a POINTER to this buffer. So you ; actually get it write the valeus into an INTEGER array if you ; want also. But that's not a easy for the user at this time.. ItemsFound=QueryWorldRegion(MyWorld,x1#,y1#,x2#,y2#,GetBankPtr(1)) If ItemsFound>0 CaptureDepth 10 For lp=0 To (ItemsFound-1) GfxItem=PeekBankInt(1,lp*4) x =Items(GfxItem).Coords(1) y =Items(GfxItem).Coords(2) x2 =Items(GfxItem).Coords(3) y2 =Items(GfxItem).Coords(4) Radius =Items(GfxItem).Radius FillState =Items(GfxItem).FillState MediaIndex =Items(GfxItem).MediaIndex Col =RGBFade(Items(GfxItem).Colour,200) Select Items(GfxItem).ItemType Case Gfx_Item_Dot ; draw the dot the world buffer DotC X,Y,Col CircleC x,y,3,0,RndRGB() Case Gfx_Item_Line ; draw the dot the world buffer LineC X,Y,x2,y2,Col CircleC x,y,3,0,RndRGB() CircleC x2,y2,3,0,RndRGB() Case Gfx_Item_Box ; draw the dot the world buffer BoxC X,Y,x2,y2,fillstate,Col CircleC x,y,3,0,RndRGB() CircleC x2,y2,3,0,RndRGB() CircleC x2,y,3,0,RndRGB() CircleC x,y2,3,0,RndRGB() Case Gfx_Item_Circle ; draw the dot the world buffer CircleC X,Y,radius,fillstate,Col CircleC x,y,2,0,RndRGB() Case Gfx_Item_Shape Ink Col ; draw/capture the Shape the world buffer DrawShape MediaIndex,X,Y,2 EndSelect ; Store the info about this ITem ; Items(lp).ItemType=ThisGfxItem Next EndIf PositionCamera MyCamera,CamX#-(GetScreenWidth()/2),Camy#-(GetScreenHeight()/2) CaptureDepth 100 CameraGrabWorld MyCamera,MyWorld ; draw the camera DrawCamera MyCamera ; show the fps rate and continue this loop Text 0,0,FPS() Text 0,10,itemsfound If SpaceKey() Then Goto restart Sync Loop |