PlayBasicFX Screen Shot Updates

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

Previous topic - Next topic

kevin

  PB170l  Running EllipseHitSpritePixels 1500 Rotating Scaling sprites

   and here's the ellipse version.



kevin

#61
  PB170l  LineHitSpritePixels

     This example is running the lineHitSpritePixels function on a 1500 Rotating Scaling sprites. 




  ; -----------------------------------------------------------
  ;               >>>>>  LINE Hit Sprite Pixels <<<<<<<
  ; -----------------------------------------------------------

; Load a Ship image and prepare it for FX (rotation)
Load3DImage "..\..\..\..\gfx\ship.bmp",1
rgbmaskimage 1,$ffffff

; 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)

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

; Turn Sprite Collision OFF - as were manually checking for collisions bellow
SpriteCollision spr2, off

; SpriteCollisionMode spr2, 6
; SpriteCollisionDebug spr2,true

; center sprite handle
CenterSpriteHandle spr2

; randomly scale the sprite
ScaleSprite Spr2,RndRange#(1,2)

Sprites(lp)=spr2
Next


Linex1=rnd(800)
Liney1=rnd(600)

Linex2=rnd(800)
Liney2=rnd(600)

; 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()

Width=100
Height=200

if mousebutton()=1
Linex1=mousex()
Liney1=Mousey()
endif

if mousebutton()=2
Linex2=mousex()
Liney2=Mousey()
endif

; run Through and check if this point is over a sprite
For lp=1 To max

; get the sprite index
Spr2=Sprites(lp)
Turnsprite Spr2,(lp*0.05)

; Check if this point hits this sprites pixels
If LineHitSpritePixels(linex1,liney1,linex2,liney2,spr2,0.5)

pokeSpritefacergb Spr2,0,0,$ff0000
pokeSpritefacergb Spr2,0,1,$ff0000
pokeSpritefacergb Spr2,0,2,$ff0000
pokeSpritefacergb Spr2,0,3,$ff0000

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 mouse position
linec linex1,liney1,linex2,liney2,rgb(200,0,200)

s$=str$(fps())
boxc xpos,ypos,xpos+GetTExtWidth(s$),ypos+GetTExtHeight(s$),true,0
Text xpos,ypos,s$


; refresh the display
Sync

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

kevin


  PB170l  Tri/QuadHitSpritePixels

     This example is running the Tri And QuadHitSpritePixels function on a 1500 Rotating Scaling sprites. 




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

; 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



; 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()


; Define a Box for uor collision checks

; define the triangles vertex
tx1=mx
ty1=my
tx2=mx-50
ty2=my+100
tx3=mx-250
ty3=my+10

; define the Quad polygons vertex
qx1=mx
qy1=my
qx2=mx+200
qy2=my-50
qx3=mx+250
qy3=my+100
qx4=mx+30
qy4=my+50


; 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 this Triangle hits this sprites pixels
If TriangleHitSpritePixels(tx1,ty1,tx2,ty2,tx3,ty3,spr2,0.5)
AddColour(lp)=rgbalphaadd(AddColour(lp),$0000ff)
EndIf

; Check if this Triangle hits this sprites pixels
If QuadHitSpritePixels(qx1,qy1,qx2,qy2,qx3,qy3,qx4,qy4,spr2,0.5)
AddColour(lp)=rgbalphaadd(AddColour(lp),$ff0000)
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$


; refresh the display
Sync

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




kevin

 PB170l  ImageHitSpritePixels

     This example is running the ImageHitSpritePixels function on a 1500 Rotating Scaling sprites. 

kevin

#64
 PB1.70l  CompareSpritePixels (Pixel Perfect collision)

    oh dear,  it would seem i've gone and re-added Pixel Perfect collision support for entity sprites, how rude! :)     The pic bellow is showing the standard test where it's comparing a large rotated/scaled sprite to 1500 rotating scaling sprites.  The example is using the "CompareSpritePixels" function  to manually resolve the intersections, rather than through SpriteHit, which hasn't yet been fleshed out to support pixel perfect modes.  From memory, all that's remaining now is to implement ShapeHitSpritePixels method.  Once that's in place, the Direct 3D based sprite engine will be a functional replacement for the older one.




