00001 #include "CameraInstructions.h"
00002 #include "CameraAnimator.h"
00003 #include "Camera.h"
00004 #include "Matrix.h"
00005
00006
00007 CameraInstructionMove::CameraInstructionMove(CameraAnimator* anim, Vec3f end, Vec3f dir, Vec3f up, float aperture, float distance, unsigned int depthsamples, unsigned int framesleft, unsigned int camnum)
00008 :CameraInstructions(anim),
00009 mEndPos(end),
00010 mEndDir(dir),
00011 mEndUp(up),
00012 mEndAperture(aperture),
00013 mEndFocusDistance(distance),
00014 mEndDepthSamples(depthsamples),
00015 mFramesLeft(framesleft),
00016 mCameraNumber(camnum),
00017 mRuned(false)
00018 {
00019 }
00020
00021
00022
00023 void CameraInstructionMove::execute()
00024 {
00025 assert(animator!=0);
00026
00027 if(!mRuned)
00028 {
00029
00030
00031 Camera* cam = animator->mCameras.at(mCameraNumber);
00032 const float cosangledir = mEndDir.normal().dot(cam->dir().normal());
00033 const float dangle = - acosf(cosangledir) / static_cast<float>(mFramesLeft);
00034 const Vec3f daxis = mEndDir.cross(cam->dir());
00035
00036
00037
00038 if(daxis.length() < EPSILON)
00039 mDirMatrix = Matrix();
00040 else
00041 mDirMatrix = Matrix(dangle,daxis);
00042
00043 const float cosangleup = mEndUp.dot(cam->up());
00044 const float uangle = - acosf(cosangleup) / static_cast<float>(mFramesLeft);
00045 const Vec3f uaxis = mEndUp.normal().cross(cam->up().normal());
00046 if(uaxis.length() < EPSILON)
00047 mUpMatrix = Matrix();
00048 else
00049 mUpMatrix = Matrix(uangle,uaxis);
00050 }
00051 mRuned = true;
00052
00053
00054 if(mFramesLeft!=0)
00055 {
00056 Camera* cam = animator->mCameras.at(mCameraNumber);
00057
00058 const Vec3f posstep = ( mEndPos - cam->pos()).scaled(1.0f / mFramesLeft);
00059 const Vec3f newpos = cam->pos() + posstep;
00060 cam->setPos(newpos);
00061
00062 const Vec3f newview = mDirMatrix.transformVector(cam->dir());
00063
00064
00065 cam->setDir(newview);
00066
00067
00068
00069
00070
00071
00072 const Vec3f newup = mUpMatrix.transformVector(cam->up());
00073 cam->setUp(newup);
00074
00075
00076
00077
00078
00079
00080 const float distancestep = (mEndFocusDistance - cam->focusDistance()) / mFramesLeft;
00081 cam->setFocusDistance(cam->focusDistance() + distancestep);
00082
00083 const float aperturestep = (mEndAperture - cam->aperture()) / mFramesLeft;
00084 cam->setAperture(cam->aperture() + aperturestep);
00085
00086
00087 const unsigned int samplesstep = (mEndDepthSamples - cam->depthSamples()) / mFramesLeft;
00088 cam->setDepthSamples(cam->depthSamples() + samplesstep);
00089 LOG("newvalues: " << newpos << " " << cam->dir() << " " << cam->up() << " "<< cam->focusDistance() + distancestep << " " << cam->aperture() + aperturestep << " " << cam->depthSamples() + samplesstep);
00090
00091
00092 mFramesLeft--;
00093 LOG("framesleft: " << mFramesLeft);
00094 if(mFramesLeft==0)
00095 animator->mPC++;
00096 }
00097 else
00098 assert(false);
00099
00100 }
00101
00102 void CameraInstructionSet::execute()
00103 {
00104
00105 assert(animator!=0);
00106 animator->mActCam = mCameraNumber;
00107 animator->mPC++;
00108 }
00109
00110 void CameraInstructionNormal::execute()
00111 {
00112 assert(animator!=0);
00113 animator->mPC++;
00114
00115
00116 }
00117
00118 void CameraInstructionStay::execute()
00119 {
00120 assert(animator!=0);
00121 mFrames--;
00122 if(mFrames==0)
00123 animator->mPC++;
00124
00125
00126 }