Jump to content
  • Advertisement
Sign in to follow this  
relpats_eht

Rotation not working correctly in skeletal animation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!