Original Post
I''m writing my own skeletal animation class and im having some problems, If i update the bones and the vertices without rotating the bones everything is fine. But when I rotate the bones they seem to still be rotating about the origin instead of their location. I am exporting from milkshape so the rotation frames i believe are in radians, and the bone positions relative to the parent (am i mistaken?).
After I load the bones I set up their inverse translate and translate matrices:
int idd;
for (i = 0; i < bonecount; i ++)
{
bones[i].invabs->SetTranslateInverse(bones[i].pos);
bones[i].abs->SetTranslate(bones[i].pos);
idd = bones[i].parent;
while(idd != -1)
{
bones[i].invabs->MultiplyTranslateInverse(bones[idd].pos);
bones[i].abs->MultiplyTranslate(bones[idd].pos);
idd = bones[idd].parent;
}
}
When I update the bones I use this recursive function
void cModel::DoBone(cMatrix *mat, int bone)
{
mat->Multiply(mat, bones[bone].invabs, mat);
if (bones[bone].numrframes > 0)
{
mat->MultiplyRotateAxis(bones[bone].rframes[0].vals[2], 0,0,1);
mat->MultiplyRotateAxis(bones[bone].rframes[0].vals[1], 0,1,0);
mat->MultiplyRotateAxis(bones[bone].rframes[0].vals[0], 1,0,0);
}
mat->Multiply(mat, bones[bone].abs, mat);
if (bones[bone].parent != -1)
DoBone(mat, bones[bone].parent);
}
void cModel::Update()
{
long i;
cMatrix *mat = new cMatrix();
idd+=.5;
for(i = 0; i < bonecount; i++)
{
if (i == ballbone) continue;
mat->SetIdentity();
DoBone(mat, i);
bones[i].mat->SetValues(mat->GetValues());
}
delete mat;
for(i = 0; i < vertcount; i++)
{
bones[verts[i].bone].mat->MultiplyVertex(verts[i].xyz, vertout[i].xyz);
}
}
If i comment out the 3 rotation lines everything appears fine. Also my rotation functions take degrees so after I load in the bone rotation frames I do this.
for (int d = 0; d< 3;d++)
bones[i].rframes[j].vals[d] = bones[i].rframes[j].vals[d] * 180 /3.14;
I think that the bone postitions are relative since that would make sense if i''m only translating down to the parent not to the origin before i rotate.
Any suggestions?