Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4421 in orxonox.OLD for orxonox


Ignore:
Timestamp:
May 31, 2005, 5:48:17 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: lifetime-animation works now via the quickAnimation (only for radius)

Location:
orxonox/trunk/src/lib/particles
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4397 r4421  
    5858  this->setMass(1.0, 0.0);
    5959  ParticleEngine::getInstance()->addSystem(this);
     60
     61  radiusAnim.addEntry(0.0,5);
     62
     63  radiusAnim.addEntry(.80,3);
     64
     65  radiusAnim.addEntry(.5, 0);
    6066}
    6167
     
    247253      // rendering new position.
    248254      tickPart->position = tickPart->position + tickPart->velocity * dt;
    249       tickPart->radius += tickPart->radiusIt * dt;
     255      tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle);
    250256     
    251257      tickPart->extForce = Vector(0,0,0);
  • orxonox/trunk/src/lib/particles/particle_system.h

    r4396 r4421  
    1212#include "glincl.h"
    1313#include "vector.h"
     14
     15#include "quick_animation.h"
    1416
    1517#define PARTICLE_DOT_MASK           0x000001
     
    136138  GLuint* glID;              //!< A List of different gl-List-ID's
    137139  GLuint dialectCount;       //!< How many different types of particles are there in the Particle System 
     140
     141  QuickAnimation radiusAnim;
    138142};
    139143
  • orxonox/trunk/src/lib/particles/quick_animation.cc

    r4415 r4421  
    3131   \brief standard constructor
    3232*/
    33 QuickAnimation::QuickAnimation (float rangeStart, float valueStart, float rangeEnd, float valueEnd)
     33QuickAnimation::QuickAnimation (void)
    3434{
    3535   this->setClassName("QuickAnimation");
    3636
    37    this->first = this->current = new QuickKeyFrame;
    38    this->current->positionStart = rangeStart;
    39    this->current->positionEnd = rangeEnd;
    40    this->current->valueStart = valueStart;
    41    this->current->valueEnd = valueEnd;
    42    this->current->next = NULL;
     37   this->first = this->current = NULL;
    4338}
    4439
     
    4843
    4944*/
    50 QuickAnimation::~QuickAnimation ()
     45QuickAnimation::~QuickAnimation (void)
    5146{
    5247  this->current = this->first;
     
    6257}
    6358
    64 
    65 void QuickAnimation::addEntry(float position, float value)
     59/**
     60   \brief adds a new entry to the list of keyframes
     61   \param position the position to add the key to
     62   \param value the Value to set for the position
     63   \returns false if the key existed already for a given position
     64*/
     65bool QuickAnimation::addEntry(float position, float value)
    6666{
    6767  this->current = this->first;
    68   if (position < this->current->positionStart)
     68  while (this->current != NULL)
    6969    {
    70       this->current = new QuickKeyFrame;
     70      // if it is between some keyframes
     71      if ((!this->current->next && this->current->position < position)
     72          || (this->current->position < position && this->current->next->position > position))
     73        break;
     74      // if it is the same as an already existing keyframe
     75      else if (this->current->position == position)
     76        return false;
     77      this->current = this->current->next;
     78    }
    7179
    72       this->current->positionStart = position;
    73       this->current->positionEnd = this->first->positionStart;
     80  QuickKeyFrame* newKey = new QuickKeyFrame;
     81  if (this->first == NULL)
     82    {
     83      this->first = newKey;
     84      this->current = newKey;
     85      newKey->next = NULL;
     86    }
     87  else
     88    {
     89      newKey->next = this->current->next;
     90      this->current->next = newKey;
     91    }
     92  newKey->value = value;
     93  newKey->position = position;
     94 
     95  this->current = this->first;
     96}
    7497
    75       this->current->valueStart = value;
    76       this->current->valueEnd = this->first->valueStart;
    77      
    78       this->current->next = this->first;
    79       this->first = this->current;
    80     }
    81  
    82   while(this->current != NULL)
     98/**
     99   \brief returns the value of the animation at a certain position
     100   \param position the position to get the value from :)
     101*/
     102float QuickAnimation::getValue(float position)
     103{
     104  if (unlikely(this->first == NULL))
     105    return 0.0;
     106  else if (unlikely (this->first->next == NULL))
     107    return this->first->value;
     108  else
    83109    {
    84       if (this->current->positionStart < position)
     110      if (unlikely(position < this->current->position))
    85111        {
    86           QuickKeyFrame* tmpKey = new QuickKeyFrame;
    87           tmpKey->positionStart = position;
    88           tmpKey->positionEnd = this->current->positionEnd;
    89           tmpKey->valueStart = value;
    90           tmpKey->valueEnd = this->current->valueEnd;
    91           tmpKey->next = this->current->next;
    92          
    93           this->current->positionEnd = tmpKey->positionStart;
    94           this->current->valueEnd = tmpKey->valueStart;
     112          if (position <= this->first->position)
     113            return this->first->value;
     114          this->current = this->first;
    95115        }
     116      while (likely(this->current->next != NULL && position > this->current->next->position))
     117        this->current = this->current->next;
     118      if (this->current->next == NULL)
     119        return this->current->value;
     120               
     121      return this->current->value + (this->current->next->value - this->current->value)
     122        * ((position-this->current->position) / (this->current->next->position -this->current->position));
    96123    }
    97124}
    98125
    99126
    100 float QuickAnimation::getValue(float position)
     127void QuickAnimation::debug(void)
    101128{
    102   while (likely (this->current->positionStart > position || this->current->positionEnd < position))
     129  this->current = this->first;
     130
     131  PRINT(0)("QuickAnim:: (position, value)");
     132  while(this->current)
    103133    {
    104       if (likely(this->current->next != NULL))
    105         this->current = this->current->next;
    106       else
    107         {
    108           if (unlikely(this->first->positionStart > position))
    109             {
    110               PRINTF(2)("Position out of range. chose %f, min is: %f, max is\n", position, this->first->positionStart, this->current->positionEnd);
    111               return 0;
    112             }
    113           this->current = this->first;
    114         }
     134      PRINT(0)("->(%f, %f)", this->current->position, this->current->value);
     135      this->current = this->current->next;
    115136    }
    116   return this->current->valueStart + (this->current->positionEnd - position) *
    117     (this->current->valueEnd - this->current->valueStart) /
    118     (this->current->positionEnd - this->current->positionStart);
     137
     138  PRINT(0)("\n");
     139  this->current = this->first;
    119140}
    120 
  • orxonox/trunk/src/lib/particles/quick_animation.h

    r4415 r4421  
    2828  struct QuickKeyFrame
    2929  {
    30     float valueStart;       //!< The starting value of this KeyFrame
    31     float valueEnd;         //!< The end value of this KeyFrame
    32     float positionStart;    //!< The starting position of this KeyFrame
    33     float positionEnd;      //!< The end position of thies KeyFrame
     30    float value;       //!< The starting value of this KeyFrame
     31    float position;    //!< The end position of thies KeyFrame
    3432
    3533    QuickKeyFrame* next;    //!< The next Animation
    3634  };
    3735
    38   QuickAnimation(float rangeStart = 0.0, float valueStart = 0.0, float rangeEnd = 1.0, float valueEnd = 0.0);
     36  QuickAnimation();
    3937  virtual ~QuickAnimation();
    4038
    41   void addEntry(float position, float value);
     39  bool addEntry(float position, float value);
    4240
    4341  float getValue(float position);
    4442
     43  void debug(void);
    4544 private:
    4645  QuickKeyFrame* first;
    4746  QuickKeyFrame* current;
    48 
    4947};
    5048
Note: See TracChangeset for help on using the changeset viewer.