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

Animation.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 ANIMATION_H_
00026 #define ANIMATION_H_
00027 
00028 namespace Lamp{
00029 
00030 class Scene;
00031 class AnimationSet;
00032 class ObjectAnimation;
00033 class CameraAnimation;
00034 class SceneNodeAnimation;
00035 class CharacterModelAnimation;
00036 
00037 //------------------------------------------------------------------------------
00038 /**
00039  * アニメーション
00040  */
00041 class Animation{
00042 friend class AnimationManager;
00043 public:
00044     //--------------------------------------------------------------------------
00045     /// アニメーションマスク
00046     enum AnimationMask{
00047         /// カメラアニメーション
00048         maskCamera =            1 << 0,
00049         /// シーンノードアニメーション
00050         maskSceneNode =         1 << 1,
00051         /// キャラクタモデルアニメーション
00052         maskCharacterModel =    1 << 2,
00053         /// カリング前アニメーション
00054         maskPreCulling =
00055             maskCamera |
00056             maskSceneNode,
00057         /// カリング後アニメーション
00058         maskPostCulling =
00059             maskCharacterModel,
00060         /// 強制アニメーション
00061         maskForce =
00062             maskCamera |
00063             maskSceneNode |
00064             maskCharacterModel
00065     };
00066 
00067     //--------------------------------------------------------------------------
00068     /// データコピーマスク
00069     enum DataCopyMask{
00070         /// データコピーしない
00071         copyNone =              0,
00072         /// カメラデータコピー
00073         copyCamera =            1 << 0,
00074         /// シーンノードデータコピー
00075         copySceneNode =         1 << 1,
00076         /// キャラクタモデルデータコピー
00077         copyCharacterModel =    1 << 2,
00078     };
00079 
00080     //--------------------------------------------------------------------------
00081     // バインド
00082     //--------------------------------------------------------------------------
00083     /**
00084      * バインド
00085      * @param scene バインド対象シーン
00086      * @return 成功すればtrue
00087      */
00088     virtual bool bind(Scene* scene) = 0;
00089 
00090     /**
00091      * バインド解除
00092      */
00093     virtual void unbind() = 0;
00094 
00095     //--------------------------------------------------------------------------
00096     // シーケンス
00097     //--------------------------------------------------------------------------
00098     /**
00099      * シーケンス数の取得
00100      * @return シーケンス数
00101      */
00102     virtual int getSequenceCount() const = 0;
00103 
00104     /**
00105      * シーケンスの設定
00106      * @param sequence 設定するシーケンス
00107      * @param time 設定する時間
00108      */
00109     virtual void setSequence(int sequence, float time = 0.f) = 0;
00110 
00111     /**
00112      * シーケンスの取得
00113      * @return シーケンス
00114      */
00115     virtual int getSequence() const = 0;
00116 
00117 // ChangeSequenceによるシーケンス補間。何秒で次のシーケンスに完全移行するか指定。
00118 // Rateに対する線形補間やベジェ補間があるといいかも
00119     //--------------------------------------------------------------------------
00120     // 時間
00121     //--------------------------------------------------------------------------
00122     /**
00123      * 時間の設定
00124      * @param time 設定する時間
00125      */
00126     virtual void setTime(float time) = 0;
00127 
00128     /**
00129      * 時間の取得
00130      * @return 時間
00131      */
00132     virtual float getTime() const = 0;
00133 
00134     //--------------------------------------------------------------------------
00135     // アニメーション
00136     //--------------------------------------------------------------------------
00137     /**
00138      * アニメーション
00139      * @param deltaTime デルタタイム
00140      * @param mask アニメーションマスク
00141      * @return アニメーションが終了していればtrue
00142      */
00143     virtual bool animate(float deltaTime, AnimationMask mask) = 0;
00144 
00145     /**
00146      * 終了しているか
00147      * @return 終了していればtrue
00148      */
00149     virtual bool isFinished() const = 0;
00150 
00151     /**
00152      * 長さの取得
00153      * @return 長さ
00154      */
00155     virtual float getLength() const = 0;
00156 
00157     /**
00158      * ループしているか
00159      * @return ループしていればtrue
00160      */
00161     virtual bool isLooped() const = 0;
00162 
00163     //--------------------------------------------------------------------------
00164     // コピー
00165     //--------------------------------------------------------------------------
00166     /**
00167      * コピー
00168      * @param dataCopyMask データコピーマスク
00169      * @return コピーされたアニメーション
00170      */
00171     virtual Animation* copy(DataCopyMask dataCopyMask = copyNone) const = 0;
00172 
00173     //--------------------------------------------------------------------------
00174     // RTTI
00175     //--------------------------------------------------------------------------
00176     /**
00177      * アニメーションセットかどうか
00178      * @return アニメーションセットならtrue
00179      */
00180     virtual bool isAnimationSet() const{ return false; }
00181 
00182     /**
00183      * アニメーションセットへのキャスト
00184      * @return アニメーションセット。型が違えばNULLを返す。
00185      */
00186     virtual AnimationSet* castAnimationSet() const{
00187         if(isAnimationSet()){ return (AnimationSet*)this; }
00188         return NULL;
00189     }
00190 
00191     //--------------------------------------------------------------------------
00192     /**
00193      * オブジェクトアニメーションかどうか
00194      * @return オブジェクトアニメーションならtrue
00195      */
00196     virtual bool isObjectAnimation() const{ return false; }
00197 
00198     /**
00199      * オブジェクトアニメーションへのキャスト
00200      * @return オブジェクトアニメーション。型が違えばNULLを返す。
00201      */
00202     virtual ObjectAnimation* castObjectAnimation() const{
00203         if(isObjectAnimation()){ return (ObjectAnimation*)this; }
00204         return NULL;
00205     }
00206 
00207     //--------------------------------------------------------------------------
00208     /**
00209      * カメラアニメーションかどうか
00210      * @return カメラアニメーションならtrue
00211      */
00212     virtual bool isCameraAnimation() const{ return false; }
00213 
00214     /**
00215      * カメラアニメーションへのキャスト
00216      * @return カメラアニメーション。型が違えばNULLを返す。
00217      */
00218     virtual CameraAnimation* castCameraAnimation() const{
00219         if(isCameraAnimation()){ return (CameraAnimation*)this; }
00220         return NULL;
00221     }
00222 
00223     //--------------------------------------------------------------------------
00224     /**
00225      * シーンノードアニメーションかどうか
00226      * @return シーンノードアニメーションならtrue
00227      */
00228     virtual bool isSceneNodeAnimation() const{ return false; }
00229 
00230     /**
00231      * シーンノードアニメーションへのキャスト
00232      * @return シーンノードアニメーション。型が違えばNULLを返す。
00233      */
00234     virtual SceneNodeAnimation* castSceneNodeAnimation() const{
00235         if(isSceneNodeAnimation()){ return (SceneNodeAnimation*)this; }
00236         return NULL;
00237     }
00238 
00239     //--------------------------------------------------------------------------
00240     /**
00241      * キャラクタモデルアニメーションかどうか
00242      * @return キャラクタモデルアニメーションならtrue
00243      */
00244     virtual bool isCharacterModelAnimation() const{ return false; }
00245 
00246     /**
00247      * キャラクタモデルアニメーションへのキャスト
00248      * @return キャラクタモデルアニメーション。型が違えばNULLを返す。
00249      */
00250     virtual CharacterModelAnimation* castCharacterModelAnimation() const{
00251         if(isCharacterModelAnimation()){
00252             return (CharacterModelAnimation*)this;
00253         }
00254         return NULL;
00255     }
00256 
00257     //--------------------------------------------------------------------------
00258     // 名前
00259     //--------------------------------------------------------------------------
00260     /**
00261      * 名前の取得
00262      * @return 名前
00263      */
00264     virtual const String& getName() const{ return name_; }
00265 
00266     //--------------------------------------------------------------------------
00267     // マネージャ
00268     //--------------------------------------------------------------------------
00269     /**
00270      * マネージャの取得
00271      * @return マネージャ
00272      */
00273     virtual AnimationManager* getManager() const{ return manager_; }
00274 
00275     //--------------------------------------------------------------------------
00276     /**
00277      * 有効、無効の設定
00278      * @param enabled trueなら有効、falseなら無効
00279      */
00280     virtual void setEnabled(bool enabled){ enabled_ = enabled; }
00281 
00282     /**
00283      * 有効、無効の取得
00284      * @return trueなら有効、falseなら無効
00285      */
00286     virtual bool isEnabled() const{ return enabled_; }
00287 
00288     //--------------------------------------------------------------------------
00289 protected:
00290     /**
00291      * コンストラクタ
00292      * @param name 名前
00293      * @param manager アニメーションマネージャ
00294      */
00295     Animation(String name, AnimationManager* manager) :
00296          name_(name), manager_(manager), enabled_(true){}
00297 
00298     /**
00299      * デストラクタ
00300      */
00301     virtual ~Animation(){}
00302 
00303     /**
00304      * 時間の増加
00305      * @param deltaTime デルタタイム
00306      * @return ループ補正された時間
00307      */
00308     float increasesTime(float deltaTime){
00309         float time = getTime();
00310         time += deltaTime;
00311         setTime(time);
00312         if(!isLooped()){ return time; }
00313         return Math::fmod(time, getLength());
00314     }
00315 
00316     //--------------------------------------------------------------------------
00317 private:
00318     // コピーコンストラクタの隠蔽
00319     Animation(const Animation& copy);
00320 
00321     // 代入コピーの隠蔽
00322     void operator =(const Animation& copy);
00323 
00324     // 名前
00325     String name_;
00326     // アニメーションマネージャ
00327     AnimationManager* manager_;
00328     // 有効、無効フラグ
00329     bool enabled_;
00330 
00331 };
00332 
00333 //------------------------------------------------------------------------------
00334 } // End of namespace Lamp
00335 #endif // End of ANIMATION_H_
00336 //------------------------------------------------------------------------------

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