Example #1
0
/*----------------------------------------------------------------------
  GetTranslation()
  Purpose: gets the translation 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 translation
  Out parameters:
    Tout  - the translation at time 
  Returns:
    TRUE if there was a translation with "name", else FALSE (and the
    translation is (0,0,0)
  Note: this routine does not check if the object is visible or not.
----------------------------------------------------------------------*/
int GetTranslation(Stack<Animation*> *al,char* name, double time, double Tout[3])
{
   Animation * a = FindAnimation(name,al);
   if(a)
   {
      _GetTranslation(a, time, Tout);
      return TRUE;
   }
   Tout[0]=Tout[1]=Tout[2]=0.0;
   return FALSE;
}
Example #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];
   }
}
Example #3
0
int GetTranslation(struct AnimationList *al, char* name, double time,
   double Tout[3])
{
   void* a = FindAnimation(name, al);
   Animation* anim = (Animation*) a;

   if(a)
   {
      _GetTranslation(anim, time, Tout);
      return TRUE;
   }

   Tout[0] = Tout[1] = Tout[2] = 0.0;

   return FALSE;
}
Example #4
0
/*----------------------------------------------------------------------
  GetCamera()
  Purpose: to get the position, the view direction and the up vector
     of the camera if it is animated. The name of the animation for
     the camera is "camera".
  In parameters:
    al   - the linked list of Animations
    time - the time of the wanted transformation
  Out parameters:
    gotPosition - by the end of the call, this will be 1 if there was a
                  position for the camera, else 0
    viewPos - the camera position (only set if gotPosition returns 1) 
    gotDirection - by the end of the call, this will be 1 if there was a
                  view direction and up vector for the camera, else 0
    viewDir - the camera direction (only set if gotDirection returns 1) 
    viewUp - the camera up vector (only set if gotDirection returns 1) 
  Returns:
    void
----------------------------------------------------------------------*/
void GetCamera(Stack<Animation*> *al,double time,
	       int *gotPosition,double viewPos[3],
	       int *gotDirection, double viewDir[3], double viewUp[3])
{
   Animation *a;
   /* is there an animation called "camera", then use it to animate the camera */
   a=FindAnimation("camera",al);
   if(a)
   {
      double m[4][4];
      
      /* get position of the camera, if any */
      if(a->translations)
      {
	 _GetTranslation(a,time,viewPos);
	 *gotPosition=1;
      }
      else *gotPosition=0;

      /* get view direction and up vector, if any */
      if(a->rotations)
      {
	 /* get matrix (we use only the upper 3x3 matrix to extract dir, and up */
	 _GetMatrix(a,time,m);
	 
	 /* the viewer looks along the negative z-axis, with the y-axis up */
	 viewDir[0]=-m[0][2];
	 viewDir[1]=-m[1][2];
	 viewDir[2]=-m[2][2];
	 
         /* the y-axis is up */
	 viewUp[0]=m[0][1];
	 viewUp[1]=m[1][1];
	 viewUp[2]=m[2][1];
	 
	 *gotDirection=1;
      }  
      else *gotDirection=0;
   }
   else
   {
      /* we did not find any position nor a direction */
      *gotPosition=0;
      *gotDirection=0;
   }
   
}
Example #5
0
void GetCamera(struct AnimationList *al, double time, int *gotPosition,
   double viewPos[3], int *gotDirection, double viewDir[3],
   double viewUp[3])
{
   /* If there is an animation called "camera", then use it to animate
    * the camera. */
   
   Animation *a;
   
   char *animName = new char[7];
   strcpy(animName, "camera");
   
   a = FindAnimation(animName, al);
   Animation* anim = (Animation*) a;
   
   delete[] animName;
   
   if(a)
   {
      double m[4][4];
      
      /* Get position of the camera, if there is any. */
      if(a->translations)
      {
         _GetTranslation(anim, time, viewPos);
         *gotPosition = 1;
      }
      else
      {
         *gotPosition = 0;
      }

      /* Get view direction and up vector, if there is any. */
      if(anim->rotations)
      {
         /* Get matrix (we use only the upper 3x3 cells of the matrix to
          * extract dir, and up). */
         _GetMatrix(anim, time, m);
         
         /* The viewer looks along the negative z-axis, with the y-axis
          * up. */
         viewDir[0] = -m[0][2];
         viewDir[1] = -m[1][2];
         viewDir[2] = -m[2][2];
	 
         /* The y-axis is up. */
         viewUp[0] = m[0][1];
         viewUp[1] = m[1][1];
         viewUp[2] = m[2][1];
	 
         *gotDirection=1;
      }  
      else
      {
         *gotDirection=0;
      }
   }
   else
   {
      /* We did not find any position nor a direction. */
      *gotPosition = 0;
      *gotDirection = 0;
   }
}