Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4194 in orxonox.OLD for orxonox/branches/openAL/src/util


Ignore:
Timestamp:
May 16, 2005, 1:33:19 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/openAL: merged trunk back to openAL
merged with command:

svn merge ../trunk/ openAL/ -r 3920:HEAD

no conflicts at all

Location:
orxonox/branches/openAL
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/openAL

    • Property svn:externals
      •  

        old new  
        1 data http://svn.orxonox.ethz.ch/data
         1
  • orxonox/branches/openAL/src/util/animation/animation.cc

    r3876 r4194  
    3434
    3535  // setting default values
     36  this->keyFramesToPlay = -1;
    3637  this->localTime = 0.0;
    37   this->bRunning = true;
     38  this->bRunning = false;
    3839
    3940  AnimationPlayer::getInstance()->addAnimation(this);
     
    8384      break;
    8485    case ANIM_INF_REPLAY:
    85       this->replay();
     86      this->rewind();
     87      this->bRunning = true;
    8688      break;
    8789    case ANIM_INF_REWIND:
     
    99101void Animation::play()
    100102{
     103  this->keyFramesToPlay = -1;
     104  this->bRunning = true;
     105}
     106
     107/**
     108   \brief plays the Next n keyframes
     109   \param n the Count of keyFrames to play.
     110*/
     111void Animation::playNextKeyframes(int n)
     112{
     113  this->keyFramesToPlay = n-1;
    101114  this->bRunning = true;
    102115}
     
    107120void Animation::stop()
    108121{
     122  this->keyFramesToPlay = -1;
    109123  this->rewind();
    110124  this->bRunning = true;
     
    127141{
    128142  this->rewind();
    129   this->bRunning = true;
     143  this->play();
    130144}
  • orxonox/branches/openAL/src/util/animation/animation.h

    r3876 r4194  
    2525   ANIM_NEG_EXP: fast, slow
    2626   ANIM_RANDOM: eratic
    27    
     27
     28   ANIM_NULL: !!DO NOT USE THIS!! only for internal handling
     29
    2830   deprecated QUADRATIC
    2931*/
     
    3537                            ANIM_NEG_EXP,
    3638                            ANIM_QUADRATIC,
    37                             ANIM_RANDOM};
     39                            ANIM_RANDOM,
     40                            ANIM_NULL};
     41#define ANIM_DEFAULT_FUNCTION ANIM_LINEAR      //!< A default function to choose from the above set
    3842
    3943//! An enumerator describing what the animation should do after the last keyframe.
     
    6973
    7074  void play(); // equals resume();
     75  void playNextKeyframes(int n = 1);
    7176  void stop();
    7277  void pause();
     
    95100  BaseObject* baseObject;         //!< The same as object in the derived classes, but with reference to BaseObject
    96101  unsigned int keyFrameCount;     //!< The Count of KeyFrames.
     102  int keyFramesToPlay;            //!< How many more Keyframes to play. if negative it will be ignored if 0 stop.
    97103  bool bHandled;                  //!< If this Animation is handled by the AnimationPlayer.
    98104  bool bRunning;                  //!< If the animation is running
  • orxonox/branches/openAL/src/util/animation/animation3d.cc

    r3876 r4194  
    1515   2005-04-17: Benjamin Grauer
    1616          Rewritte all functions, so it will fit into the Animation-class
     17   2005-04-25: Patrick Boenzli
     18          Extended the framework to support quatSlerp rotations. Each frame now supports diff mov/rot types. Implemented mov/rot functions
    1719*/
    1820
     
    4244  this->nextKeyFrame = tmpKeyFrame;
    4345
    44   this->animFunc = &Animation3D::linear;
     46  this->animFuncMov = &Animation3D::mLinear;
     47  this->animFuncRot = &Animation3D::rLinear;
     48
    4549}
    4650
     
    7276  this->nextKeyFrame = keyFrameList->nextElement(keyFrameList->firstElement());
    7377  this->localTime = 0.0;
    74   this->setAnimFunc(this->currentKeyFrame->animFunc);
     78  this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
     79  this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
    7580}
    7681
     
    8085   \param direction The direction of the new Keyframe.
    8186   \param duration The duration from the new KeyFrame to the next one
    82    \param animFunc The function to animate between this keyFrame and the next one
    83 */
    84 void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration, ANIM_FUNCTION animFunc)
     87   \param animFuncMov The function to animate position between this keyFrame and the next one
     88   \param animFuncMov The function to animate rotation between this keyFrame and the next one
     89*/
     90void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration, ANIM_FUNCTION animFuncMov, ANIM_FUNCTION animFuncRot)
    8591{
    8692  // some small check
    8793  if (duration <= 0.0)
    8894    duration = 1.0;
     95  // if the Rotation-Animation-function is set ANIM_NULL, animFuncRot will match animFuncRot
     96  if (animFuncMov == ANIM_NULL)
     97    animFuncMov = ANIM_DEFAULT_FUNCTION;
     98  if (animFuncRot == ANIM_NULL)
     99    animFuncRot = animFuncMov;
    89100
    90101  KeyFrame3D* tmpKeyFrame;
     
    94105    {
    95106      tmpKeyFrame = this->keyFrameList->firstElement();
    96       this->setAnimFunc(animFunc);
     107      //this->setAnimFuncMov(animFuncMov);
     108      //this->setAnimFuncRot(animFuncRot);
    97109    }
    98110  else
     
    106118
    107119  tmpKeyFrame->position = position;
     120  //tmpKeyFrame->lastPosition = position;
    108121  tmpKeyFrame->direction = direction;
    109122  tmpKeyFrame->duration = duration;
    110   tmpKeyFrame->animFunc = animFunc;
     123  tmpKeyFrame->animFuncMov = animFuncMov;
     124  tmpKeyFrame->animFuncRot = animFuncRot;
    111125  this->keyFrameCount++;
    112126}
     127
     128
    113129
    114130/**
     
    123139      if (localTime >= this->currentKeyFrame->duration)
    124140        {
    125           // switching to the next Key-Frame
    126           this->localTime -= this->currentKeyFrame->duration;
    127           this->currentKeyFrame = this->nextKeyFrame;
    128           // checking, if we should still Play the animation
    129           if (this->currentKeyFrame == this->keyFrameList->lastElement())
    130             this->handleInfinity();
    131           this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    132           this->setAnimFunc(this->currentKeyFrame->animFunc);     
    133          
    134           if( this->currentKeyFrame->animFunc == ANIM_NEG_EXP)
     141          if (likely(this->keyFramesToPlay != 0))
    135142            {
    136               this->tmpVect = this->nextKeyFrame->position - this->currentKeyFrame->position;
    137               this->deltaT = 1/this->currentKeyFrame->duration * logf(1.0 + 600.0/this->tmpVect.len());
     143              if (unlikely(this->keyFramesToPlay > 0))
     144                --this->keyFramesToPlay;
     145              // switching to the next Key-Frame
     146              this->localTime -= this->currentKeyFrame->duration;
     147              this->currentKeyFrame = this->nextKeyFrame;
     148              // checking, if we should still Play the animation
     149              if (this->currentKeyFrame == this->keyFrameList->lastElement())
     150                this->handleInfinity();
     151              this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
     152              this->setAnimFuncMov(this->currentKeyFrame->animFuncMov);
     153              this->setAnimFuncRot(this->currentKeyFrame->animFuncRot);
    138154            }
    139         }
    140 
     155          else
     156            this->pause();
     157        }     
    141158      /* now animate it */
    142       (this->*animFunc)(this->localTime);
    143       /*
    144       switch( this->movMode)
    145         {
    146         case LINEAR:
    147           *this->tmpVect = *this->currentFrame->position - *this->lastFrame->position;
    148           *this->tmpVect = *this->tmpVect * this->localTime / this->currentFrame->time;
    149           this->currentFrame->object->setRelCoor(*this->lastFrame->position + *this->tmpVect);
    150           *this->lastPosition = *this->tmpVect;
    151           break;
    152         case EXP:
    153              
    154           break;
    155         case NEG_EXP:
    156           *this->tmpVect = *this->currentFrame->position - *this->lastFrame->position;
    157           *this->tmpVect = *this->tmpVect * (1 - expf(- this->localTime * this->deltaT));     
    158           this->currentFrame->object->setRelCoor(*this->lastFrame->position + *this->tmpVect);
    159           *this->lastPosition = *this->tmpVect;
    160           break;
    161         case SIN:
    162           *this->tmpVect = *this->currentFrame->position - *this->lastFrame->position;
    163           *this->tmpVect = *this->tmpVect * 0.5*(1 - cos(M_PI * this->localTime / this->currentFrame->time));     
    164           this->currentFrame->object->setRelCoor(*this->lastFrame->position + *this->tmpVect);
    165           *this->lastPosition = *this->tmpVect;
    166           break;
    167         case COS:
    168              
    169           break;
    170         case QUADRATIC:
    171           *this->tmpVect = *this->currentFrame->position - *this->lastFrame->position;
    172           *this->tmpVect = *this->tmpVect * 1/3 * ldexpf(this->localTime, 3);
    173           break;
    174         default:
    175           break;
    176         }
    177       */
    178     }
    179 }
    180 
    181 
    182 /**
    183    \brief Sets The kind of Animation between this keyframe and the next one
     159      (this->*animFuncMov)(this->localTime);
     160      (this->*animFuncRot)(this->localTime);
     161    }
     162}
     163
     164
     165/*==Movement Section==========================================================*/
     166
     167/**
     168   \brief Sets The kind of movment Animation between this keyframe and the next one
    184169   \param animFunc The Type of Animation to set
    185170*/
    186 void Animation3D::setAnimFunc(ANIM_FUNCTION animFunc)
    187 {
    188   switch (animFunc)
     171void Animation3D::setAnimFuncMov(ANIM_FUNCTION animFuncMov)
     172{
     173  switch (animFuncMov)
    189174    {
     175    case ANIM_CONSTANT:
     176      this->animFuncMov = &Animation3D::mConstant;
     177      break;
     178    case ANIM_LINEAR:
     179      this->animFuncMov = &Animation3D::mLinear;
     180      this->object->setRelCoor(this->currentKeyFrame->position);
     181      this->currentKeyFrame->lastPosition = Vector();
     182      break;
     183    case ANIM_SINE:
     184      this->animFuncMov = &Animation3D::mSine;
     185      this->object->setRelCoor(this->currentKeyFrame->position);
     186      this->currentKeyFrame->lastPosition = Vector();
     187      break;
     188    case ANIM_COSINE:
     189      this->animFuncMov = &Animation3D::mCosine;
     190      this->object->setRelCoor(this->currentKeyFrame->position);
     191      this->currentKeyFrame->lastPosition = Vector();
     192      break;
     193    case ANIM_EXP:
     194      this->object->setRelCoor(this->currentKeyFrame->position);
     195      this->animFuncMov = &Animation3D::mExp;
     196      break;
     197    case ANIM_NEG_EXP:
     198      this->animFuncMov = &Animation3D::mNegExp;
     199      this->object->setRelCoor(this->currentKeyFrame->position);
     200      this->expFactorMov = -1.0 / this->currentKeyFrame->duration * logf(DELTA_X_3D);
     201      this->currentKeyFrame->lastPosition = Vector();
     202      break;
     203    case ANIM_QUADRATIC:
     204      this->object->setRelCoor(this->currentKeyFrame->position);
     205      this->animFuncMov = &Animation3D::mQuadratic;
     206      break;
     207    case ANIM_RANDOM:
     208      this->object->setRelCoor(this->currentKeyFrame->position);
     209      this->animFuncMov = &Animation3D::mRandom;
     210      break;
    190211    default:
    191     case ANIM_CONSTANT:
    192       this->animFunc = &Animation3D::constant;
    193       break;
    194     case ANIM_LINEAR:
    195       this->animFunc = &Animation3D::linear;
    196       break;
    197     case ANIM_SINE:
    198       this->animFunc = &Animation3D::sine;
    199       break;
    200     case ANIM_COSINE:
    201       this->animFunc = &Animation3D::cosine;
    202       break;
    203     case ANIM_EXP:
    204       this->animFunc = &Animation3D::exp;
    205       break;
    206     case ANIM_NEG_EXP:
    207       this->animFunc = &Animation3D::negExp;
    208       break;
    209     case ANIM_QUADRATIC:
    210       this->animFunc = &Animation3D::quadratic;
    211       break;
    212     case ANIM_RANDOM:
    213       this->animFunc = &Animation3D::random;
    214       break;
    215     }
    216 }
     212      break;
     213    }
     214}
     215
     216
    217217
    218218/**
     
    220220   \param timePassed The time passed since this Keyframe began
    221221*/
    222 void Animation3D::constant(float timePassed) const
    223 {
    224   this->object->setRelCoor(this->currentKeyFrame->position);
     222void Animation3D::mConstant(float timePassed) const
     223{
     224  //this->object->setRelCoor(this->currentKeyFrame->position);
    225225
    226226  /*
     
    238238   \todo implement also do this for direction
    239239*/
    240 void Animation3D::linear(float timePassed) const
    241 {
    242   this->object->setRelCoor(this->currentKeyFrame->position +
    243                           (this->nextKeyFrame->position - this->currentKeyFrame->position) *
    244                           (timePassed/this->currentKeyFrame->duration));
     240void Animation3D::mLinear(float timePassed) const
     241{
     242  Vector v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (timePassed/this->currentKeyFrame->duration);
     243  this->object->shiftCoor(v - this->currentKeyFrame->lastPosition);
     244  this->currentKeyFrame->lastPosition = v;
    245245}
    246246
     
    251251   \todo implement
    252252*/
    253 void Animation3D::sine(float timePassed) const
    254 {
    255   this->linear(timePassed);
    256 }
     253void Animation3D::mSine(float timePassed) const
     254{
     255  Vector v;
     256  if( timePassed  < this->currentKeyFrame->duration/2.0)
     257    v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * sin( M_PI * timePassed /this->currentKeyFrame->duration) / 2.0;
     258  else
     259    v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (2.0 + sin( M_PI * (- timePassed /this->currentKeyFrame->duration)) )/ 2.0;
     260 
     261  this->object->shiftCoor(v - this->currentKeyFrame->lastPosition);
     262  this->currentKeyFrame->lastPosition = v;
     263}
     264
    257265
    258266/**
     
    262270   \todo implement
    263271*/
    264 void Animation3D::cosine(float timePassed) const
    265 {
    266   this->linear(timePassed);
    267 }
     272void Animation3D::mCosine(float timePassed) const
     273{
     274  Vector v;
     275  v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (1.0 + cos( M_PI * timePassed / this->currentKeyFrame->duration))/2.0;
     276  this->object->shiftCoor(v - this->currentKeyFrame->lastPosition);
     277  this->currentKeyFrame->lastPosition = v;
     278
     279
     280  /*
     281  this->object->setRelCoor( this->nextKeyFrame->position -
     282                            (this->nextKeyFrame->position - this->currentKeyFrame->position) *
     283                            (1.0 + cos( M_PI * timePassed / this->currentKeyFrame->duration))/2.0);
     284  */
     285}
     286
     287
    268288
    269289/**
     
    271291   \param timePassed The time passed since this Keyframe began
    272292*/
    273 void Animation3D::exp(float timePassed) const
    274 {
    275   this->linear(timePassed);
     293void Animation3D::mExp(float timePassed) const
     294{
     295  PRINTF(0)("no exp animation3d defined\n");
     296  this->mLinear(timePassed);
    276297}
    277298
     
    279300   \brief a negative exponential interpolation between this keyframe and the next one
    280301   \param timePassed The time passed since this Keyframe began
    281 
    282    \todo implement
    283 */
    284 void Animation3D::negExp(float timePassed) const
    285 {
    286   this->linear(timePassed);
    287 }
     302*/
     303void Animation3D::mNegExp(float timePassed) const
     304{
     305  Vector v;
     306  v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (1.0 - expf(- timePassed * expFactorMov));
     307  this->object->shiftCoor(v - this->currentKeyFrame->lastPosition);
     308  this->currentKeyFrame->lastPosition = v;
     309
     310  /*
     311  this->object->setRelCoor( this->currentKeyFrame->position +
     312                            (this->nextKeyFrame->position - this->currentKeyFrame->position) *
     313                            (1.0 - expf(- timePassed * expFactorMov)) );
     314  */
     315}
     316
    288317
    289318/**
     
    293322   \todo implement
    294323*/
    295 void Animation3D::quadratic(float timePassed) const
    296 {
    297   this->linear(timePassed);
     324void Animation3D::mQuadratic(float timePassed) const
     325{
     326  PRINTF(0)("no quadratic animation3d defined\n");
     327  this->mLinear(timePassed);
    298328}
    299329
     
    302332   \param timePassed The time passed since this Keyframe began
    303333*/
    304 void Animation3D::random(float timePassed) const
    305 {
     334void Animation3D::mRandom(float timePassed) const
     335{
     336  /*
    306337  this->object->setRelCoor(this->currentKeyFrame->position +
    307338                           (this->nextKeyFrame->position - this->currentKeyFrame->position) * (float)rand()/(float)RAND_MAX);
    308339  this->object->setRelDir(this->currentKeyFrame->direction +
    309340                          (this->nextKeyFrame->direction - this->currentKeyFrame->direction)* (float)rand()/(float)RAND_MAX);
    310 }
     341  */
     342}
     343
     344
     345/*==Rotation Section==========================================================*/
     346
     347
     348/**
     349   \brief Sets The kind of rotation Animation between this keyframe and the next one
     350   \param animFunc The Type of Animation to set
     351*/
     352void Animation3D::setAnimFuncRot(ANIM_FUNCTION animFuncRot)
     353{
     354  switch (animFuncRot)
     355    {
     356    default:
     357    case ANIM_CONSTANT:
     358      this->animFuncRot = &Animation3D::rConstant;
     359      break;
     360    case ANIM_LINEAR:
     361      this->animFuncRot = &Animation3D::rLinear;
     362      break;
     363    case ANIM_SINE:
     364      this->animFuncRot = &Animation3D::rSine;
     365      break;
     366    case ANIM_COSINE:
     367      this->animFuncRot = &Animation3D::rCosine;
     368      break;
     369    case ANIM_EXP:
     370      this->animFuncRot = &Animation3D::rExp;
     371      break;
     372    case ANIM_NEG_EXP:
     373      this->animFuncRot = &Animation3D::rNegExp;
     374      this->expFactorRot = -1.0 / this->currentKeyFrame->duration * logf(DELTA_X_3D);
     375      break;
     376    case ANIM_QUADRATIC:
     377      this->animFuncRot = &Animation3D::rQuadratic;
     378      break;
     379    case ANIM_RANDOM:
     380      this->animFuncRot = &Animation3D::rRandom;
     381      break;
     382
     383    }
     384}
     385
     386
     387/**
     388   \brief stays at the value of the currentKeyFrame
     389   \param timePassed The time passed since this Keyframe began
     390*/
     391void Animation3D::rConstant(float timePassed) const
     392{
     393  this->object->setRelDir(this->currentKeyFrame->direction);
     394}
     395
     396/**
     397   \brief linear interpolation between this keyframe and the next one
     398   \param timePassed The time passed since this Keyframe began
     399
     400   \todo implement also do this for direction
     401*/
     402void Animation3D::rLinear(float timePassed) const
     403{
     404  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     405                                     this->currentKeyFrame->direction,
     406                                     timePassed/this->currentKeyFrame->duration) );
     407}
     408
     409/**
     410   \brief a Sinusodial Interpolation between this keyframe and the next one
     411   \param timePassed The time passed since this Keyframe began
     412
     413   \todo implement
     414*/
     415void Animation3D::rSine(float timePassed) const
     416{
     417  float scale;
     418  if( timePassed < this->currentKeyFrame->duration / 2.0)
     419    scale = sin( M_PI * timePassed / this->currentKeyFrame->duration);
     420  else
     421    scale = 1.0 - sin( M_PI * timePassed / this->currentKeyFrame->duration);
     422
     423  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     424                                     this->currentKeyFrame->direction,
     425                                     scale) );
     426}
     427
     428
     429/**
     430   \brief a cosine interpolation between this keyframe and the next one
     431   \param timePassed The time passed since this Keyframe began
     432
     433   \todo implement
     434*/
     435void Animation3D::rCosine(float timePassed) const
     436{
     437  float scale = cos(M_PI * timePassed / this->currentKeyFrame->duration);
     438  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     439                                     this->currentKeyFrame->direction,
     440                                     scale) );
     441}
     442
     443
     444
     445/**
     446   \brief an exponential interpolation between this keyframe and the next one
     447   \param timePassed The time passed since this Keyframe began
     448*/
     449void Animation3D::rExp(float timePassed) const
     450{
     451  PRINTF(0)("exp rotation function not implemented\n");
     452}
     453
     454/**
     455   \brief a negative exponential interpolation between this keyframe and the next one
     456   \param timePassed The time passed since this Keyframe began
     457*/
     458void Animation3D::rNegExp(float timePassed) const
     459{
     460  float scale = (1.0 - expf(- timePassed * expFactorRot));
     461  this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction,
     462                                     this->currentKeyFrame->direction,
     463                                     scale) );
     464}
     465
     466
     467/**
     468   \brief a quadratic interpolation between this keyframe and the next one
     469   \param timePassed The time passed since this Keyframe began
     470
     471   \todo implement
     472*/
     473void Animation3D::rQuadratic(float timePassed) const
     474{
     475  PRINTF(0)("quadratic rotation alg not implemented\n");
     476}
     477
     478/**
     479   \brief some random animation (fluctuating)
     480   \param timePassed The time passed since this Keyframe began
     481*/
     482void Animation3D::rRandom(float timePassed) const
     483{
     484  PRINTF(0)("random rotation alg not implemented\n");
     485}
  • orxonox/branches/openAL/src/util/animation/animation3d.h

    r3868 r4194  
    99class PNode;
    1010
     11#define DELTA_X_3D 0.05  //!< the percentag of the distance that doesnt have to be done by neg_exp (asymptotical) ~ maschinendelta
     12
    1113//! KeyFrame3D Struct
    1214/**
     
    1618  float duration;                   //!< The duration of this KeyFrame
    1719  Vector position;                  //!< The position of this KeyFrame
     20  Vector lastPosition;
    1821  Quaternion direction;             //!< The direction of this KeyFrame
    19   ANIM_FUNCTION animFunc;           //!< with whitch function to iterate to the next KeyFrame3D
     22  ANIM_FUNCTION animFuncMov;        //!< with whitch function to iterate movement to the next KeyFrame3D
     23  ANIM_FUNCTION animFuncRot;        //!< with whitch function to iterate rotation to the next KeyFrame3D
    2024};
    2125
     
    3236  virtual void rewind(void);
    3337
    34   void addKeyFrame(Vector position, Quaternion direction, float time, ANIM_FUNCTION animFunc = ANIM_LINEAR);
     38  void addKeyFrame(Vector position, Quaternion direction, float time, ANIM_FUNCTION animFuncMov = ANIM_DEFAULT_FUNCTION, ANIM_FUNCTION animFuncRot = ANIM_NULL);
    3539  //  void addKeyFrame(KeyFrame3D* frame);
    3640
    3741  virtual void tick(float dt);
    38 
     42 
    3943 private:
    4044  // animation functions
    41   void setAnimFunc(ANIM_FUNCTION animFunc);
    42   void constant(float timePassed) const;
    43   void linear(float timePassed) const;
    44   void sine(float timePassed) const;
    45   void cosine(float timePassed) const;
    46   void exp(float timePassed) const;
    47   void negExp(float timePassed) const;
    48   void quadratic(float timePassed) const;
    49   void random(float timePassed) const;
     45  void setAnimFuncMov(ANIM_FUNCTION animFunc);
     46  void setAnimFuncRot(ANIM_FUNCTION animFunc);
     47  void mConstant(float timePassed) const;
     48  void mLinear(float timePassed) const;
     49  void mSine(float timePassed) const;
     50  void mCosine(float timePassed) const;
     51  void mExp(float timePassed) const;
     52  void mNegExp(float timePassed) const;
     53  void mQuadratic(float timePassed) const;
     54  void mRandom(float timePassed) const;
     55  void rConstant(float timePassed) const;
     56  void rLinear(float timePassed) const;
     57  void rSine(float timePassed) const;
     58  void rCosine(float timePassed) const;
     59  void rExp(float timePassed) const;
     60  void rNegExp(float timePassed) const;
     61  void rQuadratic(float timePassed) const;
     62  void rRandom(float timePassed) const;
    5063  //  ANIM_FUNCTION animFunc;
    51   void (Animation3D::*animFunc)(float) const;      //!< A Function for the AnimationType
     64  void (Animation3D::*animFuncMov)(float) const;      //!< A Function for the AnimationType
     65  void (Animation3D::*animFuncRot)(float) const;      //!< A Function for the AnimationType
    5266
    5367  KeyFrame3D* currentKeyFrame;                     //!< The current KeyFrame
     
    6074  Vector tmpVect;        //!< what for??
    6175  float deltaT;          //!< ??
     76  float expFactorMov;
     77  float expFactorRot;
    6278};
  • orxonox/branches/openAL/src/util/animation/t_animation.h

    r3876 r4194  
    4343  void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
    4444
    45   void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);
     45  void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_DEFAULT_FUNCTION);
    4646
    4747  virtual void rewind();
     
    154154  if (duration <= 0.0)
    155155    duration = 1.0;
     156  if (animFunc == ANIM_NULL)
     157    animFunc = ANIM_DEFAULT_FUNCTION;
    156158
    157159  KeyFrameF* tmpKeyFrame;
     
    190192      if (localTime >= this->currentKeyFrame->duration)
    191193        {
    192           // switching to the next Key-Frame
    193           this->localTime -= this->currentKeyFrame->duration;
    194 
    195           this->currentKeyFrame = this->nextKeyFrame;
    196           // checking, if we should still Play the animation
    197           if (this->currentKeyFrame == this->keyFrameList->lastElement())
    198             this->handleInfinity();
    199           this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    200 
    201           printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);
    202           this->setAnimFunc(this->currentKeyFrame->animFunc);     
     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();
    203212        }
    204213     
     
    235244      {
    236245        this->animFunc = &tAnimation<T>::negExp;
    237         float d = fabs(this->currentKeyFrame->value - this->nextKeyFrame->value);
    238246        expFactor =  - 1.0 / this->currentKeyFrame->duration * logf(DELTA_X);
    239247        break;
  • orxonox/branches/openAL/src/util/resource_manager.cc

    r3883 r4194  
    9292      this->dataDir = new char[strlen(dataDir)+1];
    9393      strcpy(this->dataDir, dataDir);
     94      return true;
    9495    }
    9596  else
    9697    {
    9798      PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir, this->dataDir);
    98     }
     99      return false;
     100    }
     101}
     102
     103/**
     104   \brief checks for the DataDirectory, by looking if
     105   \param fileInside is inisde??
     106*/
     107bool ResourceManager::checkDataDir(const char* fileInside)
     108{
     109  bool retVal;
     110  if (!isDir(this->dataDir))
     111    {
     112      PRINTF(1)("%s is not a directory\n", this->dataDir);
     113      return false;
     114    }
     115 
     116  char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1];
     117  sprintf(testFile, "%s%s", this->dataDir, fileInside);
     118  retVal = isFile(testFile);
     119  delete testFile;
     120  return retVal;
    99121}
    100122
     
    180202  // searching if the resource was loaded before.
    181203  Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3);
    182   if (tmpResource) // if the resource was not loaded before.
     204  if (tmpResource) // if the resource was loaded before.
    183205    {
    184206      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
     
    199221
    200222      // creating the full name. (directoryName + FileName)
    201       char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
    202       sprintf(fullName, "%s%s", this->dataDir, fileName);
    203      
     223      char* fullName = new char[strlen(this->getDataDir())+strlen(fileName)+1];
     224      sprintf(fullName, "%s%s", this->getDataDir(), fileName);
    204225      // Checking for the type of resource \see ResourceType
    205226      switch(type)
     
    211232            tmpResource->modelSize = 1.0;
    212233
    213           if(isFile(fullName))
     234          if(ResourceManager::isFile(fullName))
    214235            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
    215236          else
     
    508529    }
    509530
    510   stat(tmpDirName, &status);
    511   if (status.st_mode & (S_IFDIR
     531  if(!stat(tmpDirName, &status))
     532    {
     533      if (status.st_mode & (S_IFDIR
    512534#ifndef __WIN32__
    513                         | S_IFLNK
     535                            | S_IFLNK
    514536#endif
    515                         ))
    516     {
    517       delete tmpDirName;
    518       return true;
    519     }
    520   else
    521     {
    522       delete tmpDirName;
    523       return false;
    524     }
     537                            ))
     538        {
     539          delete tmpDirName;
     540          return true;
     541        }
     542      else
     543        {
     544          delete tmpDirName;
     545          return false;
     546        }
     547    }
     548  else
     549    return false;
    525550}
    526551
     
    532557bool ResourceManager::isFile(const char* fileName)
    533558{
     559  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
     560  // actually checks the File
    534561  struct stat status;
    535   stat(fileName, &status);
    536   if (status.st_mode & (S_IFREG
     562  if (!stat(tmpFileName, &status))
     563    {
     564      if (status.st_mode & (S_IFREG
    537565#ifndef __WIN32__
    538                         | S_IFLNK
     566                            | S_IFLNK
    539567#endif
    540                         ))
    541     return true;
    542   else
    543     return false;
    544 }
     568                            ))
     569        {
     570          delete tmpFileName;
     571          return true;
     572        }
     573      else
     574        {
     575          delete tmpFileName;
     576          return false;
     577        }
     578    }
     579  else
     580    {
     581      delete tmpFileName;
     582      return false;
     583    }
     584}
     585
     586/**
     587   \brief touches a File on the disk (thereby creating it)
     588   \param fileName The file to touch
     589*/
     590bool ResourceManager::touchFile(const char* fileName)
     591{
     592  char* tmpName = ResourceManager::homeDirCheck(fileName);
     593
     594  FILE* stream;
     595  if( (stream = fopen (tmpName, "w")) == NULL)
     596    {
     597      PRINTF(1)("could not open %s fro writing\n", fileName);
     598      return false;
     599    }
     600  fclose(stream);
     601   
     602  delete tmpName;
     603}
     604
     605/**
     606   \brief deletes a File from disk
     607   \param fileName the File to delete
     608*/
     609bool ResourceManager::deleteFile(const char* fileName)
     610{
     611  char* tmpName = ResourceManager::homeDirCheck(fileName);
     612  unlink(tmpName);
     613  delete tmpName;
     614}
     615
     616/**
     617    \param fileName the Name of the file to check
     618    \returns The name of the file, including the HomeDir
     619    IMPORTANT: this has to be deleted from the outside
     620*/
     621char* ResourceManager::homeDirCheck(const char* name)
     622{
     623  char* retName;
     624  if (!strncmp(name, "~/", 2))
     625    {
     626      char tmpFileName[500];
     627#ifdef __WIN32__
     628      strcpy(tmpFileName, getenv("USERPROFILE"));
     629#else
     630      strcpy(tmpFileName, getenv("HOME"));
     631#endif
     632      retName = new char[strlen(tmpFileName)+strlen(name)];
     633      sprintf(retName, "%s%s", tmpFileName, name+1);
     634    }
     635  else
     636    {
     637      retName = new char[strlen(name)+1];
     638      strcpy(retName, name);
     639    }
     640  return retName;
     641}
     642
     643/**
     644    \param fileName the Name of the File to check
     645    \returns The full name of the file, including the DataDir, and NULL if the file does not exist
     646    IMPORTANT: this has to be deleted from the outside
     647*/
     648char* ResourceManager::getFullName(const char* fileName)
     649{
     650  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(fileName)+1];
     651  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     652  if (ResourceManager::isFile(retName))
     653    return retName;
     654  else
     655    {
     656      delete retName;
     657      return NULL;
     658    }
     659}
     660
    545661
    546662/**
  • orxonox/branches/openAL/src/util/resource_manager.h

    r3911 r4194  
    1818
    1919//! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support
    20 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE};
     20enum ResourceType {OBJ,
     21                   PRIM,
     22                   WAV,
     23                   MP3,
     24                   OGG,
     25                   TTF,
     26                   IMAGE};
    2127//! An enumerator for different UNLOAD-types.
    2228/**
     
    2632   RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)
    2733*/
    28 enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3};
     34enum ResourcePriority {RP_NO = 0,
     35                       RP_LEVEL = 1,
     36                       RP_CAMPAIGN = 2,
     37                       RP_GAME = 3};
    2938
    3039//! A Struct that keeps track about A resource its name its Type, and so on
     
    6574
    6675  bool setDataDir(const char* dataDir);
     76  /** \returns the Name of the data directory */
     77  inline const char* getDataDir(void) const {return this->dataDir;}
     78
     79  bool checkDataDir(const char* fileInside);
    6780  bool addImageDir(char* imageDir);
    6881  void* load(const char* fileName, ResourcePriority prio = RP_NO,
     
    7386  bool unload(Resource* resource, ResourcePriority = RP_NO);
    7487  bool unloadAllByPriority(ResourcePriority prio);
     88
    7589  void debug(void);
     90
     91  // utility functions of this class
     92  static bool isDir(const char* directory);
     93  static bool isFile(const char* fileName);
     94  static bool touchFile(const char* fileName);
     95  static bool deleteFile(const char* fileName);
     96  static char* homeDirCheck(const char* fileName);
     97  static char* getFullName(const char* fileName);
    7698
    7799 private:
     
    87109  Resource* locateResourceByPointer(const void* pointer);
    88110 
    89   bool isDir(const char* directory);
    90   bool isFile(const char* directory);
    91 
    92111};
    93112
Note: See TracChangeset for help on using the changeset viewer.