History: Camcorder
Source of version: 11
Copy to clipboard
I use this class to help me record demos without having the jerky movement of a manually moved camera; the animation smooths out my motion making a more professional looking video. --((User:Sinbad|Sinbad))
To use this class, just include it in your project, and call ''init(viewport, camera)'' and ''setEnabled(true)'' to turn it on. You will need to call ''processUnbufferedKeyboard'' and update every frame. When enabled, you can start & stop recording the camera by pressing ''Insert'', and toggle playback using ''Return''. The brackets change the interval between the keyframes that are created in record mode, and the playback speed in playback mode. You can also place keyframes manually with the ''Space'' key.
It's currently limited to just one animation and there are no editing features built in, it's purely one-shot recording & playback. Feel free to extend it to full Final Cut Pro status if you want :)
{maketoc}
!Prerequisites
This class was made using the '''old''' overlays, so you need to grab OgreCore.zip from here:
http://ogre.svn.sourceforge.net/viewvc/ogre/branches/v1-6/Samples/Media/packs/OgreCore.zip
Add this to resources[[_d].cfg:
{CODE(wrap="1", colors="ini")}Zip=../../media/packs/OgreCore.zip{CODE}
!Usage
{CODE(wrap="1", colors="c++", caption="Initialisation")}
camCorder = new CamcorderHelper();
camCorder->init(vp, mCamera);
camCorder->setEnabled(true);
{CODE}
{CODE(wrap="1", colors="c++", caption="frameRenderingQueued")}
camCorder->processUnbufferedKeyboard(mKeyboard, evt.timeSinceLastFrame);
camCorder->update(evt.timeSinceLastFrame);
{CODE}
!Code
{toc}
!Loading and Saving animations using the AnimationSerializer
The ((AnimationSerializer)) was made to be able to save and load recorded camera animations, and it requires only two small changes to the CamcorderHelper class.
!!Camcorder modifications
Add these two lines to Camcorder.h:
{CODE(wrap="1", colors="c++")}
const Animation* getAnimation() const {return mCurrentAnimation; }
void setAnimation(Animation* anim);
{CODE}
The definition of CamcorderHelper::setAnimation:
{CODE(wrap="1", colors="c++")}
void CamcorderHelper::setAnimation(Animation* anim)
{
if(mCurrentAnimation)
mCurrentAnimation->destroyAllTracks();
mCurrentAnimation = anim;
mCurrentTrack = anim->getNodeTrack(0);
mCurrentAnimation->setInterpolationMode(mInterpolationMode);
mCurrentAnimation->setRotationInterpolationMode(mRotationInterpolationMode);
mCurrentTrack->setUseShortestRotationPath(false);
}
{CODE}
!!Loading and saving animations
{CODE(wrap="1", colors="c++", caption="Save animation")}
AnimationSerializer animSerializer;
animSerializer.exportAnimation(camCorder->getAnimation(), "cam.anim");
{CODE}
{CODE(wrap="1", colors="c++", caption="Load animation")}
AnimationSerializer animSerializer;
camCorder->setAnimation(animSerializer.importAnimation("cam.anim"));
{CODE}
To get a more accurate recording you can lower the frame frequency:
{CODE(wrap="1", colors="c++")}camCorder->setKeyFrameFrequency(0.1f);{CODE}
%warning2% __Warning!__
The serializer needs to be fixed so that it saves the animation file in the resource group manager search paths.
Right now it saves the file in the current working directory, and loads it from the resource directories..
So in order to load a saved animation, you need to move the saved animation to a resource directory.
This notice will be removed once that issue is fixed.