kevin

  PB1.70m  Closest Point To Sprite


    1.70m now supports finding the closest point to sprite entities.


kevin


  PB1.70 -  Z ordered Sprite with Video feedback
 

kevin


PB1.70m  Closest Point To Sprite #2

    While not a pretty screen,  the 1.70m version of the command now supports all methods axis,face and collision region.


kevin

#68
PB 1.71a - Alpha Channel Support for 3D surfaces

   This example is a quick rehash of older example that used the AFX image format to load images with Alpha channel.   In this version you can load the image directly to a 3D surface (ie. Hardware Accel) and render it.  While currently this is only hooked up through the DrawImage method (ie. DrawAlphaImage/DrawRotatedImage namely),  the main difference is that you can now tell the renderer what type of transparency to use. 

  The transparent flag contains packed 3 bit settings, which you can combine will tell it how to render the surface.   

  1 (bit 0) =  Use colour mask
  2 (Bit 1) =  use alpha channel
  4           = not in use.
  8 (bit 3) =  Apply filtering




openscreen 800,600,32,1

; Include the Free Image Slib
#include "FreeImage"

Screen=newimage(800,600)

; Use Free Image to load this image, so the Alpha channel is preserved.
Logo=FreeImage_LoadImage("PlayBasicSig.png",2)


; Clear Screen
rendertoimage screen
ct=rgb(100,200,50)
cb=rgb(200,200,250)
Shadebox 0,0,getscreenwidth(),GetSCreenHeight(),ct,ct,cb,cb

rendertoscreen

Do
setcursor 0,0
drawimage screen,0,0,0

mx=mousex()
my=mousey()

w=getimagewidth(logo)
h=getimageheight(logo)



DrawAlphaImage logo,mx,my ,1,1 ; Use Mask colour transparent
DrawAlphaImage logo,mx,my+h ,1,2 ; Use Alpha channel
DrawAlphaImage logo,mx,my+(h*2) ,1,2+8 ; Use Alpha channel + filtering

For lp=0 to 10
Scale#=1+(lp/100.0)
DrawRotatedImage  logo,400+(lp*1),400+lp,angle#+5,scale#,scale#,w/-2,h/-2,2
next
angle#=angle#+0.1

print fps()
Sync
loop





kevin

#69
PB 1.71a - Anti Aliased Shape Rendering (line mode)

   This demo draws a bunch of ring shaped shapes perspectively, a bit like the old dot tunnel effect (from back in the day).  The main difference is that PB1.71a has anti aliased line rendering support for batched tasks like drawing the shape edges. 


rings=500
RingSize#=600

FarDepth#=10000
NearDepth#=10

