gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Quaternion to matrix problem [SOLVED]

#166033 - Marcel24 - Sat Jan 17, 2009 5:21 pm

Hi,currently i try to convert a Quaternion to 4x4 videoGL matrix
and multiply it my the current hardware matrix.

I need this for interpolation key frames (rotations and positions)

But it doesnt work :(

Maybe somebody can help me ?

If i convert the result of QuatSlerpFixed to axis angle then
it works right.
but its damm slow:(

tnx for help..


:( i forgot to swap the z,y parameter from the quat
i wrote a exporter for 3dstudio max
and forgot it.
now it works :)
tnx

Code:



#define DELTA 0.001

inline void C3DNode::QuatSlerpFixed(QUATNDS * from, QUATNDS * to, int32 t,QUATNDS * res)
      {
      int32           to1Fixed[4];
      int32      cosomFixed;
      int32      omegaFixed;
      int32      scale0Fixed;
      int32      scale1Fixed;
   
      cosomFixed =  mulf32(from->x, to->x) +
                 mulf32(from->y, to->y) +
                 mulf32(from->z, to->z) +
                 mulf32(from->w, to->w);

      

      // adjust signs (if necessary)
        if ( cosomFixed < floattof32(0.0) )
      {
        cosomFixed = -cosomFixed;
        to1Fixed[0] = - to->x;
        to1Fixed[1] = - to->y;
        to1Fixed[2] = - to->z;
        to1Fixed[3] = - to->w;
        }
      else 
      {
         to1Fixed[0] = to->x;
        to1Fixed[1] = to->y;
        to1Fixed[2] = to->z;
        to1Fixed[3] = to->w;
        }

        // calculate coefficients
       scale0Fixed = floattof32(1.0) - t;
        scale1Fixed = t;

   // calculate final values

   res->x = mulf32(scale0Fixed,from->x) + mulf32(scale1Fixed,to1Fixed[0]);
   res->y = mulf32(scale0Fixed,from->y) + mulf32(scale1Fixed,to1Fixed[1]);
   res->z = mulf32(scale0Fixed,from->z) + mulf32(scale1Fixed,to1Fixed[2]);
   res->w = mulf32(scale0Fixed,from->w) + mulf32(scale1Fixed,to1Fixed[3]);
}

inline void C3DNode::LinearInterpolate(FASTPOS *from , FASTPOS *to , FASTPOS *res, int32 t)
{
   int32 tmp1 = inttof32(1) - t;
   
   res->x = (mulf32(from->x,tmp1) + mulf32(to->x,t));
   res->y = (mulf32(from->y,tmp1) + mulf32(to->y,t));
   res->z = (mulf32(from->z,tmp1) + mulf32(to->z,t));
}


// In render function
FASTPOS posRes;
      QUATNDS resQuat;
      AXIS_ROT_NDS axisRot;

      LinearInterpolate(&pNode->pPosAnimation->pPosValues[m_iCurKeyFrame],
                    &pNode->pPosAnimation->pPosValues[m_iCurKeyFrame+1],
                    &posRes,m_fixedSplineTime);
      
      glTranslate3f32(posRes.x,posRes.y,posRes.z);

      
      QuatSlerpFixed(&pNode->pPosAnimation->pRotValues[m_iCurKeyFrame],
              &pNode->pPosAnimation->pRotValues[m_iCurKeyFrame + 1], m_fixedSplineTime,&resQuat);
   
      m4x4 matrix;
      
      QuatToMatrixFixed(&resQuat,&matrix,&posRes);
      
      glMultMatrix4x4(&matrix);