Main Menu

PlayBasicFX Screen Shot Updates

Started by kevin, February 16, 2007, 11:45:46 AM

Previous topic - Next topic

kevin



3D City Scape + Terrain

    This example is of a 3D city scape that's generated in code.   The example uses the Sprite Entity feature of PB1.7x combined and Draw Perspective Sprite command to render a 3D scene.   


kevin

#76
PB1.71f TexturedPolyHitSprite Pixels

    This function is more a exposed helper function than a user function persay,  but it's there if you want to detect impacts between a textured convex polygon and a sprites pixels.




; Load a Ship image and prepare it for rotation
Load3DImage "..\..\..\..\gfx\ship.bmp",1

; Load the uw logo image as FX image as the texture
LoadFXImage "..\..\..\..\gfx\uwlogo.bmp",2


; get the images width + height
w=GetImageWidth(1)
h=GetImageHeight(1)


; Set the Max number of sprites in this test
max=1500
Dim Sprites(MAx)
Dim AddColour(max)

For lp=1 To max
; create a new sprite, and give it a random X & Y position
Spr2 =NewSprite(Rnd(800),Rnd(600),1)
; set the sprites drawmode to rotated (mode 2)
SpriteDrawMode spr2,2
; center sprite handle
CenterSpriteHandle spr2
; randomly scale the sprite
ScaleSprite Spr2,RndRange#(1,2)

Sprites(lp)=spr2
Next




Dim Poly as PBpositionUV pointer
Dim Vert1 as PBpositionUV pointer
Dim Vert2 as PBpositionUV pointer
Dim Vert3 as PBpositionUV pointer
Dim Vert4 as PBpositionUV pointer

VertexBuffer=Newbank(1000)

poly=GetBankPtr(VertexBuffer)

Vert1=GetBankPtr(VertexBuffer)
Vert2=GetBankPtr(VertexBuffer)+20
Vert3=GetBankPtr(VertexBuffer)+40
Vert4=GetBankPtr(VertexBuffer)+60







; Start of program Main loop
Do
; clear the screen to RGB colour 100,100,100
Cls RGB(100,100,100)

; Get the Mouse Position
mX=MouseX()
mY=MouseY()



texture=2


// Set Vertex 1
vert1.x =-200.00 +mx
vert1.y =0.00 +my
vert1.u =0.0
vert1.v =0.0

vert2.x =300.00 +mx
vert2.y =000.00 +my
vert2.u =float(GetImageWidth(Texture))
vert2.v =0.0


Vert3.x =300.00 +mx
Vert3.y =200.00 +my
Vert3.u =float(GetImageWidth(Texture))
Vert3.v = float(GetImageheight(Texture))


Vert4.x =-200.00 +mx
Vert4.y =200.00 +my
Vert4.u =float(0)
Vert4.v = float(GetImageheight(Texture))

; run Through and check if this point is over a sprite
For lp=1 To max
; get the sprite index
Spr2=Sprites(lp)
AddColour(lp)=0

; turn the sprite
Turnsprite Spr2,(lp*0.05)

; reset this sprites draw mode to rotated (mode2)
SpriteDrawMode spr2,2

; Check if a textured quad hits this sprites pixels
If TexturedPolyHitSpritePixels(poly,4,texture,spr2,0.5)
AddColour(lp)=rgbalphaadd(AddColour(lp),$0fa07f)
EndIf


; set the colour addition colour for this sprite
if AddColour(lp)<>0

pokeSpritefacergb Spr2,0,0,AddColour(lp)
pokeSpritefacergb Spr2,0,1,AddColour(lp)
pokeSpritefacergb Spr2,0,2,AddColour(lp)
pokeSpritefacergb Spr2,0,3,AddColour(lp)

else
pokeSpritefacergb Spr2,0,0,$ffffff
pokeSpritefacergb Spr2,0,1,$ffffff
pokeSpritefacergb Spr2,0,2,$ffffff
pokeSpritefacergb Spr2,0,3,$ffffff

endif
Next


