AREA forums upgrade
Read more about the planned upgrade of our forums
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / SDK / Bones and Biped Matrix on translation
IMPORTANT ANNOUNCEMENT ABOUT AREA FORUMS
  RSS 2.0 ATOM  

Bones and Biped Matrix on translation
Rate this thread
 
65050
 
Permlink of this thread  
avatar
  • arkeon
  • Posted: 07 March 2012 06:29 AM
  • Total Posts: 5
  • Joined: 24 February 2012 06:32 AM

Hello,

I still working on a ogre export and I saw some strange effects on bone translations.
I get correct bone Orientation but with the same matrix I get a translation reverted on some axes depending of the parent bone.
Should I use a different matrix for translations ?

Here my code.

matrix manipulation code :

inline Matrix3 UniformMatrix(Matrix3 orig_cur_matbool yUp)
{
  AffineParts   parts
;
  
Matrix3       mat;

  
Matrix3 YtoZ;
  
Matrix3 ZtoY;

  
GMatrix gmat;
  
gmat.SetRow(0Point4(1,  000));
  
gmat.SetRow(1Point4(0,  010));
  
gmat.SetRow(2Point4(0, -100));
  
gmat.SetRow(3Point4(0,  001));
  
YtoZ gmat.ExtractMatrix3();
  
ZtoY Inverse(YtoZ);

///Remove  scaling  from orig_cur_mat
//1) Decompose original and get decomposition info
  
decomp_affine(orig_cur_mat, &parts); 

//2) construct 3x3 rotation from quaternion parts.q
  
parts.q.MakeMatrix(mat);

//3) construct position row from translation parts.t  
  
mat.SetRow(3,  parts.t);

  if (
yUp)
    
mat YtoZ mat ZtoY;

 return(
mat);
}

inline Matrix3 GetRelativeUniformMatrix
(Matrix3 mat1Matrix3 mat2bool yUp)
{          
  Matrix3 dest_mat
;
  
  
//Decompose each matrix
  
Matrix3 cur_mat UniformMatrix(mat1yUp);
  
Matrix3 par_mat UniformMatrix(mat2yUp);
 
  
//then return relative matrix in coordinate space of parent
  
dest_mat cur_mat Inverse(par_mat);

  return 
dest_mat;
}

Now get the initial bone matrix

// Get mesh matrix at initial pose
    
ISkinpskin = (ISkin*)m_pGameSkin->GetMaxModifier()->GetInterface(I_SKIN);

    
GMatrix GSkinTM;
    
m_pGameSkin->GetInitSkinTM(GSkinTM);
    
Matrix3 SkinTM GSkinTM.ExtractMatrix3();

    
Matrix3 boneTM;
    
Matrix3 ParentTM;

    if(
pskin->GetBoneInitTM(pNodeboneTMfalse) == SKIN_INVALID_NODE_PTR)
      
boneTM pNode->GetNodeTM(firstFrame);

    if(
pskin->GetBoneInitTM(pNodeParentParentTMfalse) == SKIN_INVALID_NODE_PTR)
      
ParentTM pNodeParent->GetNodeTM(firstFrame);

    
Matrix3 localTM;
    if(
parentIdx >= 0)
    
{
      localTM 
GetRelativeUniformMatrix(boneTMParentTMm_params.yUpAxis);
    
}
    
else // for root bone use the mesh
    
{
      localTM 
GetRelativeUniformMatrix(boneTMParentTMm_params.yUpAxis) * Inverse(SkinTM);
    
}
    
    m_joints[boneIndex]
.bindMatrix localTM;

And now getting the relative matrix by time

INodebone j.pNode;
    
    
// Get the bone local matrix for this key
    
Matrix3 boneTM GetRelativeUniformMatrix(bonetimem_params.yUpAxis);

    
GMatrix GSkinTM;
    
m_pGameSkin->GetInitSkinTM(GSkinTM);
    
Matrix3 SkinTM GSkinTM.ExtractMatrix3();

    
// for root bone use the mesh
    
if(j.parentIndex 0)
      
boneTM boneTM Inverse(SkinTM);

    
Matrix3 relMat boneTM Inverse(j.bindMatrix);

    
AffineParts ap;
    
decomp_affine(relMat, &ap);

    
Point3 trans ap.m_params.lum;
    
Point3 scale ap.k;
    
Quat rot ap.q;
    
// Notice that in Max we flip the w-component of the quaternion;
    
rot.= -rot.w;

    
//create keyframe
    
skeletonKeyframe key;
    
key.time 0;

    
// don't know why root translation are Z X reverted
    // what matrix should I use for translations ?
    
if(IsBipedRoot(bone))
    
{
      key
.trans.= -trans.z;
      
key.trans.trans.y;
      
key.trans.trans.x;
    
}
    
else if(IsBipedRoot(bone->GetParentNode()))
    
{
      key
.trans.trans.x;
      
key.trans.= -trans.z;
      
key.trans.trans.y;
    
}
    
else
    
{
      key
.trans.trans.z;
      
key.trans.trans.x;
      
key.trans.trans.y;
    
}

  key
.rot rot;
  
key.scale scale;
  return 
key;

So as you can see I use a strange hack to get the correct translation in some cases…



Replies: 0
avatar
  • arkeon
  • Posted: 11 April 2012 04:32 AM

Up ^^ ?!

I still have the issue for the bones translations :/
Any clue ?



Replies: 0