Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QBJS Particle Fountain
#1
I am tweaking dbox pset version with less bubble release each frame for consistent fountain pattern (same tweak as in Proggies) PLUS a wider viewing frame that spreads Bell Curve a little better:

https://qbjs.org/index.html?code=J09wdGl...A1FTdWIKCg==


   
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#2
Looks great!
Reply
#3
Code: (Select All)
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// Unseen GDK_GL - Single Particle Jet \\
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////

REM $INCLUDE:'UnseenGDK_DEV\GDK2_GL.bi'

Debug%% = GDK_TRUE

CONST nP = 50000

'//////////////////////// UDTs ///////////////////////////////////////

TYPE FTN_Particle
  Position AS GDK2_Vertex_F
  Velocity AS GDK2_Vertex_F
  Color AS _UNSIGNED LONG
  Alpha AS _BYTE
  BounceCount AS INTEGER
  Lifetime AS SINGLE
END TYPE

TYPE FTN_Fountain
  Origin AS GDK2_Vertex_F
  NumParticles AS LONG
END TYPE


'//////////////////////// Global Variables /////////////////////////////
DIM SHARED Fountain AS FTN_Fountain
DIM SHARED Particles(1 TO nP) AS FTN_Particle ' The shared particle array
DIM SHARED MaxBounce AS INTEGER: MaxBounce = 3
DIM SHARED ParticleMaxLifetime AS SINGLE: ParticleMaxLifetime = 350

'///////////////////////////////////// System Initialisation ////////////////////////////////////////////////
GDK2_System_New "UnseenGDK_Dev\", 800, 600, GDK_FALSE, ""
_DISPLAYORDER _GLRENDER , _SOFTWARE
_MOUSEHIDE
GDK_Init_GL = GDK_TRUE
GDK_Allow_GL = GDK_TRUE

Initialize_Fountain Fountain, Particles(), nP

'//////////////////////////////////////// Main Loop ////////////////////////////////////////////////////////////
DO
  GDK2_System_Update
  Update_Fountain_Physics Fountain, Particles()
LOOP UNTIL GDK_KB(0).ESC
SYSTEM

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////
REM $INCLUDE:'UnseenGDK_DEV\GDK2_GL.bm'
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB _GL
  IF GDK_Allow_GL = GDK_TRUE THEN
    _GLCLEARDEPTH 1
    _GLCLEARCOLOR 0, 0, 0, 1
    _GLENABLE _GL_DEPTH_TEST
    _GLENABLE _GL_BLEND
    _GLBLENDFUNC _GL_SRC_ALPHA, _GL_ONE_MINUS_SRC_ALPHA
    _GLENABLE _GL_TEXTURE_2D
    _GLMATRIXMODE _GL_PROJECTION
    _GLLOADIDENTITY
    _GLUPERSPECTIVE 65, GDK_System.WH.X / GDK_System.WH.Y, 1, 1000
    _GLMATRIXMODE _GL_MODELVIEW
    _GLLOADIDENTITY
    _GLVIEWPORT 0, 0, GDK_System.WH.X, GDK_System.WH.Y

    IF GDK_Init_GL = GDK_TRUE THEN
      GDK_Init_GL = GDK_FALSE
    ELSE
      GDK_GL_CLS
      _GLTRANSLATEF 0, 0, -500
      Draw_Particles Fountain, Particles()
      _DISPLAY
    END IF
  END IF
END SUB

SUB Initialize_Fountain (fountain AS FTN_Fountain, particles() AS FTN_Particle, maxParticles AS LONG)
  DIM i AS LONG
  fountain.NumParticles = 0
  fountain.Origin.X = GDK_System.WH.X / 2
  fountain.Origin.Y = GDK_System.WH.Y
  fountain.Origin.Z = 0
  FOR i = 1 TO maxParticles
    Reset_Particle particles(i), fountain
  NEXT i
END SUB

SUB Reset_Particle (particle AS FTN_Particle, fountain AS FTN_Fountain)
  DIM dynamicHeight AS SINGLE
  DIM minHeight AS SINGLE, maxHeight AS SINGLE
  DIM freq AS SINGLE

  minHeight = 15
  maxHeight = 40
  freq = 0.5 ' Frequency of the height change

  ' Calculate the current dynamic height using a sine wave and GDK_System.GT
  dynamicHeight = (SIN(GDK_System.GT * freq) * ((maxHeight - minHeight) / 2)) + (minHeight + (maxHeight - minHeight) / 2)

  particle.BounceCount = 0
  particle.Position.X = fountain.Origin.X + RND * 20 - 10
  particle.Position.Y = fountain.Origin.Y
  particle.Position.Z = fountain.Origin.Z + RND * 10 - 5
  particle.Lifetime = ParticleMaxLifetime * (RND * .5 + .75)

  ' Apply the dynamically changing velocity
  particle.Velocity.X = RND * 1 - .5
  particle.Velocity.Y = dynamicHeight + (RND * 2) - 2.5
  particle.Velocity.Z = RND * 1 - .5

  particle.Color = _RGBA32(5 * RND + 15, 50 * RND + 16, 255, 64)
  particle.Alpha = _ALPHA32(particle.Color)
END SUB

SUB Update_Fountain_Physics (fountain AS FTN_Fountain, particles() AS FTN_Particle)
  DIM i AS LONG

  IF fountain.NumParticles < nP THEN fountain.NumParticles = fountain.NumParticles + 100

  FOR i = 1 TO fountain.NumParticles
    DIM particle AS FTN_Particle: particle = particles(i)

    ' Gravity
    particle.Velocity.Y = particle.Velocity.Y + .1

    ' Update position
    particle.Position.X = particle.Position.X + particle.Velocity.X
    particle.Position.Y = particle.Position.Y + particle.Velocity.Y
    particle.Position.Z = particle.Position.Z + particle.Velocity.Z

    ' Update particle lifetime and alpha
    particle.Lifetime = particle.Lifetime - 1
    IF particle.Lifetime < 0 THEN particle.Lifetime = 0
    particle.Alpha = 64 * (particle.Lifetime / (ParticleMaxLifetime * 1.25))

    ' Check for reset conditions
    IF (particle.Position.Y > GDK_System.WH.Y + 20 AND particle.Velocity.Y > 0 AND particle.BounceCount >= MaxBounce) OR particle.Lifetime <= 0 THEN
      Reset_Particle particle, fountain
    END IF

    ' Boundary check for bouncing
    IF particle.Position.Y > GDK_System.WH.Y + 20 AND particle.Velocity.Y > 0 AND particle.BounceCount < MaxBounce THEN
      particle.Velocity.Y = -particle.Velocity.Y * (RND * .2 + .5)
      particle.Position.Y = GDK_System.WH.Y + 19
      particle.Velocity.X = (RND - .5) * 2
      particle.Velocity.Z = (RND - .5) * 2
      particle.BounceCount = particle.BounceCount + 1
    END IF

    particles(i) = particle
  NEXT i
END SUB

SUB Draw_Particles (fountain AS FTN_Fountain, particles() AS FTN_Particle)
  DIM i AS LONG
  _GLPOINTSIZE 2.0
  _GLBEGIN _GL_POINTS
  FOR i = 1 TO fountain.NumParticles
    _GLCOLOR4UB _RED32(particles(i).Color), _GREEN32(particles(i).Color), _BLUE32(particles(i).Color), particles(i).Alpha
    _GLVERTEX3F particles(i).Position.X - (GDK_System.WH.X / 2), GDK_System.WH.Y - particles(i).Position.Y - (GDK_System.WH.Y / 2), particles(i).Position.Z
  NEXT i
  _GLEND
END SUB
Its a work in progress, ai assisted and it fun! My adaptation give varying pressure to the fountain so the jet changes height and the associated droplets then fall sooner, etc...

Unseen
Reply
#4
Heres where im at now, its so much fun! gonna apply textures net and then do fire, smoke and sparks! I love particles!
[Image: fountain-3.png]
Unseen
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)