Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 2D Skeletal Animation with OpenGL

Credits go to Matt Smith for helping out!
This thread is locked; no one can reply to it. rss feed Print
2D Skeletal Animation with OpenGL
Archon
Member #4,195
January 2004
avatar

I'm wanting to make a flat (virtually 2D) object move about the screen but employ skeletal animation using textured quads for each body part... What would be the best way to do this? A simple vertex mesh (like MD3)?

Secondly, what's the recommended way (and any other way) to rotate the vertices and have the child vertices swing around with their parents?

Matt Smith
Member #783
November 2000

In GL, you generally use glRotatef() on the MODEL_VIEW matrix to do joints

e.g.

    transform skeleton parent (object) position
    draw torso vertices

    pushmatrix
    rotate shoulder joint
    draw upper arm vertices
    pushmatrix
    rotate elbow joint
    draw lower arm vertices
    popmatrix
    popmatrix  // returns to parent

    pushmatrix etc... repeat for other limbs

That's the basic idea, but I've missed out things like translating to the pivot (I'm not sure at this moment whether this goes inside or outside the pushmatrix), and drawing polys that are stretched between two different rotation sets

Archon
Member #4,195
January 2004
avatar

Quote:

I've missed out things like translating to the pivot

Yes -- I think that this is the main problem that I have...

[edit]
I think that if I glTranslatef to move to the centre of the pivot before glScalef-ing, then the vertices would be moved too...

I don't know what you mean by "drawing polys that are stretched between two different rotation sets" though.

Matt Smith
Member #783
November 2000

If the vertices are all relative to their immediate parent joint, then you should be OK. This effectively means that each movable part will be a separate mesh.

The stretched polys are ones that have some vertices in one part, and others in another. In a 3d mesh like md3 these would be the ones around the joints. It sounds like you won't have this problem if your meshes are like paper cut-outs

Archon
Member #4,195
January 2004
avatar

OK, from this:

Quote:

If the vertices are all relative to their immediate parent joint

I've started something using that idea. The file will save their global points but I'll have to offset them when I load them.

Mr. Big
Member #6,196
September 2005

Go to: