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