; draw all the sprites
DrawAllSprites
; draw the triangle and the quad regions Alpha blended to the frame buffer
inkmode 1+32
Tric tx1,ty1,tx2,ty2,tx3,ty3,rgb(0,0,255)
Quadc qx1,qy1,qx2,qy2,qx3,qy3,qx4,qy4,rgb(255,0,0)
inkmode 1

s$=str$(fps())
boxc xpos,ypos,xpos+GetTextWidth(s$),ypos+GetTextHeight(s$),true,0
Text xpos,ypos,s$


/*
texturetri texture, Vert1.x,Vert1.y,int(Vert1.u)*$10000,int(Vert1.v)*$10000,_
Vert2.x,Vert2.y,int(Vert2.u)*$10000,int(Vert2.v)*$10000,_
Vert3.x,Vert3.y,int(Vert3.u)*$10000,int(Vert3.v)*$10000,true
*/

textureQuad texture, Vert1.x,Vert1.y,int(Vert1.u)*$10000,int(Vert1.v)*$10000,_
Vert2.x,Vert2.y,int(Vert2.u)*$10000,int(Vert2.v)*$10000,_
Vert3.x,Vert3.y,int(Vert3.u)*$10000,int(Vert3.v)*$10000,_
Vert4.x,Vert4.y,int(Vert4.u)*$10000,int(Vert4.v)*$10000,true


; refresh the display
Sync

; loop back to the DO statement and continue this program
Loop





kevin

PB 1.71f Level Hit Sprite Pixels

    This example is demonstrating the current WIP of the new LevelHitSprite command.   This command allows you to detect pixel level intersections between a sprite and a map (level).  In the picture bellow the test version of the routine is running through and comparing the overlapping tiles + sprite.  If a tile collides with the sprite, the routine internally renders a red coloured rect at this position, so the collision is visible.   Obviously that's just for testing purposes atm.  The routine supports animated and static levels,  moreover the levels transparent tile is ignored during collision.   




loadfximage "D:\Play_Basic\PlayBasic\Projects_PB170\GFX\Ship.bmp",50

; =================================================
;  Part #1 - CREATE A MAP Manually
; =================================================

; Make a map with space with 5 levels
MyMap=NewMap(5)


;  Create some block gfx..   
BlockWidth =32
BlockHeight =42
BlockCount =10

; Create Block Gfx in out map.  These will be blank by default
CreateMapGfx MyMap,BlockWidth,BlockHeight,BlockCount,rgb(0,0,0)


; Draw an array of random blocks and copy them into the maps private block image
   For lp=1 to BlockCount
Cls 0

; Draw a randomly colours box to the screen 
; boxc 0,0,BlockWidth,Blockheight,true,rndrgb()

Circlec BlockWidth/2,Blockheight*0.5,10,true,rndrgb()

; draw a character to the box
CenterText BlockWidth/2,Blockheight*0.4,chr$(32+rnd(64))

; grab the upper corner of the screen as a block
GetMapBlk MyMap,lp,0,0
next



; Create Level #1 and attach it to MyMap  (100=width in tiles, 200 Height in tiles)
CreateLevel MyMap, 1,  100,200

blk=0
; Fill our level with random block indexes.  So it'll be a bit of a mess :)
   For ylp=0 to GetLevelHeight(myMap,1)-1
   For xlp=0 to GetLevelWidth(myMap,1)-1

; Poke (set) the block index at this x/y position in the level.
PokeLevelTile MyMap,1, Xlp,Ylp, blk
inc blk
if blk=>BlockCount then blk=0

next   
next   
   



; =================================================
;  Part #2 - CREATE A CAMERA
; =================================================

  ; create a new camera.  This camera's render output with be attached to the screen by default
  MyCamera=NewCamera()
 
 
 
Spr=newsprite(100,100,50)
centerspritehandle spr
SpriteDrawMode Spr,2
ScaleSprite Spr,5
SpriteCollisionMode Spr,6
SpriteCollisionDebug Spr,true


; =================================================
;  Part #3 - Main Loop
; =================================================
Setfps 30



Do

;
; MapX=(MapX+1) and 127
; MapY=(MapY+1) and 255

; Clear the scene buffer of any previous information
ClsScene

; Tell PB to capture all coming drawing commands to the scenebuffer
CaptureToScene


