Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

QuaternionLinearInterpolator.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 四元数回転線形補間ヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef QUATERNION_LINEAR_INTERPOLATOR_H_
00026 #define QUATERNION_LINEAR_INTERPOLATOR_H_
00027 
00028 #include <Animation/RotationInterpolator/RotationInterpolator.h>
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * 四元数回転線形補間
00035  */
00036 class QuaternionLinearInterpolator : public RotationInterpolator{
00037 public:
00038     //--------------------------------------------------------------------------
00039     /**
00040      * コンストラクタ
00041      */
00042     QuaternionLinearInterpolator();
00043 
00044     /**
00045      * デストラクタ
00046      */
00047     virtual ~QuaternionLinearInterpolator();
00048 
00049     /**
00050      * コピーコンストラクタ
00051      * @param copy コピー元
00052      */
00053     explicit QuaternionLinearInterpolator(
00054         const QuaternionLinearInterpolator& copy);
00055 
00056     /**
00057      * 代入演算子
00058      * @param copy 代入元
00059      */
00060     virtual QuaternionLinearInterpolator& operator =(
00061         const QuaternionLinearInterpolator& copy);
00062 
00063     //--------------------------------------------------------------------------
00064     /**
00065      * 複製
00066      * @return 複製されたベクトル補間。呼び出し元でdeleteする必要がある
00067      */
00068     virtual RotationInterpolator* duplicate() const{
00069         RotationInterpolator* result = new QuaternionLinearInterpolator(*this);
00070         return result;
00071     }
00072 
00073     //--------------------------------------------------------------------------
00074     /**
00075      * 同じ値かどうか
00076      * @param target 比較対象
00077      * @return 同じ値ならtrueをかえす
00078      */
00079     virtual bool equals(const RotationInterpolator& target) const{
00080         QuaternionLinearInterpolator* interpolator =
00081             target.castQuaternionLinearInterpolator();
00082         if(interpolator == NULL){ return false; }
00083         if(keyCount_ != interpolator->keyCount_){ return false; }
00084         for(int i = 0; i < keyCount_; i++){
00085             const Key& key = keys_[i];
00086             const Key& targetKey = interpolator->keys_[i];
00087             if(key.value_ != targetKey.value_){ return false; }
00088             if(key.time_ != targetKey.time_){ return false; }
00089         }
00090         return true;
00091     }
00092 
00093     //--------------------------------------------------------------------------
00094     // 長さ
00095     //--------------------------------------------------------------------------
00096     /**
00097      * 長さの取得
00098      * @return 長さ
00099      */
00100     virtual float getLength() const;
00101 
00102     //--------------------------------------------------------------------------
00103     // オイラー補間
00104     //--------------------------------------------------------------------------
00105     /**
00106      * オイラー補間かどうか
00107      * @return オイラー補間ならtrue
00108      */
00109     virtual bool isEulerInterpolator() const{ return true; }
00110 
00111     /**
00112      * オイラー補間
00113      * @param time 時間
00114      * @return 補間された回転
00115      */
00116     virtual Vector3 eulerInterpolate(float time);
00117 
00118     //--------------------------------------------------------------------------
00119     // 四元数補間
00120     //--------------------------------------------------------------------------
00121     /**
00122      * 四元数補間かどうか
00123      * @return 四元数補間ならtrue
00124      */
00125     virtual bool isQuaternionInterpolator() const{ return true; }
00126 
00127     /**
00128      * 四元数補間
00129      * @param time 時間
00130      * @return 補間された回転
00131      */
00132     virtual Quaternion quaternionInterpolate(float time);
00133 
00134     //--------------------------------------------------------------------------
00135     // キー
00136     //--------------------------------------------------------------------------
00137     /**
00138      * キー数の設定
00139      * @param keyCount キー数
00140      */
00141     virtual void setKeyCount(int keyCount);
00142 
00143     /**
00144      * キー数の取得
00145      * @return キー数
00146      */
00147     virtual int getKeyCount() const{ return keyCount_; }
00148 
00149     //--------------------------------------------------------------------------
00150     /**
00151      * キーの設定
00152      * @param index キーインデックス
00153      * @param time 時間
00154      * @param value 値
00155      */
00156     virtual void setKey(int index, float time, const Quaternion& value){
00157         Assert((index >= 0) && (index < keyCount_) && (keys_ != NULL));
00158         Key& key = keys_[index];
00159         key.value_ = value;
00160         key.time_ = time;
00161     }
00162 
00163     /**
00164      * 値の取得
00165      * @param index キーインデックス
00166      * @return 値
00167      */
00168     virtual const Quaternion& getValue(int index) const{
00169         Assert((index >= 0) && (index < keyCount_) && (keys_ != NULL));
00170         return keys_[index].value_;
00171     }
00172 
00173     /**
00174      * 時間の取得
00175      * @param index キーインデックス
00176      * @return 時間
00177      */
00178     virtual float getTime(int index) const{
00179         Assert((index >= 0) && (index < keyCount_) && (keys_ != NULL));
00180         return keys_[index].time_;
00181     }
00182 
00183     //--------------------------------------------------------------------------
00184     // RTTI
00185     //--------------------------------------------------------------------------
00186     /**
00187      * 四元数回転線形補間かどうか
00188      * @return 四元数回転線形補間ならtrue
00189      */
00190     virtual bool isQuaternionLinearInterpolator() const{ return true; }
00191 
00192     //--------------------------------------------------------------------------
00193 private:
00194     /// キー
00195     class Key{
00196     friend class QuaternionLinearInterpolator;
00197     private:
00198         /// 値
00199         Quaternion value_;
00200         /// 時間
00201         float time_;
00202     };
00203 
00204     // キー
00205     Key* keys_;
00206     // キーの数
00207     int keyCount_;
00208     // 最後に使用したキーインデックス
00209     int lastestUseKeyIndex_;
00210 
00211 };
00212 
00213 //------------------------------------------------------------------------------
00214 } // End of namespace Lamp
00215 #endif // End of QUATERNION_LINEAR_INTERPOLATOR_H_
00216 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:34 2005 for Lamp by doxygen 1.3.2