need help with particles.
Blitz3D Forums/Blitz3D Beginners Area/need help with particles.
| ||
Hi, I am very new to blitz3d (about a week now). I am looking to experiment with particles and particle effects. Does anyone know where to find tutorials on creating your own? Or can someone show me some sample code to make a simple particle effect so I may learn from there? I do not want to buy any 3rd party software, so please help with this is you can! |
| ||
hey, just knocked this together very quickly. This is a VERY basic example of a particle engine. the way i see it is, it works by creating a type, with say 50 objects. each object has the point it starts at, a speed at which it travels at, a set distance or time it travels for that speed at and each also has a fade, to make it look better this applies only to my system below, as i say, there is much better particle engines out there. i used low poly spheres so i could post the code and it could run on anyone computer with blitz. Most people use sprites with say a firey looking texture if they were doing a particle engine for fire. Graphics3D 800,600; set graphics mode SetBuffer BackBuffer(); set to double buffering light=CreateLight(); create a light camera=CreateCamera(); create a camera PositionEntity camera,0,5,-13; and position it back from the particles cube=CreateSphere(2); create the low poly sphere for the particles to copy PositionEntity cube,-50,0,0; position it out of view EntityColor cube,255,20,20; change the color to red Gosub setup; goto the type setup subroutine (not really needed) timer=30; the time in milliseconds in which the next particle will be generated, the lower the number the more that will be generated timer1=MilliSecs() While Not KeyHit(1) If MilliSecs()>timer1+timer Then Gosub createparticle; if the timer reaches 100 milliseconds then goto the createnewparticle sub-routine. then reset the timer timer1=millisecs() end if Gosub updateparticles; update the particles ie, move them UpdateWorld() RenderWorld() Flip Wend End .updateparticles For p.particle=Each particle; cycle thru all the available type objects p\y=p\y+p\speed; move the particle upwards according to it's speed EntityAlpha p\entity,(p\distance-p\y)/p\distance; fade the entity as it comes to the end of it's distance PositionEntity p\entity,p\x,p\y,0; position the entity on screen in it's updated place If p\y>p\distance Then FreeEntity p\entity:Delete p.particle; if the entity reaches its max distance then free the entity and delete the type object ;(ALWAYS FREE THE ENTITY FIRST) Next Return .createparticle p.particle=New particle; create a new type object p\entity=CopyEntity(cube); copy the cube entity into the type object p\y=0 p\x=Rnd(-3,3); set a random x position p\speed=Rnd(0.01,0.9); set the speed the particle will travel at p\distance=Rnd(2,15); set the max distance the particel can travel Return .setup Type particle; set up the type fields Field entity Field x#,y# Field speed# Field distance# End Type Return other links you should check out norcs particle engine http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=norc02062003164813&comments=no hope some of this helps :D |
| ||
thanks, Im going to try that out right now. If your using sprites, does the camera automatically face them? And is it the same technique more or less? I havent touched your code yet, so if this question is obviously answered, ignore it please. |
| ||
By default, sprites always face the camera. However look at SpriteViewMode in the 3D command Reference docs for more info. Generally the code will be the same as sprites act as entities similar to the cubes -oops spheres, not sure why they're called 'cube'... in the above code. It should be as simple as replacing cube=CreateSphere(2); with cube=CreateSprite() |
| ||
thanks! I have some things to play around with for a few days! :) |