Results 1 to 8 of 8

Thread: Tail or streak Effect

  1. #1

    Thread Starter
    New Member Atheer's Avatar
    Join Date
    Jun 2008
    Location
    Baghdad - Iraq
    Posts
    7

    Tail or streak Effect

    Hello guys,

    I would like to make a tail or streak-like effect for a moving points that fades out behind them. I tried to avarage the color of the buffer each frame then bitblt the results, I got something similar to the tail but at the cost of speed.

    So anyone has any idea? I am using GDI API with VB6.

    Thanks in advance.

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Tail or streak Effect

    There is a few things you can do with GDI, a lot depends on what else you have going on and how many points you have.

    I'd be better placed to suggest ideas if i knew a little more about what you are doing.

    You say you have tried averaging the colours in the buffer, are you using a DIB for a buffer? Are you familiar with DIBs. How many moving points do you potentially have? How far (in pixels) do they move each frame?

    There does come a point when regular GDI simply can't hack the amount of stuff going on. It's the time to consider using DirectX or Open GL.

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Tail or streak Effect

    Quote Originally Posted by Milk
    There does come a point when regular GDI simply can't hack the amount of stuff going on. It's the time to consider using DirectX or Open GL.
    While this is true.. it is possible to hack together stuff that looks fine anyway..

    What is the object you're trying to tail ? Is it large? Small? Medium sized? Square? Circle?

    One way I have used before to streak behind a large object, was to create a 1-pixel high by 40-pixel wide white image.. then blit that behind the object about 10 times. Then, with each one, I would just average random pixels from around rows 4-10, until the end had pretty much all of the pixels transparent.

    So, instead of calculating 40*10 pixels individually and drawing them individually (which costs alot of cycles), you're drawing only 10 images, and altering only 7 of them slightly each time.

    Attached is an extremely bad example in paint.. but it sorta outlines what I mean.

    chem
    Attached Images Attached Images  
    Last edited by chemicalNova; Jul 18th, 2008 at 01:50 AM.

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Tail or streak Effect

    I'm pleasantly surprised at your post there Chem. I like GDI, it can do most of the things I want. I'll show you an example of what I mean by too much, that smoke trail below works fine in VB on it's own, but if I had say another 100 sprites and a few other blend effects then it starts to struggle.
    Attached Images Attached Images  

  5. #5
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Tail or streak Effect

    I was hoping Atheer was going to give us an idea of how many points he's trying to handle, 10? 100? 10000?

  6. #6

    Thread Starter
    New Member Atheer's Avatar
    Join Date
    Jun 2008
    Location
    Baghdad - Iraq
    Posts
    7

    Re: Tail or streak Effect

    hello guys,

    I'm sorry for being late in my reply, I was out of internet connection..
    anyway,

    In fact am doing a kind of galaxy simulation with stars rotating around the center of the galaxy (using centripetal force and gravitation..etc)..so the number of my starts could be anything from 500 to 1000.

    I know about DIB sections..but actaully I did not use it , I used instead GetBitmapBits

    Milk - can you please give some hint about the smoke effect you made in that picture?


    thanks to all of guys

  7. #7
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Tail or streak Effect

    I would recommend that you don't use GetBitmapBits, rather create a DIBSection of the right size and use a SafeArray hack to access the pixel data. This means you don't have to make a copy of the bitmap every time you want to manipulate it.

    This is the smoke trail code, nothing special. Attached is the source bitmap, it needs to be loaded into the PicSrc picturebox.
    Code:
    Option Explicit
    Private Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, _
        ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
        ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal widthSrc As Long, _
        ByVal heightSrc As Long, ByVal blendFunct As Long) As Boolean
        
    Private Const USE_BITMAP_ALPHA = &H1000000 'AC_SRC_ALPHA scaled up to the 4th byte of a long
    Private Const FULL_OPACITY = &HFF0000 '255 scaled up to the 3rd byte of a long
    
    Private mMosX As Long
    Private mMosY As Long
    Private mFrameX() As Long
    Private mFrameY() As Long
    Private mFrameUB As Long
    Private mCurFrame As Long
    Private mFrameSz As Long
    
    Private Sub Form_Load()
       ScaleMode = vbPixels
       AutoRedraw = True
       With picSrc
          .AutoRedraw = True
          .Autosize = true
          .ScaleMode = vbPixels
          .BorderStyle = 0
          .Visible = false
          mFrameUB = .Width \ .Height - 1
          mFrameSz = .Height
       End With
       ReDim mFrameX(mFrameUB)
       ReDim mFrameY(mFrameUB)
    End Sub
    
    Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       mMosY = -mFrameSz \ 2
       mMosX = X + mMosY
       mMosY = Y + mMosY
    End Sub
    
    Private Sub Timer1_Timer()
    Dim i As Long, j As Long, XOff As Long
       If mCurFrame < mFrameUB Then mCurFrame = mCurFrame + 1 Else mCurFrame = 0
       mFrameX(mCurFrame) = mMosX - 8 + Rnd * 16
       mFrameY(mCurFrame) = mMosY - 8 + Rnd * 16
       Cls
       XOff = mFrameUB * mFrameSz
       j = mCurFrame - 1
       For i = 0 To mFrameUB
          If j < mFrameUB Then j = j + 1 Else j = 0
          AlphaBlend hDC, mFrameX(j), mFrameY(j), mFrameSz, mFrameSz, picSrc.hDC, XOff, 0, mFrameSz, mFrameSz, USE_BITMAP_ALPHA Or &H400000
          XOff = XOff - mFrameSz
       Next i
       Refresh
    End Sub
    Attached Files Attached Files

  8. #8

    Thread Starter
    New Member Atheer's Avatar
    Join Date
    Jun 2008
    Location
    Baghdad - Iraq
    Posts
    7

    Re: Tail or streak Effect

    Thanks a lot Milk (for the tip and for the code sample) - I will check the DIBSection and the safe array thing and get to you guys..

    thanks again Milk..

Posting Permissions

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



Click Here to Expand Forum to Full Width