Click here to Skip to main content
Licence CPOL
First Posted 2 Oct 2009
Views 8,404
Downloads 116
Bookmarked 11 times

TB-Stickfigure

By | 2 Oct 2009 | Article
Combine graphic objects to create own scenes

Introduction

This article was made for testing how to simply create realism looking objects by line painting.

A problem I would to solve in VB.NET is the animation performance. Because of keeping vector datas, it should be easy to create the animation with good performance, or sending the data to any 3D software like Truespace or Maya.

Background

The main idea was to make animations driven by external programs, music, joybad controller, etc. 

How will your music visualization look if your own objects will dance for Bass drum, melody and hihats? That was my question.

This is a good document for keeping the proportions.

Using the Code

A main view should be taken to the clsStickStructure.vb Class. It save the properties of any point. It also saves if the point will be in reference to any other point. So it is possible to make the animation with simple kinematics.

While moving the mouse, the selection has to be fixed to a grid to create models faster:

If MoveIndex > -1 Then
    If e.Button = Windows.Forms.MouseButtons.Left _
	Then Call MoveObjectToPosition(MoveIndex, New Point(e.X, e.Y), False)
    If e.Button = Windows.Forms.MouseButtons.Right _
	Then Call MoveObjectToPosition(MoveIndex, New Point(e.X, e.Y), True)
End If 

To make the reference to the points, it is necessary to keep an object for each point.

 Private Sub MoveObjectToPosition(ByVal ObjectIndex As Integer, ByVal Pos As PointF, _
	ByVal MoveFullObject As Boolean)
        Dim X, Y As Integer
        Dim DiffX, DiffY As Integer
        'Dim item2 As StickStructure
        Dim i As Integer

        X = CInt(Pos.X / GridSize) * GridSize
        Y = CInt(Pos.Y / GridSize) * GridSize

        X = X - MittX
        Y = Y - MittY
        If Stick.Points IsNot Nothing _
		AndAlso UBound(Stick.Points)>= MoveIndex Then       
            If LastPoint.Pos2Active = True Then
                DiffX = Stick.Points(MoveIndex).Pos2Relativ.X - X
                DiffY = Stick.Points(MoveIndex).Pos2Relativ.Y - Y
                Stick.Points(MoveIndex).Pos2Relativ = New PointF(X, Y)

                If MoveFullObject = True Then
                    Stick.Points(MoveIndex).Pos1Relativ = _
			New PointF(Stick.Points(MoveIndex).Pos1Relativ.X - DiffX, _
			Stick.Points(MoveIndex).Pos1Relativ.Y - DiffY)

                    If Stick.Points(MoveIndex).Pos1LinkToIndexToP1 > -1 _
		     Then Stick.Points(Stick.Points(MoveIndex).Pos1LinkToIndexToP1)._
			Pos1Relativ = Stick.Points(MoveIndex).Pos1Relativ
                    If Stick.Points(MoveIndex).Pos1LinkToIndexToP2 > -1 _
		     Then Stick.Points(Stick.Points(MoveIndex).Pos1LinkToIndexToP2)._
			Pos2Relativ = Stick.Points(MoveIndex).Pos1Relativ
                End If

            Else
                DiffX = Stick.Points(MoveIndex).Pos1Relativ.X - X
                DiffY = Stick.Points(MoveIndex).Pos1Relativ.Y - Y
                Stick.Points(MoveIndex).Pos1Relativ = New PointF(X, Y)

                If MoveFullObject = True Then
                    Stick.Points(MoveIndex).Pos2Relativ.X = _
			Stick.Points(MoveIndex).Pos2Relativ.X - DiffX
                    Stick.Points(MoveIndex).Pos2Relativ.Y = _
			Stick.Points(MoveIndex).Pos2Relativ.Y - DiffY

                    If Stick.Points(MoveIndex).Pos2LinkToIndexToP1 > -1 _
			Then Stick.Points(Stick.Points(MoveIndex)._
			Pos2LinkToIndexToP1).Pos1Relativ = _
			Stick.Points(MoveIndex).Pos1Relativ
                    If Stick.Points(MoveIndex).Pos2LinkToIndexToP2 > -1 _
			Then Stick.Points(Stick.Points(MoveIndex)._
			Pos2LinkToIndexToP2).Pos2Relativ = _
			Stick.Points(MoveIndex).Pos1Relativ
                End If
            End If

            For i = 0 To Stick.Points.Length - 1
                If i <> MoveIndex Then
                    If Stick.Points(i).Pos1LinkToIndexToP1 = _
		    Stick.Points(MoveIndex).Id Then Stick.Points(i).Pos1Relativ = _
			Stick.Points(MoveIndex).Pos1Relativ
                    If Stick.Points(i).Pos1LinkToIndexToP2 = _
		    Stick.Points(MoveIndex).Id Then Stick.Points(i).Pos1Relativ = _
			Stick.Points(MoveIndex).Pos2Relativ
                    If Stick.Points(i).Pos2LinkToIndexToP1 = _
		    Stick.Points(MoveIndex).Id Then Stick.Points(i).Pos2Relativ = _
			Stick.Points(MoveIndex).Pos1Relativ
                    If Stick.Points(i).Pos2LinkToIndexToP2 = _
		    Stick.Points(MoveIndex).Id Then Stick.Points(i).Pos2Relativ = _
			Stick.Points(MoveIndex).Pos2Relativ
                End If
            Next
        End If
    End Sub

    Private Sub PaintMousePosition(ByVal Pos As PointF)
        If Me.pic.Image Is Nothing Then Exit Sub
        Dim i As Integer = 5
        Pos.X = CInt(Pos.X / Me.GridSize) * Me.GridSize
        Pos.Y = CInt(Pos.Y / Me.GridSize) * Me.GridSize
        Dim P As New Pen(Color.FromArgb(100, 90, 90, 90), 1)
        Dim PBlue As New Pen(Color.FromArgb(90, 90, 90, 255), 1)
        PBlue.DashStyle = Drawing2D.DashStyle.DashDotDot

        Using gr As Graphics = Graphics.FromImage(Me.pic.Image)
            'Cross
            gr.DrawLine(P, CInt(Pos.X - i), CInt(Pos.Y - i), CInt(Pos.X + i), _
			CInt(Pos.Y + i))
            gr.DrawLine(P, CInt(Pos.X + i), CInt(Pos.Y - i), CInt(Pos.X - i), _
			CInt(Pos.Y + i))

            'Horizontal line
            gr.DrawLine(PBlue, 0, Pos.Y, Me.pic.Image.Width, Pos.Y)

            'Vertical line
            gr.DrawLine(PBlue, Pos.X, 0, Pos.X, pic.Image.Height)

        End Using
    End Sub

