/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: ... co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "quick_animation.h" #include "compiler.h" #include "debug.h" #ifndef NULL #define NULL 0 #endif using namespace std; /** \brief standard constructor */ QuickAnimation::QuickAnimation (void) { this->setClassName("QuickAnimation"); this->first = this->current = NULL; } /** \brief standard deconstructor */ QuickAnimation::~QuickAnimation (void) { this->current = this->first; QuickKeyFrame delKF; while (this->current != NULL) { this->first = this->current->next; delete this->current; this->current = this->first; } } /** \brief adds a new entry to the list of keyframes \param position the position to add the key to \param value the Value to set for the position \returns false if the key existed already for a given position */ bool QuickAnimation::addEntry(float position, float value) { this->current = this->first; while (this->current != NULL) { // if it is between some keyframes if ((!this->current->next && this->current->position < position) || (this->current->position < position && this->current->next->position > position)) break; // if it is the same as an already existing keyframe else if (this->current->position == position) return false; this->current = this->current->next; } QuickKeyFrame* newKey = new QuickKeyFrame; if (this->first == NULL) { this->first = newKey; this->current = newKey; newKey->next = NULL; } else { newKey->next = this->current->next; this->current->next = newKey; } newKey->value = value; newKey->position = position; this->current = this->first; } /** \brief returns the value of the animation at a certain position \param position the position to get the value from :) */ float QuickAnimation::getValue(float position) { if (unlikely(this->first == NULL)) return 0.0; else if (unlikely (this->first->next == NULL)) return this->first->value; else { if (unlikely(position < this->current->position)) { if (position <= this->first->position) return this->first->value; this->current = this->first; } while (likely(this->current->next != NULL && position > this->current->next->position)) this->current = this->current->next; if (this->current->next == NULL) return this->current->value; return this->current->value + (this->current->next->value - this->current->value) * ((position-this->current->position) / (this->current->next->position -this->current->position)); } } void QuickAnimation::debug(void) { this->current = this->first; PRINT(0)("QuickAnim:: (position, value)"); while(this->current) { PRINT(0)("->(%f, %f)", this->current->position, this->current->value); this->current = this->current->next; } PRINT(0)("\n"); this->current = this->first; }