interpolator.h

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software 
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00010 /*!****************************************************************************
00011  * \file    interpolator.h
00012  * \author  Raj Sharma, roos@allacrost.org
00013  * \brief   Header file for Interpolator class
00014  *
00015  * The Interpolator class can interpolate between a single and final value
00016  * using various methods (linear, fast, slow, etc.)
00017  *****************************************************************************/ 
00018 
00019 #ifndef __INTERPOLATOR_HEADER__
00020 #define __INTERPOLATOR_HEADER__
00021 
00022 #include "defs.h"
00023 #include "utils.h"
00024 
00025 namespace hoa_video
00026 {
00027 
00028 
00029 /*!***************************************************************************
00030  *  \brief Interpolation metods are various ways to create smoothed values
00031  *         between two numbers, e.g. linear interpolation
00032  *****************************************************************************/
00033 
00034 enum InterpolationMethod
00035 {
00036   VIDEO_INTERPOLATE_INVALID = -1,
00037   
00039   VIDEO_INTERPOLATE_EASE = 0,
00041   VIDEO_INTERPOLATE_SRCA = 1,
00043   VIDEO_INTERPOLATE_SRCB = 2,
00045   VIDEO_INTERPOLATE_FAST = 3,
00047   VIDEO_INTERPOLATE_SLOW = 4,
00049   VIDEO_INTERPOLATE_LINEAR = 5,
00050   
00051   VIDEO_INTERPOLATE_TOTAL = 6
00052 };
00053 
00054 
00055 /*!***************************************************************************
00056  *  \brief class that lets you set up various kinds of interpolations.
00057  *         The basic way to use it is to set the interpolation method using
00058  *         SetMethod(), then call Start() with the values you want to
00059  *         interpolate between and the time to do it in.
00060  *****************************************************************************/
00061  
00062 class Interpolator
00063 {
00064 public:
00065 
00066   /*!***************************************************************************
00067   *  \brief Constructor
00068   *****************************************************************************/
00069   Interpolator();
00070 
00071   /*!***************************************************************************
00072   *  \brief Begins interpolation
00073   * \param a start value of interpolation
00074   * \param b end value of interpolation
00075   * \param milliseconds amount of time to interpolate over
00076   * \return success/failure
00077   *****************************************************************************/
00078   bool Start(float a, float b, int32 milliseconds);
00079 
00080   /*!***************************************************************************
00081   *  \brief Sets the interpolation method.  If this is not called, VIDEO_INTERPOLATION_LINEAR
00082   *      is assumed
00083   * \param method interpolation method to use
00084   * \return success/failure
00085   *****************************************************************************/
00086   bool  SetMethod(InterpolationMethod method);
00087   
00088   /*!***************************************************************************
00089   *  \brief Gets the current interpolated value
00090   * \return the current interpolated value
00091   *****************************************************************************/
00092   float GetValue();
00093   
00094   /*!***************************************************************************
00095   *  \brief Increments time by frameTime and updates the interpolation
00096   * \param frame_time amount to update the time value by
00097   * \return success/failure
00098   *****************************************************************************/
00099   bool  Update(int32 frame_time);
00100   
00101   /*!***************************************************************************
00102   *  \brief Is interpolation finished?
00103   * \return true if done, false if not
00104   *****************************************************************************/
00105   bool  IsFinished();
00106 
00107 private:
00108 
00109   /*!***************************************************************************
00110   *  \brief Interpolates logarithmically.  Increases quickly then levels off.
00111   * \param t float value to interpolate
00112   * \return interpolated value
00113   *****************************************************************************/
00114   float _FastTransform(float t);
00115   
00116   /*!***************************************************************************
00117   *  \brief Interpolates exponentially.  Increases slowly then skyrockets.
00118   * \param t float value to interpolate
00119   * \return interpolated value
00120   *****************************************************************************/
00121   float _SlowTransform(float t);
00122   
00123   /*!***************************************************************************
00124   *  \brief Interpolates periodically.  Increases slowly to 1.0 then back down to 0.0
00125   * \param t float value to interpolate
00126   * \return interpolated value
00127   *****************************************************************************/
00128   float _EaseTransform(float t);
00129 
00130   /*!***************************************************************************
00131   *  \brief Verifies the interpolation method is valid.
00132   * \return true for valid, false for not
00133   *****************************************************************************/
00134   bool _ValidMethod();
00135   
00137   InterpolationMethod _method;
00138   
00140   float _a, _b;
00141   
00143   int32   _current_time;
00144   
00146   int32   _end_time;
00147   
00149   bool  _finished;
00150   
00152   float _current_value;
00153   
00154 }; // class Interpolator
00155 
00156 }  // namespace hoa_video
00157 
00158 #endif // !__INTERPOLATOR_HEADER__

Generated on Fri Jul 6 23:11:16 2007 for Hero of Allacrost by  doxygen 1.5.1