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 #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 }
00123