Problems with skeletal animation, chaotic movements

Started by
4 comments, last by superpig 17 years, 11 months ago
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.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);	
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  gl.glLoadIdentity();
  glu.gluLookAt(-70,75,350, 15,75,0, 0,1,0);
  gl.glRotatef(90,0,1,0);
  gl.glRotatef(270,1,0,0);
  gl.glRotatef(a,0,0,1);
  a++;
  gl.glPushMatrix();
  object.CurFrame++;
  if(object.CurFrame>object.MaxFrame)
      object.CurFrame = object.MinFrame;
           
  object.CalcAnimCoords(object.CurFrame);
            
  object.SumFrame++;
  object.render();

  gl.glPopMatrix();
}

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];
                    else 
                        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;
            }
        }
        
    }
Advertisement
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?
It would be helpful to see the CalculationBone() function.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

    /**     * 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         if(bone.parent_bone_id<0)            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;                        if(IsHelper)        {            bone = CalcAbsolute(frame, helper[bone.parent_bone_id-helper[0].object_id], bone);        }        else         {             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();        if(!Child.IsBillboarded)            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;    }
It is a code look, please, and prompt in what there can be a mistake.
http://juds.dev.juga.ru/mdlload.jar
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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement