i hav problem. it bug me for couple weeks now
i try to code skeletal animation... but it dont work!!!
i can post what i have currently that isnt working
ill post some things im using...
i am exporting model from blender.
my model format:
i use a 4x4 matrix for each bone. blender calls the 4x4 matrix "armaturespace". theres also a 3x3 matrix called "bonespace" but i dont use that one... i dont really know which one i should be using.
each vert looks like this:
x y z xnormal ynormal znormal
['bonename', weight with bone]
['bonename2', weight with bone]
['bonename3', weight with bone]
etc.
im using c++/opengl for the gam
no trouble in loading the blender model
i only export still pose and load that
no trouble with everything else besides the drawing...
this is my draw code...
int drawModelAnim(MODEL* modelname, GLuint texname, float mod_x, float mod_y, float mod_z)
{
int triCount;
int v1, v2, v3;
float temp[16];
float x_, y_, z_, u_, v_;
float* normal;
float* vert;
triCount = modelname->triCount;
glTranslatef(mod_x,mod_y,mod_z);
glBindTexture(GL_TEXTURE_2D, texname);
glBegin(GL_TRIANGLES);
for(int t=0; t<triCount; t++)
{
//verts from triangle
v1=modelname->triangle[t].v1;
v2=modelname->triangle[t].v2;
v3=modelname->triangle[t].v3;
//VERTEX 1
x_=modelname->vertex[v1].x; y_=modelname->vertex[v1].y; z_=modelname->vertex[v1].z;
u_ = modelname->triangle[t].v1U;
v_ = modelname->triangle[t].v1V;
for (int j=0; j<16; j++){ temp[j] = 0; }
for(int i; i<modelname->vertex[v1].boneamount; i++){
for(int j = 0; j<16; j++){
temp[j] += ( modelname->bone[ modelname->vertex[v1].boneind[i] ].mat_rotation[j] ) *
( modelname->vertex[v1].bonewgt[i] );
}
}
normal = multiplybymatrix(modelname->vertex[v1].normx, modelname->vertex[v1].normy, modelname->vertex[v1].normz, temp);
vert = multiplybymatrix(x_, y_, z_, temp);
glTexCoord2f(u_, v_);
glNormal3f(normal[0], normal[1], normal[2]);
glVertex3f(vert[0], vert[1], vert[2]);
//VERTEX 2
x_=modelname->vertex[v2].x; y_=modelname->vertex[v2].y; z_=modelname->vertex[v2].z;
u_ = modelname->triangle[t].v2U;
v_ = modelname->triangle[t].v2V;
for (int j=0; j<16; j++){ temp[j] = 0; }
for(int i; i<modelname->vertex[v1].boneamount; i++){
for(int j = 0; j<16; j++){
temp[j] += ( modelname->bone[ modelname->vertex[v2].boneind[i] ].mat_rotation[j] ) *
( modelname->vertex[v2].bonewgt[i] );
}
}
normal = multiplybymatrix(modelname->vertex[v2].normx, modelname->vertex[v2].normy, modelname->vertex[v2].normz, temp);
vert = multiplybymatrix(x_, y_, z_, temp);
glNormal3f(normal[0], normal[1], normal[2]);
glVertex3f(vert[0], vert[1], vert[2]);
//VERT 3
x_=modelname->vertex[v3].x; y_=modelname->vertex[v3].y; z_=modelname->vertex[v3].z;
u_ = modelname->triangle[t].v3U;
v_ = modelname->triangle[t].v3V;
for (int j=0; j<16; j++){ temp[j] = 0; }
for(int i; i<modelname->vertex[v3].boneamount; i++){
for(int j = 0; j<16; j++){
temp[j] += ( modelname->bone[ modelname->vertex[v3].boneind[i] ].mat_rotation[j] ) *
( modelname->vertex[v3].bonewgt[i] );
}
}
normal = multiplybymatrix(modelname->vertex[v3].normx, modelname->vertex[v3].normy, modelname->vertex[v3].normz, temp);
vert = multiplybymatrix(x_, y_, z_, temp);
glTexCoord2f(u_, v_);
glNormal3f(normal[0], normal[1], normal[2]);
glVertex3f(vert[0], vert[1], vert[2]);
}
glEnd();
}
and this is the multiplybymatrix
float* multiplybymatrix( float x, float y, float z, float* matrix)
{
float ret[3];
ret[0] = x*matrix[0]+y*matrix[4]+z*matrix[8]+matrix[12];
ret[1] = x*matrix[1]+y*matrix[5]+z*matrix[9]+matrix[13];
ret[2] = x*matrix[2]+y*matrix[6]+z*matrix[10]+matrix[14];
return ret;
}
/*
ive tried both
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
and
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
orders, with no result.
*/
this what it looks like if i just draw without bone calculation
this character is not visible on screen (or idk where its drawn) if i do try drawing with the skeletabob
...
i hope this enough info...