PDA

View Full Version : Linear Blend Skinning



twoski
02-23-2014, 10:33 AM
I am working on implementing LBS for a model, however it is slightly different since the bone structure does not use a hierarchy. Transformations are given each frame in respect to the rest pose (they aren't incremental).

Right now i have figured out how to draw the skeleton in its rest pose, however I am having trouble animating the skeleton. The animation is given in the form of a file with an axis/angle transform for every bone on each keyframe.




void drawSkeleton()
{
if (bones.size() == 0)
{
cout << "ERROR - NO BONES!" << endl;
return;
}

glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_DEPTH_TEST);

glColor3f(0.2, 0.8, 0.2);

for (int i = 0; i < bones.size(); i++)
{
Joint jnta = *bones[i].jointA;
Joint jntb = *bones[i].jointB;
Transform trans = getTransform(bones[i].id);

glPushMatrix();

glBegin(GL_LINES);

double degrees = (trans.angle * 180 / 3.1415926) * 57.2957795;

glTranslatef(trans.translation[0], trans.translation[1], trans.translation[2]);
glRotatef(degrees, trans.rotation[0], trans.rotation[1], trans.rotation[2]);

glVertex3f(jnta.vector[0], jnta.vector[1], jnta.vector[2]);
glVertex3f(jntb.vector[0], jntb.vector[1], jntb.vector[2]);

glEnd();

glPopMatrix();

glPushMatrix();
glTranslatef(jnta.vector[0], jnta.vector[1], jnta.vector[2]);
glutSolidSphere(0.01, 30, 10);
glPopMatrix();

}
}

For some reason the lines i am drawing are not affected by glTranslatef. If i do the same glTranslatef with the glutSphere, the joints will move around.

Ilian Dinev
03-04-2014, 04:52 AM
It is invalid to call glTranslatef() and glRotatef() inside a glBegin()/glEnd() section.
Move the "glBegin(GL_LINES);" after glRotatef() .