To select the next point object, the following function will help: 

Private Function GetNextFreeItemIdNumber()
        Dim i As Integer
        Dim res As Integer = 1
        Dim S As clsStickStructure.StickPoint

        If Stick.Points Is Nothing OrElse Stick.Points.Length = 0 Then Return 1

        For i = 0 To Stick.Points.Length - 1
            S = Stick.GeItemById(Stick.Points(i).Id)
            If S.Equals(Nothing) Then
                Exit For
            Else
                res = S.Id + 1
            End If
        Next
        Return res
    End Function

Points of Interest

I think VB.NET is very easy to use for making such an tool. And after having the stick figure objects as data, it could be very quick for any animation.   

History

  • 2nd October, 2009: Initial post

The tool is prepared to fix the angles in the project. But I had no time to include it until today. Hopefully someone has fun working on the project. The animation control would be a nice tool for the future too.  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nasenbaaer



Switzerland Switzerland

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIt looks cool, but... PinmemberShane Story6:09 5 Oct '09  
GeneralMy Vote of 4 Pinmembersam.hill18:30 2 Oct '09  
GeneralRe: My Vote of 4 PinmvpDave Kreskowiak6:49 11 Oct '09  
GeneralMy vote of 1 Pinmembergbraux11:00 2 Oct '09  
GeneralMy vote of 1 PinmvpDave Kreskowiak10:18 2 Oct '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 2 Oct 2009
Article Copyright 2009 by Nasenbaaer
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid