Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4597 in orxonox.OLD for orxonox/trunk/src/util/animation


Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

Location:
orxonox/trunk/src/util/animation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/animation/animation.cc

    r3988 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2222/**
    2323   \brief creates a new Animation
    24    
     24
    2525   This also adds the Animation automatically to the AnimationPlayer's list
    2626*/
    2727Animation::Animation(void)
    28 
     28{
     29  this->setClassID(CL_ANIMATION, "Animation");
     30
    2931  // initialize a beginning KeyFrame, that will be deleted afterwards
    3032  this->keyFrameCount = 0;
     
    4345/**
    4446   \brief destructs the Animation
    45    
     47
    4648   this also takes the animation out of the AnimationPlayer's list (if it is there)
    4749*/
     
    5456   \brief tells the AnimationPlayer, that we do not wish to  handle this animation
    5557   automatically.
    56    
     58
    5759   This means that it will not be ticked, and not be deleted with the AnimationPlayer
    5860*/
  • orxonox/trunk/src/util/animation/animation.h

    r4485 r4597  
    1 /*! 
     1/*!
    22    \file animation.h
    33    A Subclass for all animations in orxonox
     
    3131   deprecated QUADRATIC
    3232*/
    33 typedef enum ANIM_FUNCTION {ANIM_CONSTANT,
    34                             ANIM_LINEAR,
    35                             ANIM_SINE,
    36                             ANIM_COSINE,
    37                             ANIM_EXP,
    38                             ANIM_NEG_EXP,
    39                             ANIM_QUADRATIC,
    40                             ANIM_RANDOM,
    41                             ANIM_NULL};
     33typedef enum ANIM_FUNCTION
     34{
     35  ANIM_CONSTANT,
     36  ANIM_LINEAR,
     37  ANIM_SINE,
     38  ANIM_COSINE,
     39  ANIM_EXP,
     40  ANIM_NEG_EXP,
     41  ANIM_QUADRATIC,
     42  ANIM_RANDOM,
     43  ANIM_NULL
     44};
     45
    4246#define ANIM_DEFAULT_FUNCTION ANIM_LINEAR      //!< A default function to choose from the above set
    4347
     
    4953   ANIM_INF_DELETE deletes the animation. !! THIS IS DANGEROUS !! only do this with non-class variables
    5054*/
    51 typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT,
    52                             ANIM_INF_REPLAY,
    53                             ANIM_INF_REWIND,
    54                             ANIM_INF_DELETE};//, ANIM_INF_LINEAR, ANIM_INF_PINGPONG;
     55typedef enum ANIM_INFINITY
     56{
     57  ANIM_INF_CONSTANT,
     58  ANIM_INF_REPLAY,
     59  ANIM_INF_REWIND,
     60  ANIM_INF_DELETE
     61}; //, ANIM_INF_LINEAR, ANIM_INF_PINGPONG};
    5562
    5663//! A Superclass for describing an animation (all animations will be derived from this one)
    5764/** implement in subclasses:
    58  * 
     65 *
    5966 * De-/Constructor
    6067 * Animation Functions
     
    6572 * virtual rewind, to go to the first Keyframe. (other functions will call this one)
    6673*/
    67 class Animation
     74class Animation : public BaseObject
    6875{
    6976 public:
  • orxonox/trunk/src/util/animation/animation3d.cc

    r4485 r4597  
    5151/**
    5252   \brief standard deconstructor
    53    
     53
    5454   deletes all the Keyframes
    5555*/
     
    8989*/
    9090void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration,
    91                               ANIM_FUNCTION animFuncMov, ANIM_FUNCTION animFuncRot)
     91                              ANIM_FUNCTION animFuncMov, ANIM_FUNCTION animFuncRot)
    9292{
    9393  // some small check
     
    101101
    102102  KeyFrame3D* tmpKeyFrame;
    103    
     103
    104104  // when adding the first frame
    105105  if (this->keyFrameCount == 0)
     
    114114      // when adding the second frame
    115115      if (this->currentKeyFrame == this->nextKeyFrame)
    116         this->nextKeyFrame = tmpKeyFrame;
     116        this->nextKeyFrame = tmpKeyFrame;
    117117      this->keyFrameList->add(tmpKeyFrame);
    118118    }
     
    136136{
    137137  if (this->bRunning)
    138     { 
     138    {
    139139      this->localTime += dt;
    140140      if (localTime >= this->currentKeyFrame->duration)
    141         {
    142           if (likely(this->keyFramesToPlay != 0))
    143             {
    144               if (unlikely(this->keyFramesToPlay > 0))
    145                 --this->keyFramesToPlay;
    146               // switching to the next Key-Frame
    147               this->localTime -= this->currentKeyFrame->duration;
    148               this->currentKeyFrame = this->nextKeyFrame;
    149               // checking, if we should still Play the animation
    150               if (this->currentKeyFrame == this->keyFrameList->lastElement())
    151                 this->handleInfinity();
    152               this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    153               this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
    154               this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
    155             }
    156           else
    157             this->pause();
    158         }     
     141        {
     142          if (likely(this->keyFramesToPlay != 0))
     143            {
     144              if (unlikely(this->keyFramesToPlay > 0))
     145                --this->keyFramesToPlay;
     146              // switching to the next Key-Frame
     147              this->localTime -= this->currentKeyFrame->duration;
     148              this->currentKeyFrame = this->nextKeyFrame;
     149              // checking, if we should still Play the animation
     150              if (this->currentKeyFrame == this->keyFrameList->lastElement())
     151                this->handleInfinity();
     152              this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
     153              this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
     154              this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
     155            }
     156          else
     157            this->pause();
     158        }
    159159      /* now animate it */
    160160      (this->*animFuncMov)(this->localTime);
     
    257257  else
    258258    v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (2.0 + sin( M_PI * (- timePassed /this->currentKeyFrame->duration)) )/ 2.0;
    259  
     259
    260260  this->object->shiftCoor(v - this->currentKeyFrame->lastPosition);
    261261  this->currentKeyFrame->lastPosition = v;
     
    279279  /*
    280280  this->object->setRelCoor( this->nextKeyFrame->position -
    281                             (this->nextKeyFrame->position - this->currentKeyFrame->position) *
    282                             (1.0 + cos( M_PI * timePassed / this->currentKeyFrame->duration))/2.0);
     281                            (this->nextKeyFrame->position - this->currentKeyFrame->position) *
     282                            (1.0 + cos( M_PI * timePassed / this->currentKeyFrame->duration))/2.0);
    283283  */
    284284}
     
    309309  /*
    310310  this->object->setRelCoor( this->currentKeyFrame->position +
    311                             (this->nextKeyFrame->position - this->currentKeyFrame->position) *
    312                             (1.0 - expf(- timePassed * expFactorMov)) );
     311                            (this->nextKeyFrame->position - this->currentKeyFrame->position) *
     312                            (1.0 - expf(- timePassed * expFactorMov)) );
    313313  */
    314314}
     
    334334{
    335335  /*
    336   this->object->setRelCoor(this->currentKeyFrame->position + 
    337                            (this->nextKeyFrame->position - this->currentKeyFrame->position) * (float)rand()/(float)RAND_MAX);
     336  this->object->setRelCoor(this->currentKeyFrame->position +
     337                           (this->nextKeyFrame->position - this->currentKeyFrame->position) * (float)rand()/(float)RAND_MAX);
    338338  this->object->setRelDir(this->currentKeyFrame->direction +
    339                           (this->nextKeyFrame->direction - this->currentKeyFrame->direction)* (float)rand()/(float)RAND_MAX);
     339                          (this->nextKeyFrame->direction - this->currentKeyFrame->direction)* (float)rand()/(float)RAND_MAX);
    340340  */
    341341}
     
    401401void Animation3D::rLinear(float timePassed) const
    402402{
    403   this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 
    404                                      this->currentKeyFrame->direction,
    405                                      timePassed/this->currentKeyFrame->duration) );
     403  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     404                                     this->currentKeyFrame->direction,
     405                                     timePassed/this->currentKeyFrame->duration) );
    406406}
    407407
     
    420420    scale = 1.0 - sin( M_PI * timePassed / this->currentKeyFrame->duration);
    421421
    422   this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 
    423                                      this->currentKeyFrame->direction,
    424                                      scale) );
     422  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     423                                     this->currentKeyFrame->direction,
     424                                     scale) );
    425425}
    426426
     
    435435{
    436436  float scale = cos(M_PI * timePassed / this->currentKeyFrame->duration);
    437   this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 
    438                                      this->currentKeyFrame->direction,
    439                                      scale) );
     437  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     438                                     this->currentKeyFrame->direction,
     439                                     scale) );
    440440}
    441441
     
    458458{
    459459  float scale = (1.0 - expf(- timePassed * expFactorRot));
    460   this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 
    461                                      this->currentKeyFrame->direction,
    462                                      scale) );
     460  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     461                                     this->currentKeyFrame->direction,
     462                                     scale) );
    463463}
    464464
  • orxonox/trunk/src/util/animation/animation3d.h

    r4485 r4597  
    1 /*! 
     1/*!
    22    \file animation3d.h
    33*/
     
    3333  Animation3D(PNode* object);
    3434  virtual ~Animation3D(void);
    35    
     35
    3636  virtual void rewind(void);
    3737
     
    4040
    4141  virtual void tick(float dt);
    42  
     42
    4343 private:
    4444  // animation functions
  • orxonox/trunk/src/util/animation/animation_player.cc

    r4485 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2626   \brief standard constructor
    2727*/
    28 AnimationPlayer::AnimationPlayer () 
     28AnimationPlayer::AnimationPlayer ()
    2929{
    30    this->setClassID(CL_ANIMATION_PLAYER, "AnimationPlayer");
     30  this->setClassID(CL_ANIMATION_PLAYER, "AnimationPlayer");
     31  this->setName("AnimationPlayer");
    3132
    32    this->animationList = new tList<Animation>();
    33    this->play();
     33  this->animationList = new tList<Animation>();
     34  this->play();
    3435}
    3536
     
    4344
    4445   !! DANGER !! when unloading the AnimationPlayer no other Function
    45    should reference any Animations, from the animationList because it 
    46    automatically deletes them. 
     46   should reference any Animations, from the animationList because it
     47   automatically deletes them.
    4748   This usually happens when unloading a World.
    4849*/
    49 AnimationPlayer::~AnimationPlayer () 
     50AnimationPlayer::~AnimationPlayer ()
    5051{
    5152  // deleting the Animation List AND all the elements of the List
     
    6162
    6263   when adding a Animation the Animation will too be deleted when
    63    the AnimationPlayer gets deleted. Consider not adding it, or 
     64   the AnimationPlayer gets deleted. Consider not adding it, or
    6465   unadding it with animation->notHandled();
    6566*/
     
    8081/**
    8182   \brief empties the list AND deletes all the Animations
    82 */ 
     83*/
    8384void AnimationPlayer::flush(void)
    8485{
     
    99100
    100101/**
    101    \brief Ticks all the animations in animationList 
     102   \brief Ticks all the animations in animationList
    102103   \param timePassed the time passed since the last tick.
    103104*/
     
    110111      Animation* anim = animIt->nextElement();
    111112      while( anim != NULL)
    112         {
    113           anim->tick(timePassed);
    114           if(unlikely(anim->ifDelete()))
    115           {
    116             this->animationList->remove(anim);
    117             delete anim;
    118           }
    119           anim = animIt->nextElement();
    120         }
     113        {
     114          anim->tick(timePassed);
     115          if(unlikely(anim->ifDelete()))
     116          {
     117            this->animationList->remove(anim);
     118            delete anim;
     119          }
     120          anim = animIt->nextElement();
     121        }
    121122      delete animIt;
    122123    }
     
    150151    {
    151152      if(anim->getBaseObject() == baseObject)
    152         {
    153           delete animIt;
    154           return anim;
    155         }
     153        {
     154          delete animIt;
     155          return anim;
     156        }
    156157      anim = animIt->nextElement();
    157158    }
  • orxonox/trunk/src/util/animation/animation_player.h

    r4485 r4597  
    1 /*! 
     1/*!
    22    \file animation_player.h
    33*/
     
    1515   <b>AnimationPlayer usage:</b> \n
    1616
    17    <b>Initialisation</b>: AnimationPlayer::getInstance() does the trick this is 
     17   <b>Initialisation</b>: AnimationPlayer::getInstance() does the trick this is
    1818   usually done when initializing a world \n
    1919   <b>Adding Animations</b>: create an Animation the following Way:
     
    2121   \li set some parameters: also see the specific classes for more info
    2222   \n
    23    if you do not want a specific Animation to be handled by the AnimationPlayer, you have to 
     23   if you do not want a specific Animation to be handled by the AnimationPlayer, you have to
    2424   unload it explicitely with animation->doNotHandle();
    2525   \n
  • orxonox/trunk/src/util/animation/t_animation.h

    r3982 r4597  
    1414*/
    1515
    16 /*! 
     16/*!
    1717    \file t_animation.h
    1818*/
     
    8080*/
    8181template<class T>
    82 tAnimation<T>::tAnimation (T* object, void (T::*funcToAnim)(float)) 
     82tAnimation<T>::tAnimation (T* object, void (T::*funcToAnim)(float))
    8383{
    8484  // create a new List
     
    100100/**
    101101   \brief standard deconstructor
    102    
     102
    103103   deletes all the Keyframes
    104104*/
    105105template<class T>
    106 tAnimation<T>::~tAnimation () 
     106tAnimation<T>::~tAnimation ()
    107107{
    108108  // delete all the KeyFrames
     
    158158
    159159  KeyFrameF* tmpKeyFrame;
    160    
     160
    161161  // when adding the first frame
    162162  if (this->keyFrameCount == 0)
     
    170170      // when adding the second frame
    171171      if (this->currentKeyFrame == this->nextKeyFrame)
    172         this->nextKeyFrame = tmpKeyFrame;
     172        this->nextKeyFrame = tmpKeyFrame;
    173173      this->keyFrameList->add(tmpKeyFrame);
    174174    }
     
    191191      this->localTime += dt;
    192192      if (localTime >= this->currentKeyFrame->duration)
    193         {
    194           if (likely(this->keyFramesToPlay != 0))
    195             {
    196               if (unlikely(this->keyFramesToPlay > 0))
    197                 --this->keyFramesToPlay;
    198               // switching to the next Key-Frame
    199               this->localTime -= this->currentKeyFrame->duration;
    200              
    201               this->currentKeyFrame = this->nextKeyFrame;
    202               // checking, if we should still Play the animation
    203               if (this->currentKeyFrame == this->keyFrameList->lastElement())
    204                 this->handleInfinity();
    205               this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    206              
    207               printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);
    208               this->setAnimFunc(this->currentKeyFrame->animFunc);         
    209             }
    210           else
    211             this->pause();
    212         }
    213      
     193        {
     194          if (likely(this->keyFramesToPlay != 0))
     195            {
     196              if (unlikely(this->keyFramesToPlay > 0))
     197                --this->keyFramesToPlay;
     198              // switching to the next Key-Frame
     199              this->localTime -= this->currentKeyFrame->duration;
     200
     201              this->currentKeyFrame = this->nextKeyFrame;
     202              // checking, if we should still Play the animation
     203              if (this->currentKeyFrame == this->keyFrameList->lastElement())
     204                this->handleInfinity();
     205              this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
     206
     207              printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);
     208              this->setAnimFunc(this->currentKeyFrame->animFunc);
     209            }
     210          else
     211            this->pause();
     212        }
     213
    214214      (this->object->*(funcToAnim))((this->*animFunc)(this->localTime));
    215215    }
     
    243243    case ANIM_NEG_EXP:
    244244      {
    245         this->animFunc = &tAnimation<T>::negExp;
    246         expFactor =  - 1.0 / this->currentKeyFrame->duration * logf(DELTA_X);
    247         break;
     245        this->animFunc = &tAnimation<T>::negExp;
     246        expFactor =  - 1.0 / this->currentKeyFrame->duration * logf(DELTA_X);
     247        break;
    248248      }
    249249    case ANIM_QUADRATIC:
     
    273273*/
    274274template<class T>
    275 float tAnimation<T>::linear(float timePassed) const 
     275float tAnimation<T>::linear(float timePassed) const
    276276{
    277277  return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value)
     
    287287{
    288288  if (timePassed * 2.0 < this->currentKeyFrame->duration)
    289     return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) 
     289    return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value)
    290290      * sin( M_PI * timePassed / this->currentKeyFrame->duration)/2;
    291   else 
     291  else
    292292    return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value)
    293293      * sin( M_PI * (1.0 - timePassed / this->currentKeyFrame->duration))/2;
     
    350350float tAnimation<T>::random(float timePassed) const
    351351{
    352   return this->currentKeyFrame->value + 
     352  return this->currentKeyFrame->value +
    353353    (this->nextKeyFrame->value - this->currentKeyFrame->value) *
    354354    (float)rand()/(float)RAND_MAX;
Note: See TracChangeset for help on using the changeset viewer.