Beispiel #1
0
int GetMatrix(struct AnimationList *al, char* name, double time,
   double m[4][4])
{
   int x, y;
   void* a = FindAnimation(name, al);
   Animation* anim = (Animation*) a;

   if(a)
   {
      _GetMatrix(anim, time, m);
      return TRUE;
   }
   
   /* Otherwise, return identity matrix. */
   for(x = 0; x < 4; x++)
   {
      for(y = 0; y < 4; y++)
      {
         if(x == y)
         {
            m[x][y] = 1.0;
         }
         else
         {
            m[x][y] = 0.0;
         }
      }
   }
   return FALSE;
}
Beispiel #2
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;
   }
   
}
Beispiel #3
0
/*----------------------------------------------------------------------
  GetMatrix()
  Purpose: gets the full matrix( including scaling, rotation, and 
    translation) of an animated object with a certain name
    This function can be used instead calling GetScale, GetRotation,
    and GetTranslation and then concatenate these transforms.
  In parameters:
    al   - the linked list of Animations
    name - the name of the Animation
    time - the time of the wanted transformation
  Out parameters:
    m  - the matrix at time, the matrix is of column major form,
         i.e., the translation is in the right most column of the matrix
         So, in order to use it with OpenGl, you have to transpose the
         matrix.
  Returns:
    TRUE if we could find an animation with "name", else FALSE, and
    the matrix will be an identity matrix
  Note: this routine does not check if the object is visible or not.
----------------------------------------------------------------------*/
int GetMatrix(Stack<Animation*> *al,char* name, double time, double m[4][4])
{
   int x,y;
   Animation * a = FindAnimation(name,al);
   if(a)
   {
      _GetMatrix(a, time, m);
      return TRUE;
   }
   /* return identity matrix */
   for(x=0;x<4;x++)
   {
      for(y=0;y<4;y++)
      {
	 if(x==y) m[x][y]=1.0;
	 else m[x][y]=0.0;
      }
   }
   return FALSE;
}
Beispiel #4
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;
   }
}