Пример #1
0
/*----------------------------------------------------------------------
  GetRotation()
  Purpose: gets the rotation of an animated object with a certain name
  In parameters:
    al   - the linked list of Animations
    name - the name of the Animation
    time - the time of the wanted rotation
  Out parameters:
    Rout  - the rotation at time. (Rout[0],Rout[1],Rout[2]) is the 
            rotation axis, and Rout[3] is the rotation angle (in radians)
            about that axis
  Returns:
    TRUE if there was a rotation with "name", else FALSE (and the
    axis is (1,0,0) and the angle is 0.0
  Note: this routine does not check if the object is visible or not.
----------------------------------------------------------------------*/
int GetRotation(Stack<Animation*> *al,char* name, double time, double Rout[4])
{
  Animation* a = FindAnimation(name,al);
  if(a)
  {
     _GetRotation(a, time, Rout);
     return TRUE;
  }
  Rout[0]=1.0; Rout[1]=0.0; Rout[2]=0.0; Rout[3]=0.0;
  return FALSE;
}
Пример #2
0
void _GetMatrix(Animation* animation, double time, double m[4][4])
{
   Animation* a = (Animation*) animation;
   
   /* m = translation * rotation * scale */
   
   /* Rotation. */
   if(a->rotations)
   {
      double drot[4];
      _GetRotation(a, time, drot);
      
      Rotation3 RR;
      RR.x = drot[0];
      RR.y = drot[1];
      RR.z = drot[2];
      RR.angle = drot[3];
      
      Quaternion q;
      FromAngleAxis(&q, RR.angle, RR.x, RR.y, RR.z);
      QuatToMatrix(&q, m); /* Also sets bottom row to 0 0 0 1 */
   }
   else
   {
      m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0;
      m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0;
      m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0;
      m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
   }

   /* Concatenate with scaling. */
   if(a->scales)
   {
      double S[3];
      _GetScale(a, time, S);

      m[0][0] *= S[0]; m[0][1] *= S[1]; m[0][2] *= S[2];
      m[1][0] *= S[0]; m[1][1] *= S[1]; m[1][2] *= S[2];
      m[2][0] *= S[0]; m[2][1] *= S[1]; m[2][2] *= S[2];
   }

   /* Translation. */
   if(a->translations)  
   {
      double P[3];
      _GetTranslation(a, time, P);
      
      m[0][3] = P[0];
      m[1][3] = P[1];
      m[2][3] = P[2];
   }
}
Пример #3
0
int GetRotation(struct AnimationList *al, char* name, double time,
   double Rout[4])
{
   void* a = FindAnimation(name, al);
   Animation* anim = (Animation*) a;

   if(a)
   {
     _GetRotation(anim, time, Rout);
     return TRUE;
   }

   Rout[0] = 1.0;
   Rout[1] = 0.0;
   Rout[2] = 0.0;
   Rout[3] = 0.0;

   return FALSE;
}