# Rotation not working correctly in skeletal animation

This topic is 4991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

last night i started adding skeletal animation to my MilkShape model class (only joint rotation for now). well, it works except for the fact that the verticies are moving out from the bone and back in, as if they were rotating around a point a slight distance away from the bone. ill post the code i wrote as well as a variable explanation
void MSmodel::rotatebone(int bonei, float angle, float xAxis, float yAxis, float zAxis){
int i,l,b;                            // looping vars
float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);
CPoint vNewPos;
CPoint vPos;

for(i=0; i<meshes; i++){
for(l=0; l<mesh.numverts; l++){
for(b=0; b<mesh.vert[l].owners.size(); b++){
if(mesh.vert[l].owners == bonei){
vPos = mesh.vert[l].pos - bone[bonei].pos;

vNewPos.x = (cosTheta + (1 - cosTheta) * xAxis * xAxis) * vPos.x;
vNewPos.x += ((1 - cosTheta) * xAxis * yAxis - zAxis * sinTheta) * vPos.y;
vNewPos.x += ((1 - cosTheta) * xAxis * zAxis + yAxis * sinTheta) * vPos.z;

vNewPos.y = ((1 - cosTheta) * xAxis * yAxis + zAxis * sinTheta) * vPos.x;
vNewPos.y += (cosTheta + (1 - cosTheta) * yAxis * yAxis) * vPos.y;
vNewPos.y += ((1 - cosTheta) * yAxis * zAxis - xAxis * sinTheta) * vPos.z;

vNewPos.z = ((1 - cosTheta) * xAxis * zAxis - yAxis * sinTheta) * vPos.x;
vNewPos.z += ((1 - cosTheta) * yAxis * zAxis + xAxis * sinTheta) * vPos.y;
vNewPos.z += (cosTheta + (1 - cosTheta) * zAxis * zAxis) * vPos.z;

mesh.vert[l].pos = bone[bonei].pos + vNewPos;
}
}
}
}
}
type CPoint is in most basic terms a class that holds x,y, and z values mesh is an array of structs of all meshes vert is an array of structs of all verticies and is declared by mesh bone is an array of structs of all joints pos (in both bone and vert) is a CPoint of its current location owners is a vector of the indicies of all the bones that control the selected vertex if anyone can tell me what im doing wrong, or a suggested improvement about how i am doing things, please reply, thank you.

##### Share on other sites
It looks like you are pivoting on the wrong point. At frame zero does everything look ok, and then a few rotation frames later everything appears disjoined?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015827
×