me=NewConvexShape(RingSize#,16)

Edges=GetShapeEdges(me,0)*rings


ClsColour=rgb(50,50,50)

Do
CLs ClsColour

ink $ffffff
mx=getscreenwidth()/2
my=getscreenheight()/2

thisrgb=rgb(50,20,210)
thisrgb= $ffffff

zstep#=(NearDepth#-FarDepth#)/Rings
near=0
far=fardepth#

projection#=400

For lp=0 to rings

x#=cos(angle#+lp*2)*455
y#=sin(angle#+lp)*255

z#=FarDepth#+(lp*zstep#)

ProjectedSize#=(RingSize#*projection#)/z#
Scale#=ProjectedSize#/RingSize#
rotateshape me,Angle#+(lp*10),Scale#

sx#=mx+((x#*projection#)/z#)
sy#=my+((y#*projection#)/z#)

ink RgbDepthCue(thisrgb,ClsColour,z#,near,far)

DrawShape me,sx#,sy#,1
next

ink rgb(255,255,255)
angle#=wrapangle(Angle#,1)

print fps()
print edges
Sync
loop



kevin

PB 1.71a - Shape Ball/Tunnel

   This is slight variation of the previous demo,  this it's rendering 100K anti aliased lines.   



screenvsync on

rings =50
RingSize# =450

FarDepth# =5000
NearDepth# =510

me=NewConvexShape(RingSize#,15)

For lp=1 to 50
shape=NewConvexShape(RingSize#+(100*lp),17+lp)
MergeShape Shape,ME
DeleteShape Shape
next

ClsColour=rgb(50,50,50)


Surf=New3Dimage(GetScreenWidth(),GetScreenHeight())


Edges=GetShapeEdges(me,0)*rings

Do

CLs ClsColour
DrawAlphaIMage Surf,0,0,0.25,false



ink $ffffff
mx=getscreenwidth()/2
my=getscreenheight()/2

thisrgb=rgb(50,20,210)
thisrgb= $ffffff

zstep#=(NearDepth#-FarDepth#)/Rings
near=0
far=fardepth#

projection#=500

For lp=0 to rings
x#=cos(angle2#+lp*1)*255
y#=sin(angle2#+lp)*555

z#=FarDepth#+(lp*zstep#)

ProjectedSize#=(RingSize#*projection#)/z#
Scale#=ProjectedSize#/RingSize#
rotateshape me,Angle#-(lp*10),Scale#

sx#=mx+((x#*projection#)/z#)
sy#=my+((y#*projection#)/z#)

ink RgbDepthCue(thisrgb,ClsColour,z#,near,far)
; capturedepth z#

DrawShape me,sx#,sy#,1
next



ink rgb(255,255,255)
angle#=wrapangle(Angle#,1)
angle2#=wrapangle(Angle2#,1.1)





currentfps=fps()


text 0,0,CurrentFps
text 0,20,rings
text 0,40, edges

CopyRect 0,0,0,GetScreenWidth(),GetSCreenHeight(),surf,0,0

Sync

loop






kevin


  PB1.71B Sprite Filtering 

    In this update users can now control if a sprite has filtering or not.  To do so use the SpriteFilter&GetSpriteFilter commands.




; Load the Ship Bitmap from GFX folder. Which is locate up 4 level from where
; this example it located.
Load3DImage "..\..\..\..\Gfx\Ship.bmp",1


NoFilter= NewSprite(200,200,1)
SpriteDrawmode NoFilter,2
CenterSpriteHandle NoFilter
ScaleSprite NoFilter,5
SpriteFilter NoFilter,Off


Filter= NewSprite(600,200,1)
SpriteDrawmode Filter,2
CenterSpriteHandle Filter
ScaleSprite Filter,5
SpriteFilter Filter,On




Setfps 30

Do
; Clear the Backgroud toa dark green colour
Cls Rgb(30,50,40)


CenterText GetSpriteX(filter),50,"Filtering "+State(Filter)
CenterText GetSpriteX(Nofilter),50,"Filtering "+State(NoFilter)

turnsprite Filter,1
turnsprite NoFilter,1

DrawAllSprites


Sync
loop


Function State(Spr)
Select getspritefilter(Spr)
case 1
result$="Bilinear Filter"
default
result$="No Filter"
endselect
result$="["+Result$+"]"
EndFunction Result$






kevin

#72
PlatFormer Demo Using Perspective Sprites

     This is the standard platform demo from way back converted to use PB1.71c's perspective sprite rendering.    Which is a feature of PB1.7x editions of PlayBasic.  Perspective rendering has various rotation modes.   In this one (perspective 2D), it will renders the sprite scene down the z axis.  So the camera can zoom in/out and spin on the Z axis but not on the X/Y axis.  There's other rotation modes (ie full 3D) but this one is a lot simpler for 2D game scenes (no axis flipping).  and therefore a lot more plug and play friendly!






kevin

#73
 Perspective 2D platformer With Particles Patched In

    This pic is the previous demo with the 2D particles example cut together into it.  Rough as guts, but shows the potential !



kevin

#74
 Perspective 2D Platformer Video

    This is a little 30second video capture (3.4 meg - DivX5.1) of the perspective platformer demo running in PB1.71.   The demo includes 7 backdrop layers,  particles, pixel perfect collision, alpha overlays etc   All drawn from a top down perspective.



download


Download Platformer Video