Examples using the particle functions I made ( http://blitzbasic.com/codearcs/codearcs.php?code=2388 ). Uses primarily Blitz commands for basic particle and emitter manipulation.
Basic demo of most of the functions:
And simple snow demo:
Anyway, I hope someone can learn some thing from it.
Basic demo of most of the functions:
Include "particlefuncs.bb";The particle functions AppTitle "Basic particle demo" Graphics3D 640,480 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,0,-10 light=CreateLight() cylinder=CreateCylinder() emitter=createemitter(0,.05,0,0,0,0,.01,5,True);Create the particle emitter effect=1;Smoke effect While Not KeyDown(1) If del<>True;If the emitter hasn't been deleted If KeyDown(57) For a=1 To 5;Change according to your computer's speed part=createparticle(emitter,2000);Create a particle with a life of 2 seconds If part<>getparticle(1);If it's not the first particle made If effect=1;Smoke effect EntityColor part,120,120,120 ElseIf effect=2;Flat Spray effect EntityColor part,100,100,255 EndIf particlealpha(part,.2);Needed for proper fading ScaleSprite part,.2,.2 Else;If it is modifyparticle(part,0,-.5,0);Shoot the default particle downward EndIf SpriteViewMode part,2;Looks more real(and shows each particle's rotation) Next EndIf If KeyDown(28) ;Flat Spray effect modifyemitter(emitter,0,-.2,0,0,0,0,.05,2,True) modifyemitterrnd(emitter,.1,0,0,2,2,2) effect=2 Else ;Smoke effect modifyemitter(emitter,0,.05,0,0,0,0,.01,5,True) modifyemitterrnd(emitter,.01,.01,.01,5,5,5) effect=1 EndIf If KeyDown(203) TurnEntity emitter,0,0,10 If KeyDown(205) TurnEntity emitter,0,0,-10 If KeyDown(200) TurnEntity emitter,10,0,0 If KeyDown(208) TurnEntity emitter,-10,0,0 RotateEntity cylinder,EntityPitch(emitter),EntityYaw(emitter),EntityRoll(emitter) EndIf If KeyHit(211) freeemitter(emitter);Destroys the emitter and remembers that it no longer exists (it took me forever to find this bug!) del=True EndIf updateparticles;Does what it says RenderWorld fps=1000/(MilliSecs()-pframetime);Frames Per Second pframetime=MilliSecs() Text 0,0,"Particles:" + countparticles(emitter),False,False;Displays number of particles made by emitter currently in existence Text 0,12,"Total Particles: " + totalparticles,False,False;Displayes number of all particles made Text 0,24,fps,False,False Text 0,36,partmovex(part),False,False;Not useful here, just demonstrates the function Text 0,48,TrisRendered(),False,False Flip Wend ClearWorld clearparticlesystem;Does what it says End
And simple snow demo:
Include "particlefuncs.bb" AppTitle "Merry Christmas!" Graphics3D 640,480 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,0,-10 light=CreateLight() Dim tre (15) For x=0 To 5 For z=0 To 3 tre(x*z)=maketree() PositionEntity tre(x*z),6*x-15+2*Rnd(-1,1),0,4*z Next Next ground=CreatePlane() EntityColor ground,350,350,350 PositionEntity ground,0,-3,0 EntityType ground,2 Global emitter=createemitter(0,-.1,0,0,0,0,.01,0,True) Collisions 1,2,2,1 While Not KeyDown(1) main RenderWorld Flip Wend ClearWorld clearparticlesystem End Function maketree() tree=CreateCone() green_br=CreateBrush(0,150,0) PaintMesh tree,green_br ScaleMesh tree,2,2,2 PositionMesh tree,0,1,0 trunk=CreateCylinder() brown_br=CreateBrush(100,40,0) PaintMesh trunk,brown_br PositionMesh trunk,0,-2,0 AddMesh trunk,tree FreeEntity trunk EntityType tree,2 Return tree End Function Function main() For a=1 To 2;Change according to your computer's speed p=createparticle(emitter,10000) ScaleSprite p,.02,.02 PositionEntity p,Rand(-10,10),5,Rand(-10,10) EntityRadius p,.1 EntityType p,1 Next updateparticles UpdateWorld End Function
Anyway, I hope someone can learn some thing from it.