RottParticles

Blitz3D Forums/Blitz3D Beginners Area/RottParticles

I'm tring to use this particle system, but if anyone could posts an example (like a fire) it would be great!

i found this code by Rottbott from here. it's a ship with a flame trail. you need to load a mesh and some textures.

http://www.blitzbasic.com/Community/posts.php?topic=25500

Graphics3D 800, 600, 16, 2

; Types
Type Player
  Field EN
  Field Accelerate, Turn
  Field ZV#
End Type

Type Fire
  Field EN, X#, Z#, Age
End Type

; Globals
Global Cam

; Camera and lighting
Cam = CreateCamera() : CameraRange Cam, 10.0, 2500.0 : CameraZoom Cam, 1.5
PositionEntity Cam, 0, 900, 0 : RotateEntity Cam, 90, 0, 0
L = CreateLight(2) : EntityParent L, Cam : PositionEntity L, 0, 0, 0
LightRange L, 10000.0

; Backgrounds
B1 = CreatePlane() : PositionEntity B1, 0, -50, 0 : EntityFX B1, 9
B2 = CreatePlane() : PositionEntity B2, 0, -40, 0 : EntityFX B2, 9 : EntityBlend B2, 2
BT1 = LoadTexture("Data\VLines.bmp") : ScaleTexture BT1, 512, 512 : EntityTexture B1, BT1
BT2 = LoadTexture("Data\Stars.bmp") : ScaleTexture BT2, 1200, 1200 : EntityTexture B2, BT2

; Fire particle template
FireEN = CreateQuad() : ScaleMesh FireEN, 20.0, 20.0, 1 : EntityFX FireEN, 1 : EntityBlend FireEN, 3
FireTex = LoadTexture("Data\Fire.bmp") : EntityTexture FireEN, FireTex
HideEntity FireEN

; Player ship
Me.Player = New Player
Me\EN = LoadMesh("Data\Ship.b3d")

; Main loop
While Not KeyHit(1)

  ; Ship controls
  Me\Turn = KeyDown(205) - KeyDown(203)
  Me\Accelerate = KeyDown(200) - KeyDown(208)
  ; Turning
  If Me\Turn <> 0
    Roll# = CurveValue#(EntityRoll#(Me\EN), -40.0 * Me\Turn, 5.0)
    RotateEntity Me\EN, EntityPitch#(Me\EN), EntityYaw#(Me\EN), Roll#
    TurnEntity Me\EN, 0, -4 * Me\Turn, 0, True
  EndIf
  Roll# = CurveValue#(EntityRoll#(Me\EN), 00.0, 20.0)
  RotateEntity Me\EN, EntityPitch#(Me\EN), EntityYaw#(Me\EN), Roll#
  ; Moving
  Me\ZV# = Me\ZV# + 0.5 * Me\Accelerate
  If Me\ZV# > 18.0 Then Me\ZV# = 18.0 ElseIf Me\ZV# < 0.0 Then Me\ZV# = 0.0
  MoveEntity Me\EN, 0, 0, Me\ZV#
  ; Fire trail
  For i = 1 To Int(Ceil#(Me\ZV# / 2.0))
    F.Fire = New Fire : F\EN = CopyEntity(FireEN)
    PositionEntity F\EN, EntityX#(Me\EN), Rnd#(-10.0, 10.0), EntityZ#(Me\EN)
    RotateEntity F\EN, 0.0, EntityYaw#(Me\EN), 0.0 : MoveEntity F\EN, 0.0, 0.0, -30.0
    F\X# = Rnd#(-2.0, 2.0)
    F\Z# = Rnd#(-2.0, 2.0)
  Next

  ; Make stars twinkle
  BT1V# = BT1V# + 0.002
  PositionTexture BT1, 0.0, BT1V#

  UpdateFire
  UpdateWorld : RenderWorld : Flip
Wend
End

; Functions ------------------------------------------------------------------------------------------

; Updates all fire particles
Function UpdateFire()
  For F.Fire = Each Fire
    TranslateEntity F\EN, F\X#, 0.0, F\Z#
    PointEntity F\EN, Cam
    F\Age = F\Age + 1
    If F\Age > 15 Then FreeEntity F\EN : Delete F
  Next
End Function

; Creates a quad mesh
Function CreateQuad(P = 0)
  If P Then EN = CreateMesh(P) Else EN = CreateMesh()
  s = CreateSurface(EN)
  v1 = AddVertex(s, -1.0, -1.0, 0.0, 0, 1)
  v2 = AddVertex(s, 1.0, -1.0, 0.0, 1, 1)
  v3 = AddVertex(s, 1.0, 1.0, 0.0, 1, 0)
  v4 = AddVertex(s, -1.0, 1.0, 0.0, 0, 0)
  AddTriangle s, v1, v2, v3
  AddTriangle s, v1, v3, v4
  Return EN
End Function

Function CurveValue#(Current#, Destination#, Curve#)
  Return Current# + ((Destination# - Current#) / Curve#)
End Function