How to implement joints and bones in openGL?

opengl

Solution

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

Problem

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?

Original source