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

CameraAnimation.cpp

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 #include "LampBasic.h"
00026 #include "Animation/Camera/CameraAnimation.h"
00027 #include "Animation/System/AnimationManager.h"
00028 #include "Graphics/Scene/Scene.h"
00029 #include "Graphics/Camera/CameraManager.h"
00030 
00031 namespace Lamp{
00032 
00033 //------------------------------------------------------------------------------
00034 // コンストラクタ
00035 CameraAnimation::CameraAnimation(String name, AnimationManager* manager) :
00036     ObjectAnimation(name, manager), animationData_(NULL), target_(NULL){
00037 }
00038 //------------------------------------------------------------------------------
00039 // デストラクタ
00040 CameraAnimation::~CameraAnimation(){
00041 }
00042 //------------------------------------------------------------------------------
00043 // バインド
00044 bool CameraAnimation::bind(Scene* scene){
00045     // ターゲット名が指定されていなければ失敗する
00046     if(getTargetName().getSize() == 0){ return false; }
00047     // カメラの検索
00048     Camera* camera =
00049         scene->getCameraManager()->search(getTargetName());
00050     if(camera == NULL){ return false; }
00051     target_ = camera;
00052     return true;
00053 }
00054 //------------------------------------------------------------------------------
00055 // バインド
00056 bool CameraAnimation::bind(Camera* camera){
00057     if(camera == NULL){ return false; }
00058     setTargetName(camera->getName());
00059     target_ = camera;
00060     return true;
00061 }
00062 //------------------------------------------------------------------------------
00063 // アニメーション
00064 bool CameraAnimation::animate(float deltaTime, AnimationMask mask){
00065     // 条件チェック
00066     if((mask & maskCamera) == 0){ return true; }
00067     if(!isEnabled()){ return true; } 
00068     if(animationData_ == NULL){ return true; }
00069     if(target_ == NULL){ return true; }
00070 
00071     // アニメーション
00072     int sequence = getSequence();
00073     float correctTime = increasesTime(deltaTime);
00074     CameraAnimationData* data = getCameraAnimationData();
00075     // 回転、移動
00076     RotationInterpolator* rotationInterpolator = data->getRotation(sequence);
00077     VectorInterpolator* translationInterpolator =
00078         data->getTranslation(sequence);
00079     if((rotationInterpolator == NULL) && (translationInterpolator == NULL)){
00080         return true;
00081     }
00082     Vector3 translation(0.f, 0.f, 0.f);
00083     if(translationInterpolator != NULL){
00084         translation = translationInterpolator->interpolate(correctTime);
00085     }
00086     if(rotationInterpolator == NULL){
00087         target_->setTransformation(Vector3::zero, translation);
00088     }else{
00089         if(rotationInterpolator->isQuaternionInterpolator()){
00090             target_->setTransformation(
00091                 rotationInterpolator->quaternionInterpolate(correctTime),
00092                 translation);
00093         }else if(rotationInterpolator->isEulerInterpolator()){
00094             target_->setTransformation(
00095                 rotationInterpolator->eulerInterpolate(correctTime),
00096                 translation);
00097         }else{
00098             ErrorOut("CameraAnimation::animate() "
00099                 "Unsupported Rotation type");
00100         }
00101     }
00102     return isFinished();
00103 }
00104 //------------------------------------------------------------------------------
00105 // カメラアニメーションのコピー
00106 CameraAnimation* CameraAnimation::copyCameraAnimation(
00107     DataCopyMask dataCopyMask) const{
00108     CameraAnimation* animation = getManager()->createCamera(getName());
00109     copyObjectAnimationValue(animation);
00110     // アニメーションデータのコピー
00111     if((dataCopyMask & copyCamera) == copyCamera){
00112         animation->animationData_ =
00113             animationData_->copyCameraAnimationData();
00114     }else{
00115         animation->animationData_ = animationData_;
00116     }
00117     animation->animationData_->addReference();
00118     animation->bind(target_);
00119     return animation;
00120 }
00121 //------------------------------------------------------------------------------
00122 } // End of namespace Lamp
00123 //------------------------------------------------------------------------------

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