00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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
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
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
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
00190
00191 virtual int getSequenceCount() const{ return sequenceCount_; }
00192
00193
00194
00195
00196
00197
00198
00199
00200 virtual int getBoneCount() const{ return boneCount_; }
00201
00202
00203
00204
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
00220
00221
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
00238
00239
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
00255
00256
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
00273
00274
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
00290
00291
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
00308
00309
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
00322
00323
00324
00325
00326
00327 virtual bool isCharacterModelAnimationData() const{ return true; }
00328
00329
00330 protected:
00331
00332
00333
00334
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
00352
00353
00354 virtual Sequence* getSequence(int sequence){
00355 Assert(sequence >= 0);
00356 Assert(sequence < sequenceCount_);
00357 return &sequences_[sequence];
00358 }
00359
00360
00361
00362
00363
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 }
00384 #endif // End of CHARACTER_MODEL_ANIMATION_DATA_H_
00385