Hey ppl! I've just finished this single surface stuff (still needs some stuff done to it tho). I know this is posted in the advanced 3d forum (prob the wrong place to post it). Well here's the code. No image files needed.
Please try this and give me your opinions/suggestions for making it faster if possible :) And could you also tell me what fps you get on the default seetings. Press the one key to generate lots more particles.
Thank you if you respond! This code *should* run at least 5 or 6 times quicker than a sprite based particle system
[EDIT, PARTICLES ONLY UPDATE ONCE EVERY FIVE FRAMES, SHOULD PROVIDE A BIG SPEED UP]
And use this for anything you want to.
:D
Please try this and give me your opinions/suggestions for making it faster if possible :) And could you also tell me what fps you get on the default seetings. Press the one key to generate lots more particles.
Thank you if you respond! This code *should* run at least 5 or 6 times quicker than a sprite based particle system
[EDIT, PARTICLES ONLY UPDATE ONCE EVERY FIVE FRAMES, SHOULD PROVIDE A BIG SPEED UP]
Graphics3D 800,600 SetBuffer BackBuffer() cam=CreatePivot() camera=CreateCamera(cam) PositionEntity camera,0,0,-30 mesh=CreateMesh() surface=CreateSurface(mesh) NUM_PARTICLES=60 switch=0 Type s_part Field x#,y#,z#; central position for the quad Field index; index for the first vertex Field ang#; ang value. -45 for normal Field alpha# Field speed# Field time Field timer Field ang_speed# Field active Field pindex End Type g_time=1 g_timer=MilliSecs() cpx#=0 cpy#=0 cyz#=0 ang=-45 index=0 v0=AddVertex(surface,cpx+Sin(ang),cpy+Cos(ang),cpz,0,1) v1=AddVertex(surface,cpx+Sin(ang+90),cpy+Cos(ang+90),cpz,1,1) v2=AddVertex(surface,cpx+Sin(ang-90),cpy+Cos(ang-90),cpz,0,0) v3=AddVertex(surface,cpx+Sin(ang+180),cpy+Cos(ang+180),cpz,1,0) tri=AddTriangle(surface,v0,v1,v2) tri1=AddTriangle(surface,v1,v3,v2) tex=CreateTexture(128,128,2) SetBuffer TextureBuffer(tex) Color 200,100,50 Oval 20,20,87,87 SetBuffer BackBuffer() EntityTexture mesh,tex EntityFX mesh,32+2 EntityBlend mesh,3 VertexColor surface,0,200,200,200;,0.8 VertexColor surface,1,200,200,200;,0 VertexColor surface,2,200,200,200;,0 VertexColor surface,3,200,200,200;,0 For loop=0 To NUM_PARTICLES Gosub create_spart Next While Not KeyHit(1) ;TranslateEntity mesh,0,0.01,0,True TurnEntity mesh,0,0,1 cx=EntityPitch(camera,True) cy=EntityYaw(camera,True) cz=0 If MouseDown(1) Then ang=ang+1:Gosub rotatequad If MouseDown(2) Then ang=ang-1:Gosub rotatequad If KeyDown(203) Then cpx=cpx-0.1:Gosub rotatequad If KeyDown(205) Then cpx=cpx+0.1:Gosub rotatequad If KeyDown(200) Then cpy=cpy+0.1:Gosub rotatequad If KeyDown(208) Then cpy=cpy-0.1:Gosub rotatequad If KeyDown(2) Then Gosub create_spart If MilliSecs()>g_time+g_timer Then g_timer=MilliSecs() Gosub new_spart End If RotateEntity mesh,cx,cy,cz If MilliSecs()<timer+1000 Then frame=frame+1 Else fps=frame frame=0 timer=MilliSecs() End If Gosub update_spart UpdateWorld RenderWorld Text 0,0," Number of quads="+(index/4)+" fps="+fps+" trirednered="+TrisRendered() Flip 0 Wend End .rotatequad VertexCoords(surface,0,cpx+Sin(ang),cpy+Cos(ang),cpz) VertexCoords(surface,1,cpx+Sin(ang+90),cpy+Cos(ang+90),cpz) VertexCoords(surface,2,cpx+Sin(ang-90),cpy+Cos(ang-90),cpz) VertexCoords(surface,3,cpx+Sin(ang+180),cpy+Cos(ang+180),cpz) Return .create_spart p.s_part=New s_part p\pindex=index index=index+4 p\x=Rnd(-2,2) p\y=0;Rnd(-4,4) p\z=Rnd(-2,2) p\speed=Rnd(0.01,0.1) p\time=Int(Rnd(500,2000)) p\ang_speed=Rnd(0.1,2) p\ang=Rnd(-45,135) v0=AddVertex(surface,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z,0,1) v1=AddVertex(surface,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z,1,1) v2=AddVertex(surface,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z,0,0) v3=AddVertex(surface,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z,1,0) tri=AddTriangle(surface,v0,v1,v2) tri1=AddTriangle(surface,v1,v3,v2) Return .update_spart switch=switch+1 If switch>5 Then switch=0 If switch=0 Then For p.s_part=Each s_part If p\active=1 Then p\y=p\y+p\speed p\ang=p\ang+p\ang_speed VertexCoords(surface,p\pindex+0,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z) VertexCoords(surface,p\pindex+1,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z) VertexCoords(surface,p\pindex+2,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z) VertexCoords(surface,p\pindex+3,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z) If MilliSecs()>p\time+p\timer Then p\active=0 VertexColor surface,p\pindex+0,200,200,200,0 VertexColor surface,p\pindex+1,200,200,200,0 VertexColor surface,p\pindex+2,200,200,200,0 VertexColor surface,p\pindex+3,200,200,200,0 End If End If Next End If Return .new_spart loop_exit=0 For p.s_part=Each s_part If p\active=0 Then VertexColor surface,p\pindex+0,200,200,200,1 VertexColor surface,p\pindex+1,200,200,200,1 VertexColor surface,p\pindex+2,200,200,200,1 VertexColor surface,p\pindex+3,200,200,200,1 p\active=1 p\y=0 p\speed=Rnd(0.01,0.1) p\timer=MilliSecs() p\time=Int(Rnd(500,2000)) p\ang_speed=Rnd(0.01,0.3) p\ang=Rnd(-45,135) p\x=Rnd(-2,2) p\z=Rnd(-2,2) loop_exit=1 VertexCoords(surface,p\pindex+0,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z) VertexCoords(surface,p\pindex+1,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z) VertexCoords(surface,p\pindex+2,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z) VertexCoords(surface,p\pindex+3,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z) End If If loop_exit=1 Then Exit Next Return
And use this for anything you want to.
:D