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 OBJECT_ANIMATION_H_ 00026 #define OBJECT_ANIMATION_H_ 00027 00028 #include <Animation/System/Animation.h> 00029 #include <Animation/System/AnimationData.h> 00030 00031 namespace Lamp{ 00032 00033 //------------------------------------------------------------------------------ 00034 /** 00035 * オブジェクトアニメーション 00036 */ 00037 class ObjectAnimation : public Animation{ 00038 public: 00039 //-------------------------------------------------------------------------- 00040 // アニメーションデータ 00041 //-------------------------------------------------------------------------- 00042 /** 00043 * アニメーションデータの取得 00044 * @return アニメーションデータ 00045 */ 00046 virtual AnimationData* getAnimationData() = 0; 00047 00048 /** 00049 * アニメーションデータの取得 00050 * @return アニメーションデータ 00051 */ 00052 virtual const AnimationData* getAnimationData() const = 0; 00053 00054 //-------------------------------------------------------------------------- 00055 // ターゲット名 00056 //-------------------------------------------------------------------------- 00057 /** 00058 * ターゲット名の設定 00059 * @param targetName 設定するターゲット名 00060 */ 00061 virtual void setTargetName(const String& targetName){ 00062 targetName_ = targetName; 00063 } 00064 00065 /** 00066 * ターゲット名の取得 00067 * @return ターゲット名 00068 */ 00069 virtual const String& getTargetName() const{ return targetName_; } 00070 00071 //-------------------------------------------------------------------------- 00072 // シーケンス 00073 //-------------------------------------------------------------------------- 00074 /** 00075 * シーケンス数の取得 00076 * @return シーケンス数 00077 */ 00078 virtual int getSequenceCount() const{ 00079 const AnimationData* data = getAnimationData(); 00080 if(data == NULL){ return 0; } 00081 return data->getSequenceCount(); 00082 } 00083 00084 /** 00085 * シーケンスの設定 00086 * @param sequence 設定するシーケンス 00087 * @param time 設定する時間 00088 */ 00089 virtual void setSequence(int sequence, float time = 0.f){ 00090 Assert(sequence >= 0); 00091 Assert((sequence == 0) || (sequence < getSequenceCount())); 00092 sequence_ = sequence; 00093 setTime(time); 00094 } 00095 00096 /** 00097 * シーケンスの取得 00098 * @return シーケンス 00099 */ 00100 virtual int getSequence() const{ return sequence_; } 00101 00102 //-------------------------------------------------------------------------- 00103 // 時間 00104 //-------------------------------------------------------------------------- 00105 /** 00106 * 時間の設定 00107 * @param time 設定する時間 00108 */ 00109 virtual void setTime(float time){ time_ = time; } 00110 00111 /** 00112 * 時間の取得 00113 * @return 時間 00114 */ 00115 virtual float getTime() const{ return time_; } 00116 00117 //-------------------------------------------------------------------------- 00118 // アニメーション 00119 //-------------------------------------------------------------------------- 00120 /** 00121 * 終了しているか 00122 * @return 終了していればtrue 00123 */ 00124 virtual bool isFinished() const{ 00125 if(getAnimationData() == NULL){ return true; } 00126 // ループアニメーションはシーケンスが一周すれば終了フラグが立つ 00127 return (getTime() >= getLength()); 00128 } 00129 00130 /** 00131 * 長さの取得 00132 * @return 長さ 00133 */ 00134 virtual float getLength() const{ 00135 const AnimationData* data = getAnimationData(); 00136 if(data == NULL){ return 0.f; } 00137 return data->getLength(getSequence()); 00138 } 00139 00140 /** 00141 * ループしているか 00142 * @return ループしていればtrue 00143 */ 00144 virtual bool isLooped() const{ 00145 const AnimationData* data = getAnimationData(); 00146 if(data == NULL){ return false; } 00147 return data->isLooped(getSequence()); 00148 } 00149 00150 //-------------------------------------------------------------------------- 00151 // RTTI 00152 //-------------------------------------------------------------------------- 00153 /** 00154 * オブジェクトアニメーションかどうか 00155 * @return オブジェクトアニメーションならtrue 00156 */ 00157 virtual bool isObjectAnimation() const{ return true; } 00158 00159 //-------------------------------------------------------------------------- 00160 protected: 00161 /** 00162 * コンストラクタ 00163 * @param name 名前 00164 * @param manager アニメーションマネージャ 00165 */ 00166 ObjectAnimation(String name, AnimationManager* manager) : 00167 Animation(name, manager), sequence_(0), time_(0.f){} 00168 00169 /** 00170 * デストラクタ 00171 */ 00172 virtual ~ObjectAnimation(){} 00173 00174 //-------------------------------------------------------------------------- 00175 /** 00176 * オブジェクトアニメーションの値コピー 00177 * @param destination コピー対象 00178 */ 00179 virtual void copyObjectAnimationValue( 00180 ObjectAnimation* destination) const{ 00181 destination->setEnabled(isEnabled()); 00182 destination->setTargetName(getTargetName()); 00183 destination->setSequence(getSequence()); 00184 destination->setTime(getTime()); 00185 } 00186 00187 private: 00188 // ターゲット名 00189 String targetName_; 00190 // シーケンス 00191 int sequence_; 00192 // 時間 00193 float time_; 00194 00195 }; 00196 00197 //------------------------------------------------------------------------------ 00198 } // End of namespace Lamp 00199 #endif // End of OBJECT_ANIMATION_H_ 00200 //------------------------------------------------------------------------------