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