; Tell PB to give following captured (drawn) items a Z depth of 50.  This will make the circles draw in front of the map
CaptureDepth 50


; Draw a ring of circles in world space, these will be assigned a scene depth of 50 when PB captures them into the scene buffer
MaxCircles=10
For lp=0 to MaxCircles-1
Angle#=(lp*(360.0/MaxCircles))
Xpos#=1000+CosRadius(Angle#,600)
Ypos#=1000+SinRadius(Angle#,600)
   Circle Xpos#,Ypos#,100,true
next

; Tell PB to assign the next captured (drawn) items a Z depth of 100
CaptureDepth 100

; Draw the Map at position 0x , 0y in world space.  Since we're in capture mode
; this drawing request is captured to the scene buffer list.  So this object (map/level in this case)
; is positioned at 0,0 in world space.  With a Z depth of 100
DrawMap MyMap,1,MapX,MapY


positionsprite Spr,mousex(),mousey()

DrawAllSprites


; DRaw the camera.  This converts the objects held in the scenebuffer from world space to screen space
; Allowing us to position the camera anywhere we like (in world space) and render whatever objects are visible
; in that section of the world, and that are currently held in the scenebuffer  (captured to the scene). 
DrawCamera MyCamera

; Use arrows to Move the Camera through world space.
; If Leftkey() then MoveCamera Mycamera,-1,0
; If rightkey() then MoveCamera Mycamera,1,0
; If upkey() then MoveCamera Mycamera,0,-1
; If downkey() then MoveCamera Mycamera,0,1
;


; Use arrows to Move the Camera through world space.
If Leftkey() then MoveSprite Spr,-1,0
If rightkey() then MoveSprite Spr,1,0
If upkey() then MoveSprite Spr,0,-1
If downkey() then MoveSprite Spr,0,1

turnsprite Spr,1

result=levelhitsprite(MyMap,1,MapX,MapY,spr)
text 100,100,Result

; Call sync to refresh the physical display (swaps the hidden screen image with the visible one, so we can see it!)
sync


; Loop (jump) back to the DO statement to keep this program running in a LOOP
loop




kevin

#78
 PB 1.71f Level Hit Sprite Pixels (Xenon)

    This is a quick follow up on previous update about LevelHitSprite.  Here i'm simply beta testing the command in the standard scrolling demo, my multi camera Xenon 2000 remake.  The players bullets have pixel level collision against the foreground map level.   If a hit is detected the bullet pops the standard explosion anim (see the code snippet bellow).  The interesting thing is that it doesn't really add any overhead at all to the demo's performance.  Which is interesting since the bullet sprites and maps are standard video images.    But anyway, here's another piccy for good measure.




   // From Update Player Bullets function in the Player module

; Check if the bullet hits the front map layer
if LevelHitSprite(ThisMap,1,0,0,ThisSprite)=true
xpos#=GetSpriteX(ThisSprite)
ypos#=GetSpriteY(ThisSprite)
zpos#=GetSpriteZ(ThisSprite)
Add_Explosion(Aliens().TAlien,ThisPlayer,Xpos#,Ypos#,Zpos#,1)
Delete_Bullet(Bull().TPlayerBullet,lp)
Continue
endif
 



kevin

#79
 Simple Xfile Loader - TeaPot (untextured)

       This picture is shows the results of loading a DirectX 3D object file into PB.   The loader is rough as guts and can only load basic geometry as this point.  My aim is just to get it loading 'simple' textured objects.  Which would allow you to explore 2D / 3D combinations a little more seriously.


kevin

#80
 Simple Xfile (ASCII) Loader - Dragon (textured)

    The loader has been updated to support textured objects.  It's still not pretty, but they load pretty fast and you can get some 3D happening in your games.  The following pictures are of a simple textured dragon model thrown into the city space scene example. 



Example

   Get Source Code  (requires PlayBasic V1.70 or higher)



Adaz

Where can I find this particle_white.bmp?

Ádáz

Hungary

ATLUS

PB1.68h alpha???its new version PlayBasic? :o

kevin

 No, it's a transitional version between PB V1.63 (from back in 2007) and todays PBFX1.74