Jump to content
  • Advertisement
Sign in to follow this  

Problems with skeletal animation, chaotic movements

This topic is 4591 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

Kind time of day. There was a problem with skeletal animation. I read out from mdl a file all data. At usual display of model all is normal, but as soon as I try to make skeletal animation of top of model move chaotically. I understand, what the question is enough not concrete, but I ask advice on the cores a mistake, for what reason such can occur?
public void display(GLAutoDrawable drawable)
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glu.gluLookAt(-70,75,350, 15,75,0, 0,1,0);
      object.CurFrame = object.MinFrame;

public void CalcAnimCoords(int frame)
        int CountOfCoords;
        int bNum;
        Bone b = new Bone();
        Vertex3D[] Coords;
        float x, y, z;
       for(int i=0; i<MeshLenght; i++)
           for (int j=0; j<mesh.vertex.length; j++)
               mesh.vertex[j].x = buf.vertex[j].x;
               mesh.vertex[j].y = buf.vertex[j].y;
               mesh.vertex[j].z = buf.vertex[j].z;
        for(int i=0; i<HelperLenght; i++)
            helper = InterpolationBone(frame, helper);
        for(int i=0; i<BoneLenght; i++)
            bone = InterpolationBone(frame, bone);
        for(int i=0; i<HelperLenght; i++)
            helper = CalculationBone(frame, helper);
        for(int i=0; i<BoneLenght; i++)
            bone = CalculationBone(frame, bone);
        for(int i=0; i<MeshLenght; i++) 
            Coords = new Vertex3D[10];
            for(int ii = 0; ii<mesh.VertexLenght; ii++)
               CountOfCoords = mesh.matrices[mesh.vertex_group[ii]].length;
                      for(int j = 0; j<CountOfCoords; j++)
                    bNum = mesh.matrices[mesh.vertex_group[ii]][j];
                          if ((HelperLenght>0) && (bone[bNum].object_id>=helper[0].object_id))
                        b = helper[bNum-helper[0].object_id];
                        b = bone[bNum];
                    Coords[j] = new Vertex3D();
                    Coords[j].x = mesh.vertex[ii].x - pivotpoint[b.object_id].x;
                    Coords[j].y = mesh.vertex[ii].y - pivotpoint[b.object_id].y;
                    Coords[j].z = mesh.vertex[ii].z - pivotpoint[b.object_id].z;

                    x = Coords[j].x * b.AbsMatrix.matrix[0][0]+
                    	Coords[j].y * b.AbsMatrix.matrix[1][0]+
                    	Coords[j].z * b.AbsMatrix.matrix[2][0];
                    y = Coords[j].x * b.AbsMatrix.matrix[0][1]+
                    	Coords[j].y * b.AbsMatrix.matrix[1][1]+
                    	Coords[j].z * b.AbsMatrix.matrix[2][1];
                    z = Coords[j].x * b.AbsMatrix.matrix[0][2]+
                    	Coords[j].y * b.AbsMatrix.matrix[1][2]+
                    	Coords[j].z * b.AbsMatrix.matrix[2][2];
                    Coords[j].x = x + b.AbsVector.x;
                    Coords[j].y = y + b.AbsVector.y;
                    Coords[j].z = z + b.AbsVector.z;
                mesh.vertex[ii].x = 0;
                mesh.vertex[ii].y = 0;
                mesh.vertex[ii].z = 0;
                for(int j=0; j< CountOfCoords; j++)
                    mesh.vertex[ii].x = mesh.vertex[ii].x + Coords[j].x;
                    mesh.vertex[ii].y = mesh.vertex[ii].y + Coords[j].y;
                    mesh.vertex[ii].z = mesh.vertex[ii].z + Coords[j].z;

                mesh.vertex[ii].x = mesh.vertex[ii].x/CountOfCoords;
                mesh.vertex[ii].y = mesh.vertex[ii].y/CountOfCoords;
                mesh.vertex[ii].z = mesh.vertex[ii].z/CountOfCoords;

Share this post

Link to post
Share on other sites
I understand, that the question is probably silly, but without your help to me to not understand. Tell, that I not so have asked or have made. The full code can is necessary lay out?

Share this post

Link to post
Share on other sites

* The method in which occurs definitions of the father and is caused a method for reception of an absolute matrix
* @param frame
* @param bone
* @return Entering bone with an absolute matrix
public Bone CalculationBone(int frame, Bone bone)
boolean IsHelper;

// If number "father" of the given bone is less than zero (-1) then the given bone does not have "father"
// and to consider an absolute matrix there is no sense
return bone;

// By default the father at a bone other bone
IsHelper = false;

// 1. Let's find the parent

// If we have "assistants" and at a bone "father" more or is equal to number of "assistant",
// then "father" for the given bone is "helper".
if(HelperLenght>0 && bone.parent_bone_id>=helper[0].object_id)
IsHelper = true;

bone = CalcAbsolute(frame, helper[bone.parent_bone_id-helper[0].object_id], bone);
bone = CalcAbsolute(frame, this.bone[bone.parent_bone_id], bone);

return bone;

public Bone CalcAbsolute(int frame, Bone Parent, Bone Child)
int j;
float x,y,z,sx,sy,sz;
Matrix m = new Matrix();
Quaternion q = new Quaternion();

Child.AbsMatrix = Matrix.mul(Parent.AbsMatrix,Child.AbsMatrix);

Child.AbsVector.x = Child.AbsVector.x - pivotpoint[Parent.object_id].x;
Child.AbsVector.y = Child.AbsVector.y - pivotpoint[Parent.object_id].y;
Child.AbsVector.z = Child.AbsVector.z - pivotpoint[Parent.object_id].z;

x = Parent.AbsVector.x +
Parent.AbsMatrix.matrix[0][0] * Child.AbsVector.x +
Parent.AbsMatrix.matrix[1][0] * Child.AbsVector.y +
Parent.AbsMatrix.matrix[2][0] * Child.AbsVector.z;
y = Parent.AbsVector.y +
Parent.AbsMatrix.matrix[0][1] * Child.AbsVector.x +
Parent.AbsMatrix.matrix[1][1] * Child.AbsVector.y +
Parent.AbsMatrix.matrix[2][1] * Child.AbsVector.z;
z = Parent.AbsVector.z +
Parent.AbsMatrix.matrix[0][2] * Child.AbsVector.x +
Parent.AbsMatrix.matrix[1][2] * Child.AbsVector.y +
Parent.AbsMatrix.matrix[2][2] * Child.AbsVector.z;

Child.AbsVector.x = x;
Child.AbsVector.y = y;
Child.AbsVector.z = z;

return Child;

Share this post

Link to post
Share on other sites
It is a code look, please, and prompt in what there can be a mistake.

Share this post

Link to post
Share on other sites
How are you handling things if Parent.AbsMatrix has not been calculated before you try calculating Child.AbsMatrix?

You need to make sure that the parent bones are done first.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!