source file REDAnimationClip.h

Go to the documentation of this file.

#ifndef RED_ANIMATION_CLIP_H
#define RED_ANIMATION_CLIP_H

//******************************************************************************
// Copyright (c) 2005 Redway. All rights reserved.
//
// Redway3d is a registered trademark. Any reproduction and / or utilization
// of any material from this document without Redway?s express authorization
// are prohibited.
//******************************************************************************

#include "RED.h"
#include "REDObject.h"
#include "REDSTL.h"
#include "REDAnimationData.h"


namespace RED
{
  class REDFullExp AnimationClip : public RED::Object
  {
    public:

      // Typing information:
      // -------------------
      
      SET_CID( CID_class_REDAnimationClip ); IMPLEMENT_AS();


      // Constructors:
      // -------------
      
      AnimationClip();


      ~AnimationClip();


      // Accessors:
      // ----------

      inline double GetDuration() const;

      
      inline unsigned int GetChannelsCount() const;


      RED_RC GetKeysCount( unsigned int& oKeysCount,
                           unsigned int  iChannel = 0 ) const;


      RED_RC GetKeyTime( double&      oTime,
                         unsigned int iKey,
                         unsigned int iChannel = 0 ) const;


      RED_RC GetKeyData( const RED::AnimationData*& oData,
                         unsigned int               iKey,
                         unsigned int               iChannel = 0 ) const;


      // Operations:
      // -----------

      RED_RC Interpolate( RED::Vector< RED::AnimationData >& oOutput, 
                          double                             iTime ) const;


      RED_RC InterpolateChannel( RED::AnimationData& oOutput,
                                 unsigned int        iChannel,
                                 double              iTime ) const;


      // Construction methods:
      // ---------------------

      RED_RC CreateChannels( unsigned int iChannelsCount );

      
      RED_RC AddKey( const RED::AnimationData& iKeyData,
                     double                    iTime,
                     unsigned int              iChannel = 0 );

    protected:
    
      // Animation clip types:
      // ---------------------

      struct AnimationKey
      {
        double _time;
        
        RED::AnimationData _data;

        AnimationKey();
      };

      
      struct AnimationChannel
      {
        RED::Vector< AnimationKey > _keys;
        
        double _duration;
        
        AnimationChannel();
      };


      RED_RC GetSurroundingKeys( const AnimationKey*& oKeyBefore, 
                                 const AnimationKey*& oKeyAfter,
                                 unsigned int         iChannel,
                                 double               iTime ) const;


      // Animation clip members:
      // -----------------------

      RED::Vector< AnimationChannel > _channels;

      double _duration;
  };
};


//******************************************************************************
//*** AnimationClip - inlined methods ******************************************
//******************************************************************************

inline double RED::AnimationClip::GetDuration() const
{
  return _duration;
}


inline unsigned int RED::AnimationClip::GetChannelsCount() const
{
  return (unsigned int)_channels.size();
}

#endif