chutsu
chutsu

Reputation: 14103

How to implement joints and bones in openGL?

I am in the process of rolling my own openGL framework, and know how to draw 3d objects ... etc...

But how do you define relationships between 3d objects that may have a joint? Or how do you define the 3d object as being a "bone"? Are there any good resources?

Upvotes: 10

Views: 6323

Answers (2)

s3rius
s3rius

Reputation: 1452

As OpenGL is only a graphics library and not a 3D modeling framework the task of defining and using "bones" falls onto you.

There are different ways of actually implementing it, but the general idea is:

You treat each part of your model as a bone (e.g. head, torso, lower legs, upper legs, etc).
Each bone has a parent which it is connected to (e.g. the parent of the lower left leg is the upper left leg).
Thus each bone has a number of children.

enter image description here

Now you define each bone's position as a relative position to the parent bone. When displaying a bone you now multiply it's relative position with the parent bone's relative position to get the absolute position.

To visualize:
Think of it as a doll. When you grab the doll's arm and move it around, the relative position (and rotation) of the hand won't change. Its absolute position WILL change because you've moved one of its parents around.

When tried skeletal animations I learnt most of it from this link: http://content.gpwiki.org/index.php/OpenGL:Tutorials:Basic_Bones_System

Upvotes: 11

datenwolf
datenwolf

Reputation: 162164

But how do you define relationships between 3d objects that may have a joint?

OpenGL does not care about these things. I't a pure drawing API. So it's upon you to unleash your creativity and define such structures yourself. The usual approach to skeletal animatio is having a bone/rig system, where each bone has an orientation (represented by a quaternion or a 3×3 matrix) a length and a list of bones attached to it further, i.e. some kind of tree.

I'd define this structure as

typedef float quaternion[4];

struct Bone {
    quaternion orientation;
          float length;

            int  n_subbones;
           Bone *subbones;
};

In addition to that you need a pivot from where the rig starts. I'd do it like this

typedef float vec3[3];

struct GeomObjectBase {
           vec3 position;
    quaternion orientation;
};

struct BoneRig {
    struct GeomObjectBase gob;

    struct Bone pivot_bone;
}

Next you need some functions that iterate through this structure, generate the matrix palette out of it, so that it can be applied to the model mesh.

note: I'm using freeglut

Totally irrelevant

Upvotes: 8

Related Questions