Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/animation.cc @ 3786

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

orxonox/branches/textEngine: amimate: rewind works

File size: 2.9 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#include "animation.h"
18#include "debug.h"
19#include "list.h"
20
21
22Anim::Anim(void)
23{
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  AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame;
30  tmpKeyFrame->value = 0.0;
31  tmpKeyFrame->duration = 1.0;
32  keyFrameList->add(tmpKeyFrame);
33
34  // setting default values
35  this->localTime = 0.0;
36  this->animFunc = &Anim::linear;
37  this->currentKeyFrame = tmpKeyFrame;
38  this->nextKeyFrame = tmpKeyFrame;
39}
40
41
42Anim::~Anim(void)
43{
44  // delete all the KeyFrames
45  tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator();
46  AnimKeyFrame*  enumKF = itKF->nextElement();
47  while (enumKF)
48    {
49      delete enumKF;
50      enumKF = itKF->nextElement();
51    }
52  delete itKF;
53  delete this->keyFrameList;
54}
55
56tList<Anim>* Anim::animatorList = NULL;
57
58
59void Anim::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc)
60{
61  // some small check
62  if (duration <= 0.0)
63    duration = 1.0;
64 
65
66  AnimKeyFrame* tmpKeyFrame;
67   
68  if (bHasKeys)
69    {
70      tmpKeyFrame = new AnimKeyFrame;
71      if (this->currentKeyFrame == this->nextKeyFrame)
72        this->nextKeyFrame = tmpKeyFrame;
73      this->keyFrameList->add(tmpKeyFrame);
74
75    }
76  else
77    {
78      tmpKeyFrame = this->keyFrameList->firstElement();
79      bHasKeys = true;
80    }
81  tmpKeyFrame->value = value;
82  tmpKeyFrame->duration = duration;
83  tmpKeyFrame->animFunc = animFunc;
84 
85}
86
87void Anim::setInfinity(ANIM_INFINITY preInfinity, ANIM_INFINITY postInfinity)
88{
89  this->preInfinity = preInfinity;
90  this->postInfinity = postInfinity;
91}
92
93void 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
115float Anim::random(float timePassed) const
116{
117  return (float)rand()/(float)RAND_MAX;
118}
119
120float Anim::constant(float timePassed) const
121{
122  return this->currentKeyFrame->value;
123}
124
125float 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
133float Anim::sine(float timePassed) const
134{
135 
136}
Note: See TracBrowser for help on using the repository browser.