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

CharacterModelAnimationData.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 CHARACTER_MODEL_ANIMATION_DATA_H_
00026 #define CHARACTER_MODEL_ANIMATION_DATA_H_
00027 
00028 #include <Animation/System/AnimationData.h>
00029 #include <Animation/VectorInterpolator/VectorInterpolator.h>
00030 #include <Animation/RotationInterpolator/RotationInterpolator.h>
00031 
00032 namespace Lamp{
00033 
00034 //------------------------------------------------------------------------------
00035 /**
00036  * キャラクタモデルアニメーションデータ
00037  */
00038 class CharacterModelAnimationData : public AnimationData{
00039 friend class AnimationManager;
00040 protected:
00041     //--------------------------------------------------------------------------
00042     /**
00043      * キャラクタモデルシーケンス
00044      */
00045     class CharacterModelSequence : public Sequence{
00046     public:
00047         /**
00048          * コンストラクタ
00049          */
00050         CharacterModelSequence() : Sequence(),
00051             boneCount_(0), scale_(NULL), rotation_(NULL), translation_(NULL){}
00052 
00053         /**
00054          * デストラクタ
00055          */
00056         virtual ~CharacterModelSequence(){ clear(); }
00057 
00058         /**
00059          * 代入コピー
00060          * @param copy コピー元
00061          */
00062         virtual void operator =(const CharacterModelSequence& copy){
00063             Sequence::operator=(copy);
00064             int boneCount = copy.boneCount_;
00065             setBoneCount(boneCount);
00066             for(int i = 0; i < boneCount; i++){
00067                 if(copy.scale_[i] != NULL){
00068                     scale_[i] = copy.scale_[i]->duplicate();
00069                 }
00070                 if(copy.rotation_[i] != NULL){
00071                     rotation_[i] = copy.rotation_[i]->duplicate();
00072                 }
00073                 if(copy.translation_[i] != NULL){
00074                     translation_[i] = copy.translation_[i]->duplicate();
00075                 }
00076             }
00077         }
00078 
00079         /**
00080          * 長さの計算
00081          */
00082         virtual void calcLength(){
00083             // ロード時のボトルネックになる可能性有り
00084             // calcLength()を明示的に呼ぶようにするか、配列によるデータ設定か
00085             length_ = 0.f;
00086             for(int i = 0; i < boneCount_; i++){
00087                 if((scale_[i] != NULL) &&
00088                     (scale_[i]->getLength() > length_)){
00089                     length_ = scale_[i]->getLength();
00090                 }
00091             }
00092             for(int i = 0; i < boneCount_; i++){
00093                 if((rotation_[i] != NULL) &&
00094                     (rotation_[i]->getLength() > length_)){
00095                     length_ = rotation_[i]->getLength();
00096                 }
00097             }
00098             for(int i = 0; i < boneCount_; i++){
00099                 if((translation_[i] != NULL) &&
00100                     (translation_[i]->getLength() > length_)){
00101                     length_ = translation_[i]->getLength();
00102                 }
00103             }
00104         }
00105 
00106         /**
00107          * ボーン数の設定
00108          * @param boneCount ボーン数
00109          */
00110         virtual void setBoneCount(int boneCount){
00111             clear();
00112             boneCount_ = boneCount;
00113             if(boneCount_ != 0){
00114                 int size = sizeof(VectorInterpolator*) * boneCount_;
00115                 scale_ = new VectorInterpolator*[boneCount_];
00116                 ::memset(scale_, 0, size);
00117                 rotation_ = new RotationInterpolator*[boneCount_];
00118                 ::memset(rotation_, 0, size);
00119                 translation_ = new VectorInterpolator*[boneCount_];
00120                 ::memset(translation_, 0, size);
00121             }
00122         }
00123 
00124         /**
00125          * クリア
00126          */
00127         virtual void clear(){
00128             for(int i = boneCount_ - 1; i >= 0; i--){
00129                 SafeDelete(translation_[i]);
00130                 SafeDelete(rotation_[i]);
00131                 SafeDelete(scale_[i]);
00132             }
00133             SafeArrayDelete(translation_);
00134             SafeArrayDelete(rotation_);
00135             SafeArrayDelete(scale_);
00136             boneCount_ = 0;
00137         }
00138 
00139         //----------------------------------------------------------------------
00140         /// ボーン数
00141         int boneCount_;
00142         /// スケール
00143         VectorInterpolator** scale_;
00144         /// 回転
00145         RotationInterpolator** rotation_;
00146         /// 移動
00147         VectorInterpolator** translation_;
00148 
00149     };
00150 
00151 public:
00152     //--------------------------------------------------------------------------
00153     // コピー
00154     //--------------------------------------------------------------------------
00155     /**
00156      * コピー
00157      * @return コピーされたアニメーションデータ
00158      */
00159     virtual AnimationData* copy() const{
00160         return copyCharacterModelAnimationData();
00161     }
00162 
00163     /**
00164      * キャラクタモデルアニメーションデータのコピー
00165      */
00166     virtual CharacterModelAnimationData*
00167         copyCharacterModelAnimationData() const;
00168 
00169     //--------------------------------------------------------------------------
00170     // シーケンス
00171     //--------------------------------------------------------------------------
00172     /**
00173      * シーケンス数の設定
00174      * @param sequenceCount シーケンス数
00175      */
00176     virtual void setSequenceCount(int sequenceCount){
00177         SafeArrayDelete(sequences_);
00178         sequenceCount_ = sequenceCount;
00179         if(sequenceCount_ == 0){ return; }
00180         sequences_ = new CharacterModelSequence[sequenceCount_];
00181         if(boneCount_ == 0){ return; }
00182         for(int i = 0; i < sequenceCount; i++){
00183             sequences_[i].setBoneCount(boneCount_);
00184         }
00185     }
00186 
00187     /**
00188      * シーケンス数の取得
00189      * @return シーケンス数
00190      */
00191     virtual int getSequenceCount() const{ return sequenceCount_; }
00192 
00193     //--------------------------------------------------------------------------
00194     // ボーン
00195     //--------------------------------------------------------------------------
00196     /**
00197      * ボーン数の取得
00198      * @return ボーン数
00199      */
00200     virtual int getBoneCount() const{ return boneCount_; }
00201 
00202     /**
00203      * ボーン数の設定
00204      * @param boneCount ボーン数
00205      */
00206     virtual void setBoneCount(int boneCount){
00207         if(boneCount_ == boneCount){ return; }
00208         boneCount_ = boneCount;
00209         for(int i = 0; i < sequenceCount_; i++){
00210             sequences_[i].setBoneCount(boneCount_);
00211         }
00212     }
00213 
00214     //--------------------------------------------------------------------------
00215     // スケール
00216     //--------------------------------------------------------------------------
00217     /**
00218      * スケールの設定
00219      * @param sequence シーケンス
00220      * @param index ボーンのインデックス
00221      * @param scale 設定するスケール
00222      */
00223     virtual void setScale(
00224         int sequence, int index, VectorInterpolator* scale){
00225         Assert(sequence >= 0);
00226         Assert(sequence < sequenceCount_);
00227         Assert(index >= 0);
00228         Assert(index < boneCount_);
00229         CharacterModelSequence& data = sequences_[sequence];
00230         SafeDelete(data.scale_[index]);
00231         data.scale_[index] = scale;
00232         data.calcLength();
00233     }
00234 
00235     /**
00236      * スケールの取得
00237      * @param sequence シーケンス
00238      * @param index ボーンのインデックス
00239      * @return スケール
00240      */
00241     virtual VectorInterpolator* getScale(int sequence, int index) const{
00242         Assert(sequence >= 0);
00243         Assert(sequence < sequenceCount_);
00244         Assert(index >= 0);
00245         Assert(index < boneCount_);
00246         return sequences_[sequence].scale_[index];
00247     }
00248 
00249     //--------------------------------------------------------------------------
00250     // 回転
00251     //--------------------------------------------------------------------------
00252     /**
00253      * 回転の設定
00254      * @param sequence シーケンス
00255      * @param index ボーンのインデックス
00256      * @param rotation 設定する回転
00257      */
00258     virtual void setRotation(
00259         int sequence, int index, RotationInterpolator* rotation){
00260         Assert(sequence >= 0);
00261         Assert(sequence < sequenceCount_);
00262         Assert(index >= 0);
00263         Assert(index < boneCount_);
00264         CharacterModelSequence& data = sequences_[sequence];
00265         SafeDelete(data.rotation_[index]);
00266         data.rotation_[index] = rotation;
00267         data.calcLength();
00268     }
00269 
00270     /**
00271      * 回転の取得
00272      * @param sequence シーケンス
00273      * @param index ボーンのインデックス
00274      * @return 回転
00275      */
00276     virtual RotationInterpolator* getRotation(int sequence, int index) const{
00277         Assert(sequence >= 0);
00278         Assert(sequence < sequenceCount_);
00279         Assert(index >= 0);
00280         Assert(index < boneCount_);
00281         return sequences_[sequence].rotation_[index];
00282     }
00283 
00284     //--------------------------------------------------------------------------
00285     // 移動
00286     //--------------------------------------------------------------------------
00287     /**
00288      * 移動の設定
00289      * @param sequence シーケンス
00290      * @param index ボーンのインデックス
00291      * @param translation 設定する移動
00292      */
00293     virtual void setTranslation(
00294         int sequence, int index, VectorInterpolator* translation){
00295         Assert(sequence >= 0);
00296         Assert(sequence < sequenceCount_);
00297         Assert(index >= 0);
00298         Assert(index < boneCount_);
00299         CharacterModelSequence& data = sequences_[sequence];
00300         SafeDelete(data.translation_[index]);
00301         data.translation_[index] = translation;
00302         data.calcLength();
00303     }
00304 
00305     /**
00306      * 移動の取得
00307      * @param sequence シーケンス
00308      * @param index ボーンのインデックス
00309      * @return 移動
00310      */
00311     virtual VectorInterpolator* getTranslation(
00312         int sequence, int index) const{
00313         Assert(sequence >= 0);
00314         Assert(sequence < sequenceCount_);
00315         Assert(index >= 0);
00316         Assert(index < boneCount_);
00317         return sequences_[sequence].translation_[index];
00318     }
00319 
00320     //--------------------------------------------------------------------------
00321     // RTTI
00322     //--------------------------------------------------------------------------
00323     /**
00324      * キャラクタモデルアニメーションデータかどうか
00325      * @return キャラクタモデルアニメーションデータならtrue
00326      */
00327     virtual bool isCharacterModelAnimationData() const{ return true; }
00328 
00329     //--------------------------------------------------------------------------
00330 protected:
00331     /**
00332      * コンストラクタ
00333      * @param name 名前
00334      * @param manager アニメーションマネージャ
00335      */
00336     CharacterModelAnimationData(
00337         const String& name, AnimationManager* manager) :
00338         AnimationData(name, manager),
00339         sequenceCount_(0), sequences_(NULL), boneCount_(0){}
00340 
00341     /**
00342      * デストラクタ
00343      */
00344     virtual ~CharacterModelAnimationData(){
00345         SafeArrayDelete(sequences_);
00346     }
00347 
00348     //--------------------------------------------------------------------------
00349     /**
00350      * シーケンスの取得
00351      * @param sequence シーケンス
00352      * @return シーケンス
00353      */
00354     virtual Sequence* getSequence(int sequence){
00355         Assert(sequence >= 0);
00356         Assert(sequence < sequenceCount_);
00357         return &sequences_[sequence];
00358     }
00359 
00360     /**
00361      * シーケンスの取得
00362      * @param sequence シーケンス
00363      * @return シーケンス
00364      */
00365     virtual const Sequence* getSequence(int sequence) const{
00366         Assert(sequence >= 0);
00367         Assert(sequence < sequenceCount_);
00368         return &sequences_[sequence];
00369     }
00370 
00371     //--------------------------------------------------------------------------
00372 private:
00373     // シーケンス数
00374     int sequenceCount_;
00375     // シーケンス
00376     CharacterModelSequence* sequences_;
00377     // ボーン数
00378     int boneCount_;
00379 
00380 };
00381 
00382 //------------------------------------------------------------------------------
00383 } // End of namespace Lamp
00384 #endif // End of CHARACTER_MODEL_ANIMATION_DATA_H_
00385 //------------------------------------------------------------------------------

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