Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3784 in orxonox.OLD


Ignore:
Timestamp:
Apr 13, 2005, 12:24:05 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: some better implementation for the Animation Class. it now sends around some FunctionPointers

Location:
orxonox/branches/textEngine/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/animation.cc

    r3782 r3784  
    1717#include "animation.h"
    1818#include "debug.h"
     19#include "list.h"
    1920
    2021
    2122Anim::Anim(void)
    2223{
     24  // create a new List
     25  this->keyFrameList = new tList<AnimKeyFrame>();
     26 
     27  // initialize a beginning KeyFrame, that will be deleted afterwards
     28  this->bHasKeys = false;
     29
     30
     31  this->animFunc = &Anim::random;
    2332}
    2433
    2534
     35Anim::~Anim(void)
     36{
     37  // delete all the KeyFrames
     38  tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator();
     39  AnimKeyFrame*  enumKF = itKF->nextElement();
     40  while (enumKF)
     41    {
     42      delete enumKF;
     43      enumKF = itKF->nextElement();
     44    }
     45  delete itKF;
     46  delete this->keyFrameList;
     47}
     48
    2649tList<Anim>* Anim::animatorList = NULL;
     50
     51
     52void Anim::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc)
     53{
     54  if (!bHasKeys)
     55    {
     56      this->keyFrameList->remove(this->keyFrameList->firstElement());
     57      bHasKeys = true;
     58    }
     59  AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame;
     60  tmpKeyFrame->value = value;
     61  tmpKeyFrame->duration = duration;
     62  tmpKeyFrame->animFunc = animFunc;
     63 
     64  this->keyFrameList->add(tmpKeyFrame);
     65}
     66
     67void Anim::setInfinity(ANIM_INFINITY preInfinity, ANIM_INFINITY postInfinity)
     68{
     69  this->preInfinity = preInfinity;
     70  this->postInfinity = postInfinity;
     71}
     72
     73void Anim::setAnimFunc(ANIM_FUNCTION animFunc)
     74{
     75  switch (animFunc)
     76    {
     77    default:
     78    case ANIM_CONSTANT:
     79      this->animFunc = &Anim::constant;
     80      break;
     81    case ANIM_LINEAR:
     82      this->animFunc = &Anim::linear;
     83      break;
     84    case ANIM_RANDOM:
     85      this->animFunc = &Anim::random;
     86      break;
     87    case ANIM_SINE:
     88      this->animFunc = &Anim::sine;
     89      break;
     90
     91    }
     92}
     93
     94
     95// animation functions
     96float Anim::random(float time)
     97{
     98  return (float)rand()/(float)RAND_MAX;
     99}
     100
     101float Anim::constant(float time)
     102{
     103
     104}
     105
     106float Anim::linear(float time)
     107{
     108
     109}
     110
     111float Anim::sine(float time)
     112{
     113
     114}
  • orxonox/branches/textEngine/src/animation.h

    r3783 r3784  
    1818    \file animation.h
    1919    A Set of functions to animate some floats inside of an Object
     20
     21    We apologize, that most part of the Function-Definitions are located
     22    inside this h-file, but this must be like this because it is a template
     23    function.
    2024*/
    2125
     
    2731template<class T> class tList;
    2832
    29 enum ANIM_FUNCTION {ANIM_LINEAR, ANIM_SINE };
    30 enum ANIM_INFINITY {ANIM_INF_CONSTANT, ANIM_INF_LINEAR, ANIM_INF_PINGPONG, ANIM_INF_REWIND};//, ANIM_DELETE}
     33typedef enum ANIM_FUNCTION {ANIM_CONSTANT,
     34                            ANIM_LINEAR,
     35                            ANIM_SINE,
     36                            ANIM_RANDOM};
     37typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT,
     38                            ANIM_INF_LINEAR,
     39                            ANIM_INF_PINGPONG,
     40                            ANIM_INF_REWIND};//, ANIM_DELETE}
     41
     42struct AnimKeyFrame
     43{
     44  float duration;
     45  float value;
     46  ANIM_FUNCTION animFunc;
     47};
    3148
    3249class Anim
    3350{
    3451 protected:
    35   Anim();
     52  Anim(void);
     53  virtual ~Anim(void);
    3654
    3755  static tList<Anim>* animatorList;
    3856
    3957  virtual void tick(float time) = 0;
     58
     59  void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);
     60  void setInfinity(ANIM_INFINITY preInfinity = ANIM_INF_CONSTANT,
     61                   ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT);
     62  void setAnimFunc(ANIM_FUNCTION animFunc);
     63
     64
     65  // animation functions
     66  float random(float time);
     67  float constant(float time);
     68  float linear(float time);
     69  float sine(float time);
     70
     71
     72  // variables
     73  //  ANIM_FUNCTION animFunc;
     74  float (Anim::*animFunc)(float);
     75  ANIM_INFINITY preInfinity;
     76  ANIM_INFINITY postInfinity;
     77
     78  bool bHasKeys;
     79  tList<AnimKeyFrame>* keyFrameList;
    4080};
    4181
     
    4585{
    4686 public:
    47   Animation();
     87  Animation(T* object = NULL, void (T::*funcToAnim)(float) = NULL);
    4888  virtual ~Animation();
    4989
    5090  void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
    51   void setAnimFunc(ANIM_FUNCTION animFunc);
    52   void setValue(float value);
    5391
    5492  virtual void tick(float time);
    5593
    5694 private:
     95  T* object;
    5796  void (T::*funcToAnim)(float);
    58   ANIM_FUNCTION animFunc;
    59   float value;
    60   T* object;
    6197};
    6298
     
    68104*/
    69105template<class T>
    70 Animation<T>::Animation ()
     106Animation<T>::Animation (T* object, void (T::*funcToAnim)(float))
    71107{
    72    this->value = 0.0;
     108  this->setFuncToAnim(object, funcToAnim);
    73109}
    74110
     
    92128}
    93129
    94 template<class T>
    95 void Animation<T>::setValue(float value)
    96 {
    97   this->value = value;
    98   (object->*(funcToAnim))(value);
    99 }
    100130
    101131template<class T>
    102132void Animation<T>::tick(float time)
    103133{
    104   setValue(value - time/1000);
    105   if (value < 0)
    106     setValue (1.0);
     134  (this->object->*(funcToAnim))((this->*animFunc)(time));
    107135}
    108136
  • orxonox/branches/textEngine/src/story_entities/world.cc

    r3781 r3784  
    360360
    361361           
    362             tmpAnim = new Animation<Text>();
    363 
    364             tmpAnim->setFuncToAnim(testText, &Text::setBlending);
     362            tmpAnim = new Animation<Text>(testText, &Text::setBlending);
     363
     364            //      tmpAnim->setFuncToAnim(testText, &Text::setBlending);
    365365            break;
    366366          }
Note: See TracChangeset for help on using the changeset viewer.