PDA

View Full Version : laser (tbgl) collision example



Lionheart008
21-03-2012, 11:30
a) I am looking for an old example how to catch with a laser an object (or not) / cube or a primitive. I cannot find this example on my hd or here at board. perhaps anybody has a link? the work was done by petr so far as I can remember.

b) it's possible to make a simple particle line running from left to right side (linear) ?

best regards, frank

zak
21-03-2012, 13:10
Hi Frank
i am the librarian, for the first question may be this what you want "laser chamber" attached below and it is found here___ (http://www.thinbasic.com/community/showthread.php?7690-Playing-with-lines-based-on-tutorial-code) by Petr (unformatted when the forum moved from the old one)

ErosOlmi
21-03-2012, 17:27
(unformatted when the forum moved from the old one)
Code formatting fixed in the referred post.

Lionheart008
22-03-2012, 23:45
thanks zak, but I was looking for another example, doesn't matter :) I know the laser example of kent ;) sometimes it's hard do get the right example here by searching the forum. I will have a closer look at my notebook hd, thanks. nice week-end and sunny days, frank

Lionheart008
23-03-2012, 14:20
b) it's possible to make a simple particle line running from left to right side (linear) ?

my first approach for a particle cloud starting from left to right site. my ideas was a) to change camera position and b) particle born position. it's an old radial particle example from petr I have token.



' test for particle movement from left to right site, simple ' #MINVERSION 1.6.0.10 Uses "TBGL" 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 dim desktopX, desktopY, desktopDepth as long tbgl_GetDesktopInfo desktopX, desktopY, desktopDepth Dim hWnd As Dword If MsgBox( 0, "Your current desktop settings are:"+Format$(desktopX)+"x"+Format$(desktopY)+" with"+Str$(desktopDepth)+" bits of color information"+ _ $CRLF+"Do you want to go fullscreen with this settings?", %MB_YESNO Or %MB_ICONQUESTION, "Question") = %IDYES Then '---------------------------------------------- 1 // hWnd = TBGL_CreateWindowEx(" Radial particles test for particle movements", desktopX, desktopY, desktopDepth, %TBGL_WS_FULLSCREEN) TBGL_ShowCursor 1 else hWnd = TBGL_CreateWindowEx(" Radial particles test for particle movements", 640, 480, desktopDepth, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) end if 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_NewList %PARTICLE ParticleCode TBGL_EndList TBGL_ResetKeyState WHILE TBGL_IsWindow(hWnd) FrameRate = TBGL_GETFRAMERATE TBGL_ClearFrame '---------------------------------------------------- // 'here's the solution I am thinking :) TBGL_Camera -1,0,2,0,0,-1 ' only for a test, I am not sure if that's right! 'original: 3,3,3,0,0,0 'here's the solution I am thinking :) '---------------------------------------------------- // 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 TBGL_NewList %EFFECT RenderParticles TBGL_EndList ' The next smoke-threads are just clone of the first For i = 1 To %EFFECT_QUALITY 'TBGL_Rotate GetTickCount/1000+1/%EFFECT_QUALITY,1,1,1 tbgl_CallList %EFFECT next TBGL_UseBlend %FALSE TBGL_DeleteList %EFFECT TBGL_DrawFrame if TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE Wend TBGL_DestroyWindow '--------------------------------------------------- 2 // ' This function serves to initialize all particles Function InitParticles( ) as long For i = 1 To %MAXPARTICLES BornParticle(i) next end function '------------------------------------------------- 3 // ' 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 '-------------------------------------- 4 // Function RenderParticles () As Long 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 '---------------------------------------------- 5 // 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 '---------------------------------------------- 6 // Function ParticleCode() As Long 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 end function

I am sitting in an internet cafe and working with textwriter. the code tags above doesn't work as I can see, sorry.

frank

Lionheart008
02-04-2012, 13:54
Now I need an entity or new unit script example for particles or similar things at the board, I've found nothing today.

here's my next silly approach, but that's not working. It's needed to make entity for particle effects and entity for start/init particles too? I am not familar with these new techniques (not yet) ;)





' 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

Petr Schreiber
02-04-2012, 21:04
Hi Lionheart,

you might want to read through the User defined entities (http://www.thinbasic.com/community/content.php?19-tbgl-user-defined-entities) to see, how to design custom entity.

The first thing you need to do is to identify:

which properties it should have (from the example you posted we can see speed, fade factor, ...) and transform it to custom TYPE
which behavior they should have and transform it to custom FUNCTIONs


Petr

Lionheart008
18-04-2012, 11:02
thanks petr for the link and infos. I have it totally forgotten to answer here! If there is time I will check new tbgl unit's and your examples. regards, frank