Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/animation.h @ 3784

Last change on this file since 3784 was 3784, checked in by bensch, 19 years ago

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

File size: 2.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16
17/*!
18    \file animation.h
19    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.
24*/
25
26#ifndef _ANIMATION_H
27#define _ANIMATION_H
28
29
30// FORWARD DEFINITION
31template<class T> class tList;
32
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};
48
49class Anim
50{
51 protected:
52  Anim(void);
53  virtual ~Anim(void);
54
55  static tList<Anim>* animatorList;
56
57  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;
80};
81
82
83//! A Class to handle some animation for single floated values.
84template<class T> class Animation : public Anim
85{
86 public:
87  Animation(T* object = NULL, void (T::*funcToAnim)(float) = NULL);
88  virtual ~Animation();
89
90  void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
91
92  virtual void tick(float time);
93
94 private:
95  T* object;
96  void (T::*funcToAnim)(float);
97};
98
99
100
101/**
102   \brief standard constructor
103
104*/
105template<class T>
106Animation<T>::Animation (T* object, void (T::*funcToAnim)(float)) 
107{
108  this->setFuncToAnim(object, funcToAnim);
109}
110
111
112/**
113   \brief standard deconstructor
114
115*/
116template<class T>
117Animation<T>::~Animation () 
118{
119  // delete what has to be deleted here
120}
121
122
123template<class T>
124void Animation<T>::setFuncToAnim(T* object, void (T::*funcToAnim)(float))
125{
126  this->object = object;
127  this->funcToAnim = funcToAnim;
128}
129
130
131template<class T>
132void Animation<T>::tick(float time)
133{
134  (this->object->*(funcToAnim))((this->*animFunc)(time));
135}
136
137#endif /* _ANIMATION_H */
Note: See TracBrowser for help on using the repository browser.