Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3795 in orxonox.OLD


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

Location:
orxonox/trunk/src
Files:
3 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 }
  • orxonox/trunk/src/animation.h

    r3794 r3795  
    2727#define _ANIMATION_H
    2828
    29 
     29#include "list.h"
    3030// FORWARD DEFINITION
    31 template<class T> class tList;
    3231
    3332typedef enum ANIM_FUNCTION {ANIM_CONSTANT,
     
    5554  void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT);
    5655
    57   void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);
    58   void setAnimFunc(ANIM_FUNCTION animFunc);
    59 
    6056  void play(); // equals resume();
    6157  void stop();
    6258  void pause();
    6359  void replay();
     60  //  virtual void rewind();
    6461
    6562  virtual void tick(float time) = 0;
    6663
     64  /* implement in subclasses:
     65   *
     66   * De-/Constructor
     67   * Animation Functions
     68   * virtual tick
     69   * List of keyFrames
     70   * currentKeyFrame/nextKeyFrame
     71   * virtual rewind, to go to the first Keyframe. (other functions will call this one)
     72   */
    6773 protected:
    6874  Anim(void);
    6975
    70   static tList<Anim>* animatorList;
     76  // variables
     77
     78  float localTime;
     79  ANIM_INFINITY postInfinity;
     80
     81  bool bHasKeys;
     82  bool bRunning;
     83};
     84
     85
     86//! A Class to handle some animation for single floated values.
     87template<class T> class tAnim : public Anim
     88{
     89 public:
     90  tAnim(T* object = NULL, void (T::*funcToAnim)(float) = NULL);
     91  virtual ~tAnim();
     92
     93  void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
     94  void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);
     95
    7196
    7297  // animation functions
     98  void setAnimFunc(ANIM_FUNCTION animFunc);
     99
    73100  float random(float timePassed) const;
    74101  float constant(float timePassed) const;
    75102  float linear(float timePassed) const;
    76103  float sine(float timePassed) const;
    77 
    78 
    79   // variables
    80104  //  ANIM_FUNCTION animFunc;
    81   float (Anim::*animFunc)(float) const;
    82 
    83   ANIM_INFINITY postInfinity;
    84 
    85   bool bHasKeys;
    86   bool bRunning;
    87 
    88   float localTime;
     105  float (tAnim<T>::*animFunc)(float) const;
    89106  AnimKeyFrame* currentKeyFrame;
    90107  AnimKeyFrame* nextKeyFrame;
    91108  tList<AnimKeyFrame>* keyFrameList;
    92 };
    93 
    94 
    95 //! A Class to handle some animation for single floated values.
    96 template<class T> class tAnim : public Anim
    97 {
    98  public:
    99   tAnim(T* object = NULL, void (T::*funcToAnim)(float) = NULL);
    100   virtual ~tAnim();
    101 
    102   void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
     109
     110
     111
    103112
    104113  virtual void tick(float time);
     
    118127tAnim<T>::tAnim (T* object, void (T::*funcToAnim)(float))
    119128{
     129  // create a new List
     130  this->keyFrameList = new tList<AnimKeyFrame>();
     131  AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame;
     132  tmpKeyFrame->value = 0.0;
     133  tmpKeyFrame->duration = 1.0;
     134  keyFrameList->add(tmpKeyFrame);
     135
     136  this->currentKeyFrame = tmpKeyFrame;
     137  this->nextKeyFrame = tmpKeyFrame;
     138
     139  this->animFunc = &tAnim<T>::linear;
     140
    120141  this->setFuncToAnim(object, funcToAnim);
    121142}
     
    129150tAnim<T>::~tAnim ()
    130151{
    131   // delete what has to be deleted here
     152  // delete all the KeyFrames
     153  tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator();
     154  AnimKeyFrame*  enumKF = itKF->nextElement();
     155  while (enumKF)
     156    {
     157      delete enumKF;
     158      enumKF = itKF->nextElement();
     159    }
     160  delete itKF;
     161  delete this->keyFrameList;
     162
    132163}
    133164
     
    138169  this->object = object;
    139170  this->funcToAnim = funcToAnim;
     171}
     172
     173template<class T>
     174void tAnim<T>::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc)
     175{
     176  // some small check
     177  if (duration <= 0.0)
     178    duration = 1.0;
     179 
     180
     181  AnimKeyFrame* tmpKeyFrame;
     182   
     183  if (bHasKeys)
     184    {
     185      tmpKeyFrame = new AnimKeyFrame;
     186      if (this->currentKeyFrame == this->nextKeyFrame)
     187        this->nextKeyFrame = tmpKeyFrame;
     188      this->keyFrameList->add(tmpKeyFrame);
     189
     190    }
     191  else
     192    {
     193      tmpKeyFrame = this->keyFrameList->firstElement();
     194      bHasKeys = true;
     195    }
     196  tmpKeyFrame->value = value;
     197  tmpKeyFrame->duration = duration;
     198  tmpKeyFrame->animFunc = animFunc;
     199 
    140200}
    141201
     
    170230}
    171231
     232
     233template<class T>
     234void tAnim<T>::setAnimFunc(ANIM_FUNCTION animFunc)
     235{
     236  switch (animFunc)
     237    {
     238    default:
     239    case ANIM_CONSTANT:
     240      this->animFunc = &tAnim<T>::constant;
     241      break;
     242    case ANIM_LINEAR:
     243      this->animFunc = &tAnim<T>::linear;
     244      break;
     245    case ANIM_RANDOM:
     246      this->animFunc = &tAnim<T>::random;
     247      break;
     248    case ANIM_SINE:
     249      this->animFunc = &tAnim<T>::sine;
     250      break;
     251    }
     252}
     253
     254
     255// animation functions
     256template<class T>
     257float tAnim<T>::random(float timePassed) const
     258{
     259  return (float)rand()/(float)RAND_MAX;
     260}
     261
     262template<class T>
     263float tAnim<T>::constant(float timePassed) const
     264{
     265  return this->currentKeyFrame->value;
     266}
     267
     268template<class T>
     269float tAnim<T>::linear(float timePassed) const
     270{
     271  return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value)
     272    * (timePassed / this->currentKeyFrame->duration);
     273  //  PRINTF(0)("value is %f, %p %p\n", val, this->currentKeyFrame, this->nextKeyFrame);
     274  //  return val;
     275}
     276
     277template<class T>
     278float tAnim<T>::sine(float timePassed) const
     279{
     280 
     281}
     282
    172283#endif /* _ANIMATION_H */
  • orxonox/trunk/src/story_entities/world.h

    r3794 r3795  
    2424class GarbageCollector;
    2525class SimpleAnimation;
    26 class Anim;
     26template<class T> class tAnim;
    2727class Text;
    2828
     
    9999  GLMenuImageScreen* glmis;           //!< The Level-Loader Display
    100100
    101   Anim* testAnim;
     101  tAnim<Text>* testAnim;
    102102  Text* testText;                     //!< A text to Test the TextEngine;
    103103
Note: See TracChangeset for help on using the changeset viewer.