Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3795 in orxonox.OLD for orxonox/trunk/src/animation.cc


Ignore:
Timestamp:
Apr 13, 2005, 4:32:53 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: moved some functions around in the Animation-classes

File:
1 edited

Legend:

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

    r3794 r3795  
    2121
    2222Anim::Anim(void)
    23 {
    24   // create a new List
    25   this->keyFrameList = new tList<AnimKeyFrame>();
    26  
     23
    2724  // initialize a beginning KeyFrame, that will be deleted afterwards
    2825  this->bHasKeys = false;
    29   AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame;
    30   tmpKeyFrame->value = 0.0;
    31   tmpKeyFrame->duration = 1.0;
    32   keyFrameList->add(tmpKeyFrame);
    3326
    3427  // setting default values
    3528  this->localTime = 0.0;
    3629  this->bRunning = true;
    37   this->animFunc = &Anim::linear;
    38   this->currentKeyFrame = tmpKeyFrame;
    39   this->nextKeyFrame = tmpKeyFrame;
    4030}
    4131
     
    4333Anim::~Anim(void)
    4434{
    45   // delete all the KeyFrames
    46   tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator();
    47   AnimKeyFrame*  enumKF = itKF->nextElement();
    48   while (enumKF)
    49     {
    50       delete enumKF;
    51       enumKF = itKF->nextElement();
    52     }
    53   delete itKF;
    54   delete this->keyFrameList;
    55 }
    56 
    57 tList<Anim>* Anim::animatorList = NULL;
    58 
    59 
    60 void Anim::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc)
    61 {
    62   // some small check
    63   if (duration <= 0.0)
    64     duration = 1.0;
    65  
    66 
    67   AnimKeyFrame* tmpKeyFrame;
    68    
    69   if (bHasKeys)
    70     {
    71       tmpKeyFrame = new AnimKeyFrame;
    72       if (this->currentKeyFrame == this->nextKeyFrame)
    73         this->nextKeyFrame = tmpKeyFrame;
    74       this->keyFrameList->add(tmpKeyFrame);
    75 
    76     }
    77   else
    78     {
    79       tmpKeyFrame = this->keyFrameList->firstElement();
    80       bHasKeys = true;
    81     }
    82   tmpKeyFrame->value = value;
    83   tmpKeyFrame->duration = duration;
    84   tmpKeyFrame->animFunc = animFunc;
    85  
    8635}
    8736
     
    9039  this->postInfinity = postInfinity;
    9140}
    92 
    93 void Anim::setAnimFunc(ANIM_FUNCTION animFunc)
    94 {
    95   switch (animFunc)
    96     {
    97     default:
    98     case ANIM_CONSTANT:
    99       this->animFunc = &Anim::constant;
    100       break;
    101     case ANIM_LINEAR:
    102       this->animFunc = &Anim::linear;
    103       break;
    104     case ANIM_RANDOM:
    105       this->animFunc = &Anim::random;
    106       break;
    107     case ANIM_SINE:
    108       this->animFunc = &Anim::sine;
    109       break;
    110     }
    111 }
    112 
    113 
    114 // animation functions
    115 float Anim::random(float timePassed) const
    116 {
    117   return (float)rand()/(float)RAND_MAX;
    118 }
    119 
    120 float Anim::constant(float timePassed) const
    121 {
    122   return this->currentKeyFrame->value;
    123 }
    124 
    125 float Anim::linear(float timePassed) const
    126 {
    127   return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value)
    128     * (timePassed / this->currentKeyFrame->duration);
    129   //  PRINTF(0)("value is %f, %p %p\n", val, this->currentKeyFrame, this->nextKeyFrame);
    130   //  return val;
    131 }
    132 
    133 float Anim::sine(float timePassed) const
    134 {
    135  
    136 }
Note: See TracChangeset for help on using the changeset viewer.