CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    [RESOLVED] Real-time vehicle animation in .NET

    Hello,
    I work for a company that produces accident reconstruction software. We have a vehicle dynamics program that realistically simulates the motion of a vehicle (position and rotation of car and steer angle of individual wheels, etc).

    All the positions of the car are stored into an array called AMTN. The vehicle dynamics program can calculate positions at time steps finer than .005 secs (200 FPS).

    I need to represent this data in real time, and so far I have not been able to accomplish this. I have tried doing this in Excel/VBA, VB6, and am currently trying to do it in VB.NET.

    I have used a whole plethora of timers and counters as well as different methods of drawing lines on graphics linked to images linked to picture boxes, etc. My animation program writes/clears the screen correctly, but there is clearly some sort of lag in either the timer or writing method. I have scaled it down to 25 FPS and there is still a lag.

    Here is an example of what I am trying to do with each tick of the timer:

    ***********************************************************
    Code:
        Sub Timer1_Tick1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            
    MyGraphic.Clear(Color.White)
    
            If Actr < STOctr + 1 Then
                'Display vehicle
                MyGraphic.DrawLine(Mypen, AMTN(Actr, 11), AMTN(Actr, 12),   AMTN(Actr, 13), AMTN(Actr, 14))
                MyGraphic.DrawLine(Mypen, AMTN(Actr, 13), AMTN(Actr, 14), AMTN(Actr, 15), AMTN(Actr, 16))
                MyGraphic.DrawLine(Redpen, AMTN(Actr, 15), AMTN(Actr, 16), AMTN(Actr, 17), AMTN(Actr, 18))
                MyGraphic.DrawLine(Mypen, AMTN(Actr, 17), AMTN(Actr, 18), AMTN(Actr, 11), AMTN(Actr, 12))
    
                Awindow.Image = MyImage
                Actr = Actr + 1
    
            Else
                Timer1.Enabled = False
                Playing = False
                Animation_start.Text = "Start"
            End If
    ************************************************************

    With each tick of the timer, the graphic is cleared, lines representing each side of the car are drawn onto the graphic, and the picturebox is then assigned to the image, which is linked to the graphic. This is just like how your asteroids program works.

    Do I need to change my method? Should I use sprites? Or would it be better for me to create images/bitmaps of the animation beforehand and simply flip through them with a timer?

    I'm thinking that creating the images beforehand might work because I do not have to calculate the vehicle's position as it is predetermined by my AMTN matrix.

    Please let me know if there is a more efficient way of displaying my vehicle on the screen that would allow for greater FPS, etc.

    Your expertise is much appreciated!

    -Matt
    Last edited by HanneSThEGreaT; October 14th, 2009 at 11:46 AM. Reason: Code Tags!

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Real-time vehicle animation in .NET

    Welcome to the Forums Matt !

    There is an excellent article about animation, here on CG :

    http://www.codeguru.com/vb/gen/vb_gr...le.php/c15317/

    Please, in future remember to use &#091;CODE] tags when posting codes.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Real-time vehicle animation in .NET

    I would look at Silverlight. If you want cool ability, take a look at http://www.silverlight.net

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

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

Featured