Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3973 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Apr 26, 2005, 1:55:47 AM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: animation3d extended for definition of individual rotation function per keyFrame

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

Legend:

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

    r3971 r3973  
    4242  this->nextKeyFrame = tmpKeyFrame;
    4343
    44   this->animFunc = &Animation3D::linear;
     44  this->animFuncMov = &Animation3D::mLinear;
     45  this->animFuncRot = &Animation3D::rLinear;
    4546}
    4647
     
    7273  this->nextKeyFrame = keyFrameList->nextElement(keyFrameList->firstElement());
    7374  this->localTime = 0.0;
    74   this->setAnimFunc(this->currentKeyFrame->animFunc);
     75  this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
     76  this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
    7577}
    7678
     
    8284   \param animFunc The function to animate between this keyFrame and the next one
    8385*/
    84 void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration, ANIM_FUNCTION animFunc)
     86void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration, ANIM_FUNCTION animFuncMov, ANIM_FUNCTION animFuncRot)
    8587{
    8688  // some small check
     
    9496    {
    9597      tmpKeyFrame = this->keyFrameList->firstElement();
    96       this->setAnimFunc(animFunc);
     98      this->setAnimFuncMov(animFuncMov);
     99      this->setAnimFuncRot(animFuncRot);
    97100    }
    98101  else
     
    108111  tmpKeyFrame->direction = direction;
    109112  tmpKeyFrame->duration = duration;
    110   tmpKeyFrame->animFunc = animFunc;
     113  tmpKeyFrame->animFuncMov = animFuncMov;
     114  tmpKeyFrame->animFuncRot = animFuncRot;
    111115  this->keyFrameCount++;
    112116}
     117
     118
    113119
    114120/**
     
    130136            this->handleInfinity();
    131137          this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    132           this->setAnimFunc(this->currentKeyFrame->animFunc);     
     138          this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
     139          this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
    133140        }
    134141      /* now animate it */
    135       (this->*animFunc)(this->localTime);
    136     }
    137 }
    138 
    139 
    140 /**
    141    \brief Sets The kind of Animation between this keyframe and the next one
     142      (this->*animFuncMov)(this->localTime);
     143      (this->*animFuncRot)(this->localTime);
     144    }
     145}
     146
     147
     148/*==Movement Section==========================================================*/
     149
     150/**
     151   \brief Sets The kind of movment Animation between this keyframe and the next one
    142152   \param animFunc The Type of Animation to set
    143153*/
    144 void Animation3D::setAnimFunc(ANIM_FUNCTION animFunc)
    145 {
    146   switch (animFunc)
     154void Animation3D::setAnimFuncMov(ANIM_FUNCTION animFuncMov)
     155{
     156  switch (animFuncMov)
    147157    {
    148158    default:
    149159    case ANIM_CONSTANT:
    150       this->animFunc = &Animation3D::constant;
     160      this->animFuncMov = &Animation3D::mConstant;
    151161      break;
    152162    case ANIM_LINEAR:
    153       this->animFunc = &Animation3D::linear;
     163      this->animFuncMov = &Animation3D::mLinear;
    154164      break;
    155165    case ANIM_SINE:
    156       this->animFunc = &Animation3D::sine;
     166      this->animFuncMov = &Animation3D::mSine;
    157167      break;
    158168    case ANIM_COSINE:
    159       this->animFunc = &Animation3D::cosine;
     169      this->animFuncMov = &Animation3D::mCosine;
    160170      break;
    161171    case ANIM_EXP:
    162       this->animFunc = &Animation3D::exp;
     172      this->animFuncMov = &Animation3D::mExp;
    163173      break;
    164174    case ANIM_NEG_EXP:
    165       this->animFunc = &Animation3D::negExp;
     175      this->animFuncMov = &Animation3D::mNegExp;
    166176      this->expFactor = -1.0 / this->currentKeyFrame->duration * logf(DELTA_X_3D);
    167177      break;
    168178    case ANIM_QUADRATIC:
    169       this->animFunc = &Animation3D::quadratic;
     179      this->animFuncMov = &Animation3D::mQuadratic;
    170180      break;
    171181    case ANIM_RANDOM:
    172       this->animFunc = &Animation3D::random;
    173       break;
    174     }
    175 }
     182      this->animFuncMov = &Animation3D::mRandom;
     183      break;
     184    }
     185}
     186
     187
    176188
    177189/**
     
    179191   \param timePassed The time passed since this Keyframe began
    180192*/
    181 void Animation3D::constant(float timePassed) const
     193void Animation3D::mConstant(float timePassed) const
    182194{
    183195  this->object->setRelCoor(this->currentKeyFrame->position);
     
    197209   \todo implement also do this for direction
    198210*/
    199 void Animation3D::linear(float timePassed) const
     211void Animation3D::mLinear(float timePassed) const
    200212{
    201213  this->object->setRelCoor(this->currentKeyFrame->position +
     
    215227   \todo implement
    216228*/
    217 void Animation3D::sine(float timePassed) const
     229void Animation3D::mSine(float timePassed) const
    218230{
    219231  if( timePassed  < this->currentKeyFrame->duration/2.0)
     
    232244   \todo implement
    233245*/
    234 void Animation3D::cosine(float timePassed) const
     246void Animation3D::mCosine(float timePassed) const
    235247{
    236248  this->object->setRelCoor( this->nextKeyFrame->position -
     
    250262   \param timePassed The time passed since this Keyframe began
    251263*/
    252 void Animation3D::exp(float timePassed) const
     264void Animation3D::mExp(float timePassed) const
    253265{
    254266  PRINTF(0)("no exp animation3d defined\n");
    255   this->linear(timePassed);
     267  this->mLinear(timePassed);
    256268}
    257269
     
    260272   \param timePassed The time passed since this Keyframe began
    261273*/
    262 void Animation3D::negExp(float timePassed) const
     274void Animation3D::mNegExp(float timePassed) const
    263275{
    264276  this->object->setRelCoor( this->currentKeyFrame->position +
     
    274286   \todo implement
    275287*/
    276 void Animation3D::quadratic(float timePassed) const
     288void Animation3D::mQuadratic(float timePassed) const
    277289{
    278290  PRINTF(0)("no quadratic animation3d defined\n");
    279   this->linear(timePassed);
     291  this->mLinear(timePassed);
    280292}
    281293
     
    284296   \param timePassed The time passed since this Keyframe began
    285297*/
    286 void Animation3D::random(float timePassed) const
     298void Animation3D::mRandom(float timePassed) const
    287299{
    288300  this->object->setRelCoor(this->currentKeyFrame->position +
     
    291303                          (this->nextKeyFrame->direction - this->currentKeyFrame->direction)* (float)rand()/(float)RAND_MAX);
    292304}
     305
     306
     307/*==Rotation Section==========================================================*/
     308
     309
     310/**
     311   \brief Sets The kind of rotation Animation between this keyframe and the next one
     312   \param animFunc The Type of Animation to set
     313*/
     314void Animation3D::setAnimFuncRot(ANIM_FUNCTION animFuncRot)
     315{
     316  switch (animFuncRot)
     317    {
     318   default:
     319    case ANIM_CONSTANT:
     320      this->animFuncRot = &Animation3D::rConstant;
     321      break;
     322    case ANIM_LINEAR:
     323      this->animFuncRot = &Animation3D::rLinear;
     324      break;
     325    case ANIM_SINE:
     326      this->animFuncRot = &Animation3D::rSine;
     327      break;
     328    case ANIM_COSINE:
     329      this->animFuncRot = &Animation3D::rCosine;
     330      break;
     331    case ANIM_EXP:
     332      this->animFuncRot = &Animation3D::rExp;
     333      break;
     334    case ANIM_NEG_EXP:
     335      this->animFuncRot = &Animation3D::rNegExp;
     336      break;
     337    case ANIM_QUADRATIC:
     338      this->animFuncRot = &Animation3D::rQuadratic;
     339      break;
     340    case ANIM_RANDOM:
     341      this->animFuncRot = &Animation3D::rRandom;
     342      break;
     343    }
     344}
     345
     346
     347/**
     348   \brief stays at the value of the currentKeyFrame
     349   \param timePassed The time passed since this Keyframe began
     350*/
     351void Animation3D::rConstant(float timePassed) const
     352{
     353}
     354
     355/**
     356   \brief linear interpolation between this keyframe and the next one
     357   \param timePassed The time passed since this Keyframe began
     358
     359   \todo implement also do this for direction
     360*/
     361void Animation3D::rLinear(float timePassed) const
     362{
     363  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     364                                     this->currentKeyFrame->direction,
     365                                     timePassed/this->currentKeyFrame->duration) );
     366}
     367
     368/**
     369   \brief a Sinusodial Interpolation between this keyframe and the next one
     370   \param timePassed The time passed since this Keyframe began
     371
     372   \todo implement
     373*/
     374void Animation3D::rSine(float timePassed) const
     375{
     376}
     377
     378
     379/**
     380   \brief a cosine interpolation between this keyframe and the next one
     381   \param timePassed The time passed since this Keyframe began
     382
     383   \todo implement
     384*/
     385void Animation3D::rCosine(float timePassed) const
     386{
     387}
     388
     389
     390/*
     391 return ((this->nextKeyFrame->value + this->currentKeyFrame->value) +
     392    (this->currentKeyFrame->value - this->nextKeyFrame->value) *
     393    cos( M_PI * timePassed / this->currentKeyFrame->duration))/2;
     394*/
     395
     396/**
     397   \brief an exponential interpolation between this keyframe and the next one
     398   \param timePassed The time passed since this Keyframe began
     399*/
     400void Animation3D::rExp(float timePassed) const
     401{
     402
     403}
     404
     405/**
     406   \brief a negative exponential interpolation between this keyframe and the next one
     407   \param timePassed The time passed since this Keyframe began
     408*/
     409void Animation3D::rNegExp(float timePassed) const
     410{
     411}
     412
     413
     414/**
     415   \brief a quadratic interpolation between this keyframe and the next one
     416   \param timePassed The time passed since this Keyframe began
     417
     418   \todo implement
     419*/
     420void Animation3D::rQuadratic(float timePassed) const
     421{
     422}
     423
     424/**
     425   \brief some random animation (fluctuating)
     426   \param timePassed The time passed since this Keyframe began
     427*/
     428void Animation3D::rRandom(float timePassed) const
     429{
     430}
  • orxonox/trunk/src/util/animation/animation3d.h

    r3964 r3973  
    1919  Vector position;                  //!< The position of this KeyFrame
    2020  Quaternion direction;             //!< The direction of this KeyFrame
    21   ANIM_FUNCTION animFunc;           //!< with whitch function to iterate to the next KeyFrame3D
     21  ANIM_FUNCTION animFuncMov;        //!< with whitch function to iterate movement to the next KeyFrame3D
     22  ANIM_FUNCTION animFuncRot;        //!< with whitch function to iterate rotation to the next KeyFrame3D
    2223};
    2324
     
    3435  virtual void rewind(void);
    3536
    36   void addKeyFrame(Vector position, Quaternion direction, float time, ANIM_FUNCTION animFunc = ANIM_LINEAR);
     37  void addKeyFrame(Vector position, Quaternion direction, float time, ANIM_FUNCTION animFuncMov = ANIM_LINEAR, ANIM_FUNCTION animFuncRot = ANIM_LINEAR);
    3738  //  void addKeyFrame(KeyFrame3D* frame);
    3839
    3940  virtual void tick(float dt);
    40 
     41 
    4142 private:
    4243  // animation functions
    43   void setAnimFunc(ANIM_FUNCTION animFunc);
    44   void constant(float timePassed) const;
    45   void linear(float timePassed) const;
    46   void sine(float timePassed) const;
    47   void cosine(float timePassed) const;
    48   void exp(float timePassed) const;
    49   void negExp(float timePassed) const;
    50   void quadratic(float timePassed) const;
    51   void random(float timePassed) const;
     44  void setAnimFuncMov(ANIM_FUNCTION animFunc);
     45  void setAnimFuncRot(ANIM_FUNCTION animFunc);
     46  void mConstant(float timePassed) const;
     47  void mLinear(float timePassed) const;
     48  void mSine(float timePassed) const;
     49  void mCosine(float timePassed) const;
     50  void mExp(float timePassed) const;
     51  void mNegExp(float timePassed) const;
     52  void mQuadratic(float timePassed) const;
     53  void mRandom(float timePassed) const;
     54  void rConstant(float timePassed) const;
     55  void rLinear(float timePassed) const;
     56  void rSine(float timePassed) const;
     57  void rCosine(float timePassed) const;
     58  void rExp(float timePassed) const;
     59  void rNegExp(float timePassed) const;
     60  void rQuadratic(float timePassed) const;
     61  void rRandom(float timePassed) const;
    5262  //  ANIM_FUNCTION animFunc;
    53   void (Animation3D::*animFunc)(float) const;      //!< A Function for the AnimationType
     63  void (Animation3D::*animFuncMov)(float) const;      //!< A Function for the AnimationType
     64  void (Animation3D::*animFuncRot)(float) const;      //!< A Function for the AnimationType
    5465
    5566  KeyFrame3D* currentKeyFrame;                     //!< The current KeyFrame
Note: See TracChangeset for help on using the changeset viewer.