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_ARRAY_INTERPOLATOR_H_ 00026 #define QUATERNION_ARRAY_INTERPOLATOR_H_ 00027 00028 #include <Animation/RotationInterpolator/RotationInterpolator.h> 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * 四元数回転配列補間 00035 */ 00036 class QuaternionArrayInterpolator : public RotationInterpolator{ 00037 public: 00038 //-------------------------------------------------------------------------- 00039 /** 00040 * コンストラクタ 00041 */ 00042 QuaternionArrayInterpolator(); 00043 00044 /** 00045 * デストラクタ 00046 */ 00047 virtual ~QuaternionArrayInterpolator(); 00048 00049 /** 00050 * コピーコンストラクタ 00051 * @param copy コピー元 00052 */ 00053 explicit QuaternionArrayInterpolator( 00054 const QuaternionArrayInterpolator& copy); 00055 00056 /** 00057 * 代入演算子 00058 * @param copy 代入元 00059 */ 00060 virtual QuaternionArrayInterpolator& operator =( 00061 const QuaternionArrayInterpolator& copy); 00062 00063 //-------------------------------------------------------------------------- 00064 /** 00065 * 複製 00066 * @return 複製されたオイラー回転補間。呼び出し元でdeleteする必要がある 00067 */ 00068 virtual RotationInterpolator* duplicate() const{ 00069 RotationInterpolator* result = 00070 new QuaternionArrayInterpolator(*this); 00071 return result; 00072 } 00073 00074 //-------------------------------------------------------------------------- 00075 /** 00076 * 同じ値かどうか 00077 * @param target 比較対象 00078 * @return 同じ値ならtrueをかえす 00079 */ 00080 virtual bool equals(const RotationInterpolator& target) const{ 00081 QuaternionArrayInterpolator* interpolator = 00082 target.castQuaternionArrayInterpolator(); 00083 if(interpolator == NULL){ return false; } 00084 if(size_ != interpolator->size_){ return false; } 00085 for(int i = 0; i < size_; i++){ 00086 if(array_[i] != interpolator->array_[i]){ return false; } 00087 } 00088 return true; 00089 } 00090 00091 //-------------------------------------------------------------------------- 00092 /** 00093 * 長さの取得 00094 * @return 長さ 00095 */ 00096 virtual float getLength() const{ return length_; } 00097 00098 //-------------------------------------------------------------------------- 00099 // オイラー補間 00100 //-------------------------------------------------------------------------- 00101 /** 00102 * オイラー補間かどうか 00103 * @return オイラー補間ならtrue 00104 */ 00105 virtual bool isEulerInterpolator() const{ return true; } 00106 00107 /** 00108 * オイラー補間 00109 * @param time 時間 00110 * @return 補間された回転 00111 */ 00112 virtual Vector3 eulerInterpolate(float time); 00113 00114 //-------------------------------------------------------------------------- 00115 // 四元数補間 00116 //-------------------------------------------------------------------------- 00117 /** 00118 * 四元数補間かどうか 00119 * @return 四元数補間ならtrue 00120 */ 00121 virtual bool isQuaternionInterpolator() const{ return true; } 00122 00123 /** 00124 * 四元数補間 00125 * @param time 時間 00126 * @return 補間された回転 00127 */ 00128 virtual Quaternion quaternionInterpolate(float time); 00129 00130 //-------------------------------------------------------------------------- 00131 // 値 00132 //-------------------------------------------------------------------------- 00133 /** 00134 * サイズ設定 00135 * @param size 設定するサイズ。サイズ - 1がLengthになる。 00136 */ 00137 virtual void setSize(int size); 00138 00139 /** 00140 * サイズ取得 00141 * @return サイズ 00142 */ 00143 virtual int getSize() const{ return size_; } 00144 00145 //-------------------------------------------------------------------------- 00146 /** 00147 * 値の設定 00148 * @param index 設定する値のインデックス 00149 * @param value 設定する値 00150 */ 00151 virtual void setValue(int index, const Quaternion& value); 00152 00153 /** 00154 * 値の補正 00155 */ 00156 virtual void correctValue(); 00157 00158 /** 00159 * 値の取得 00160 * @param index 取得する値のインデックス 00161 * @return 値 00162 */ 00163 virtual const Quaternion& getValue(int index) const{ 00164 Assert(array_ != NULL); 00165 Assert(index >= 0); 00166 Assert(index < size_); 00167 return array_[index]; 00168 } 00169 00170 //-------------------------------------------------------------------------- 00171 // 変換 00172 //-------------------------------------------------------------------------- 00173 /** 00174 * オイラー回転配列補間への変換 00175 * @return オイラー回転配列補間、呼び出し元で破棄する必要がある 00176 */ 00177 EulerArrayInterpolator* convertEulerArrayInterpolator() const; 00178 00179 //-------------------------------------------------------------------------- 00180 // RTTI 00181 //-------------------------------------------------------------------------- 00182 /** 00183 * 四元数回転配列補間かどうか 00184 * @return 四元数回転配列補間ならtrue 00185 */ 00186 virtual bool isQuaternionArrayInterpolator() const{ return true; } 00187 00188 //-------------------------------------------------------------------------- 00189 private: 00190 // 配列 00191 Quaternion* array_; 00192 // サイズ 00193 int size_; 00194 // 長さ 00195 float length_; 00196 00197 }; 00198 00199 //------------------------------------------------------------------------------ 00200 } // End of namespace Lamp 00201 #endif // End of QUATERNION_ARRAY_INTERPOLATOR_H_ 00202 //------------------------------------------------------------------------------ 00203