Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: 2D Skeletal Animation System Questions (and Source)

  1. #1

    2D Skeletal Animation System Questions (and Source)

    Hey all, I've had a few minutes since Chance came along and started back to work on some of my projects. One of these is a 2D Skeletal Animation Package (lets you create 2D sprites and then animate them easily). To achieve this I'm using the standard Joint and Bone mech.

    Now though I have some problems, I can't seem to find out how to perform proper translations and rotations based upon the other "Nodes" in the system.

    You can view the source Here (Rather then post the entire thing in the forum) and here is a sample of the desired output:


    Basically the node at the top in green is the root joint (Joints don't have to have bones, but bones must have end point joints). From their I have a "Bone" moving on a downward vector (X:0, Y:1) etc, etc...

    When rendering I take the root joint, walk its bones and their joints recursively and place the items on the screen. The idea is you would call Translate(X, Y) or Rotate(Degree) and this would set the FRelativeValid flag to false, upon reading the RelativeTranslation or RelativeRotation it calls CalculateRelative (only if RelativeValid = false) and then returns the calculated values (as well as sets privates for later use to lower recursion and overhead). I should then be able to plot the RelativeTranslation point to the screen directly (minus any world transformations).

    What code should be in CalculateRelative?

    If I'm completely on the wrong track please SPEAK UP! I have no clue what I'm doing and their are few if any good articles on the subject. This can't be rocket science as I know that others have done it in 3D, I just want to do it in 2D.

    Thanks ahead of time.

  2. #2

    2D Skeletal Animation System Questions (and Source)

    I think that the easiest way is to use OpenGL's glPushMatrix and glPopMatrix. The pseudocode for drawing would be
    Code:
    procedure TBone.DrawBone;
    var
     i : integer;
    begin
     glPushMatrix;
     RelativeTranslation;
     RelativeRotation;
     for i := 0 to ChildrenCount - 1 do
      Children[i].DrawBone;
     glPopMatrix;
    end;
    
    procedure TSkeleton.Draw;
    begin
     root.DrawBone;
    end;
    If you dont want to use glPushMatrix and glPopMatrix (or you dont use OpenGL) then in each bone (or joint?) you should store relative position/rotation (bone's local coordinate system) and absolute position/rotation (world coordinate system) Then to calculate new absolute values:

    Code:
     AbsoluteMatrix := RelativeMatrix*Parent.AbsoluteMatrix;
    I hope it helps.

  3. #3

    2D Skeletal Animation System Questions (and Source)

    Interesting.. I am currently starting a bone animator for OpenGL. Problem with that render recursion is that each polygon may have vertices that belong to different bones. So in theory i should do recursive matrix multiplication (whole bone branch) per vertex? Maybe some faster way?

  4. #4

    2D Skeletal Animation System Questions (and Source)

    Most characters use the hips as the root node.

    User137, are you referring to weighted vertices? Recurse through each node, storing the resulting matrix in that node. When it comes to rendering the weighted vertices (making sure that the sum of all weights for each vertex equals one), multiply the matrix for the node by the vertex weight assigned to that node. Add these matrices together to get the transformation for that vertex.

  5. #5

    2D Skeletal Animation System Questions (and Source)

    I don't know about weighted vertices, each vertex has an index that refers to bone.

    Yes, having relative and transformed matrix for each bone makes it only 1 multiplication per vertex, smooth enough.

    Can't remember now if glMultMatrixf is allowed to call between glBegin and glEnd but i guess i could calculate it too...

  6. #6

    2D Skeletal Animation System Questions (and Source)

    Quote Originally Posted by User137
    Interesting.. I am currently starting a bone animator for OpenGL. Problem with that render recursion is that each polygon may have vertices that belong to different bones. So in theory i should do recursive matrix multiplication (whole bone branch) per vertex? Maybe some faster way?
    Well I got the system working last night, what I finally ended up doing was this (I'll post the app once I complete it):
    • Removed All Bones
      Used only Joints (joints have multiple references out and a single parent)
      Joints manage their child joints
      Joints contain methods to: Rotate, Translate, and Scale (recursively or non-recursivly)

    This pretty much worked to get things running. Now I'm going to go back and setup properties for Rotation, Scale and Translation as I'm not a big fan of procedures for these operations. That and right now their is no frame of reference . I'll keep everyone posted.

  7. #7

    2D Skeletal Animation System Questions (and Source)

    My old steps :)
    http://xproger.mirgames.ru/tmp/TFK_ME.rar

    IMHO using of matrixes is not desirable

  8. #8

    2D Skeletal Animation System Questions (and Source)

    Quote Originally Posted by XProger
    My old steps
    http://xproger.mirgames.ru/tmp/TFK_ME.rar

    IMHO using of matrixes is not desirable
    Well the exe looks decent, minus the fact that nothing is readable in it (I'm guessing not in english). I did manage to get a model loaded and take a look at it.

    Any chance you have the source lying around as well? I have everything working fine in my system now (well at least you can rotate and translate each node). Now I have to figure out how to get movement from pointA to pointB using locked nodes and max ranges. Funny how I passed Algebra, Calc, Trig all with flying colors and now I can't remember a damned bit of it

  9. #9

    2D Skeletal Animation System Questions (and Source)

    Here's small demo i made, no source included because the whole class is unfinished and uses my game engine.. just hope they run as smooth on others as it does for me:
    http://www.filethatfile.com/uploads/33539BoneDemo.zip
    Mouse + wheel rotate and zoom the view. The demo is only making a random bone tree and multiplying each bone matrices per frame.


  10. #10
    This is very old! But how is the progress of this?

    I would need to create 2D bones animation and I would like some advices of where to start!

Page 1 of 2 12 LastLast

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
  •