' test example how to convert old particle example into entity modus
' febr/march 2012 by lionheart
Uses "TBGL"
' -- Scene-Entity constants
BEGIN CONST
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eParticles
%eEffects
END CONST
' -- Display list constants
BEGIN CONST
%lTriangle = 1
%lParticles
%lParticles_test 'only for test
%lEffects
END CONST
Dim i As Long
Dim SpeedFactor As Single = 64
Dim FrameRate As Single
Dim EmitterX,EmitterY,EmitterZ,EmitterPulse As Single
%EFFECT_QUALITY = 24
%PARTICLE = 1
%EFFECT = 3
%MAXPARTICLES = 12'32
Dim ParticleX(%MAXPARTICLES) As Single
Dim ParticleY(%MAXPARTICLES) As Single
Dim ParticleZ(%MAXPARTICLES) As Single
Dim ParticleSize(%MAXPARTICLES) As Single
Dim ParticleSpeed(%MAXPARTICLES) As Single
Dim ParticleFade(%MAXPARTICLES) As Single
Dim ParticleR(%MAXPARTICLES) As Single
Dim ParticleG(%MAXPARTICLES) As Single
Dim ParticleB(%MAXPARTICLES) As Single
'---------------------------------------------- // main
Function TBMain() As Long
LOCAL hWnd As DWORD
LOCAL FrameRate AS DOUBLE
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL Entity Particles test", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 5)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
'---------------------------------------------------------// 1
'New Entity DLSlot ?'
EmitterX = 0.25 '0.5'sin(GetTickCount/2000)/2
EmitterZ = 0 'cos(GetTickCount/5000)/2
EmitterY = 0 'cos(GetTickCount/6000)/2
EmitterPulse = 0.75 '+cos(GetTickCount/500)
TBGL_UseBlend %TRUE
'New Entity DLSlot ?'
TBGL_NewList %EFFECT
RenderParticles
TBGL_EndList
For i = 1 To %EFFECT_QUALITY
TBGL_CallList %EFFECT
Next
TBGL_UseBlend %FALSE
TBGL_DeleteList %EFFECT
TBGL_DrawFrame
'---------------------------------------------- // 2
' ---- only for display test
TBGL_NewList %lParticles_test
TBGL_BeginPoly %GL_POINTS
TBGL_Color 255, 0, 0
TBGL_Vertex -1, -1, 0
TBGL_Color 0, 255, 0
TBGL_Vertex 1, -1, 0
TBGL_Color 0, 0, 255
TBGL_Vertex 0, 1, 0
TBGL_EndPoly
TBGL_EndList
'---------------------------------------------- // 3
TBGL_NewList %lParticles
myParticleCode()
TBGL_EndList
'---------------------------------------------- // 4
TBGL_EntityCreateDLSlot(%sScene, %eParticles, 0, %lParticles)
TBGL_EntitySetPos(%sScene, %eParticles, 0, 0, 0)
TBGL_EntityCreateDLSlot(%sScene, %eEffects, 0, %lEffects) '?
TBGL_EntitySetPos(%sScene, %eEffects, 0, 0, 0) '?
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
'---------------------------------------------- // 5
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
'---------------------------------------------- // 6
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
' -- Entity turn has parameters for rotation in x, y and z axis
If TBGL_GetWindowKeyState(hWnd, %VK_UP) Then TBGL_EntityTurn(%sScene, %eParticles, -1, 0, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then TBGL_EntityTurn(%sScene, %eParticles, 1, 0, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then TBGL_EntityTurn(%sScene, %eParticles, 0, 1, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then TBGL_EntityTurn(%sScene, %eParticles, 0,-1, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_PGDN) Then TBGL_EntityTurn(%sScene, %eParticles, 0, 0, 1)
If TBGL_GetWindowKeyState(hWnd, %VK_PGUP) Then TBGL_EntityTurn(%sScene, %eParticles, 0, 0,-1)
Wend
TBGL_DestroyWindow
END FUNCTION
'---------------------------------------------- 7 //
Function myParticleCode() As Long
TBGL_LoadTexture APP_SourcePath+"Textures\Cloud.bmp",1,%TBGL_TEX_MIPMAP
TBGL_UseTexturing %TRUE
TBGL_BindTexture 1
TBGL_BlendFunc %GL_SRC_ALPHA , %GL_ONE
TBGL_UseDepth %FALSE
TBGL_UseDepthMask %FALSE
InitParticles
TBGL_BeginPoly %GL_QUADS
TBGL_TexCoord2D 0,1
TBGL_Vertex -1,1,0
TBGL_TexCoord2D 1,1
TBGL_Vertex 1,1,0
TBGL_TexCoord2D 1,0
TBGL_Vertex 1,-1,0
TBGL_TexCoord2D 0,0
TBGL_Vertex -1,-1,0
TBGL_EndPoly
EmitterX = 0.25 '0.5'sin(GetTickCount/2000)/2
EmitterZ = 0 'cos(GetTickCount/5000)/2
EmitterY = 0 'cos(GetTickCount/6000)/2
EmitterPulse = 0.75 '+cos(GetTickCount/500)
End Function
'---------------------------------------------- // 8
Function InitParticles( ) As Long
For i = 1 To %MAXPARTICLES
BornParticle(i)
Next
End Function
'------------------------------------------------- 9 //
' This will prepare one particle
Function BornParticle( index As Long ) As Long
ParticleSize(index) = 0.00125 '+ Rnd * 0.06 '0.0125 '+ rnd * 0.06
ParticleX(index) = EmitterX/4'+Rndf(0,1) 'EmitterX/2'+rndf(0,1)
'ParticleY(index) = EmitterY/3'+rndf(0,1)
'ParticleZ(index) = EmitterZ/4'+rndf(0,1)
ParticleR(index) = EmitterX*255
ParticleG(index) = EmitterY*255
ParticleB(index) = EmitterZ*255
ParticleSpeed(index)= 0.01 + Rnd *0.01'0.01 + Rnd *0.01
End Function
'-------------------------------------- 10 //
Function RenderParticles () As Long
FrameRate = TBGL_GetFrameRate
For i = 1 To %MAXPARTICLES
ParticleSize(i) += SpeedFactor/600/FrameRate
ParticleX(i) += (ParticleSpeed(i) * SpeedFactor)/FrameRate
'ParticleY(i) += ParticleY(i)/100
If ParticleX(i) > 4 Then BornParticle(i)
DrawParticle(i)
Next
End Function
'---------------------------------------------- 11 //
Function DrawParticle ( index As Long) As Long
TBGL_PushMatrix
'(!)'
TBGL_Translate -2.0+ParticleX(index), ParticleY(index), ParticleZ(index)
'TBGL_Rotate ParticleSpeed(index) * GetTickCount,0,0,1 ' Slow rotation of the "smokie" looks good
TBGL_Scale ParticleSize(index),ParticleSize(index),1
TBGL_ColorAlpha ParticleR(index),ParticleG(index),ParticleB(index),255-(ParticleY(index)/2)*255' The particle will fade out
TBGL_CallList %PARTICLE
TBGL_PopMatrix
End Function
any help like script example or link would be great. thanks, nice day, frank
Bookmarks