Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 8 of 8

Thread: laser (tbgl) collision example

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    41
    Posts
    914
    Rep Power
    97

    laser (tbgl) collision example

    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
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    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___ by Petr (unformatted when the forum moved from the old one)
    Attached Files Attached Files

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,551
    Blog Entries
    2
    Rep Power
    10
    Quote Originally Posted by zak View Post
    (unformatted when the forum moved from the old one)
    Code formatting fixed in the referred post.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    41
    Posts
    914
    Rep Power
    97
    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
    Last edited by Lionheart008; 23-03-2012 at 14:16.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  5. #5
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    41
    Posts
    914
    Rep Power
    97
    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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	particles-left-to-right-simple.png 
Views:	57 
Size:	14.1 KB 
ID:	7855  
    Attached Files Attached Files
    Last edited by Lionheart008; 23-03-2012 at 14:25.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  6. #6
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    41
    Posts
    914
    Rep Power
    97
    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
    Attached Files Attached Files
    Last edited by Lionheart008; 02-04-2012 at 13:59.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,352
    Rep Power
    645
    Hi Lionheart,

    you might want to read through the 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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  8. #8
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    41
    Posts
    914
    Rep Power
    97
    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
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. Replies: 0
    Last Post: 29-01-2012, 13:13
  2. TBGL Sprites collision sample 2
    By Michael Hartlef in forum TBGL module by Petr Schreiber
    Replies: 7
    Last Post: 03-11-2009, 15:51
  3. TBGL sprite collision; I want to tune the box2circle collision a bit
    By Michael Hartlef in forum TBGL module by Petr Schreiber
    Replies: 3
    Last Post: 31-07-2009, 23:36
  4. 2D and Collision Detection
    By Michael Clease in forum TBGL General
    Replies: 10
    Last Post: 04-02-2008, 15:49
  5. good collision paper
    By kryton9 in forum TBGL General
    Replies: 4
    Last Post: 06-02-2007, 22:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •