help animating the camera

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
dowi
Halfling
Posts: 48
Joined: Wed Sep 07, 2011 3:37 am

help animating the camera

Post by dowi »

hi all

i'm using ogre 1.8 on the iphone xcode4

i'm trying to animate the camera from point A to point B.
for start all i want is to move the camera say from 0,0,100 to 0,0,150 within x seconds.

i looked at the forum and the sample and did the following:

Code: Select all

void OgreFramework::InitCameraAnimations()
{

    mCamNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("camera node");
    mCamNode->attachObject(m_pCamera);

    Ogre::Animation* mCamAnim = m_pSceneMgr->createAnimation( "Camera Animation", 10 );
    mCamAnim ->setInterpolationMode( Ogre::Animation::IM_SPLINE );
   // mCamAnim->setRotationInterpolationMode(Animation::RIM_SPHERICAL);

    Ogre::NodeAnimationTrack* mCamTrack = mCamAnim->createNodeTrack( 0, mCamNode );

   // mCamTrack->setUseShortestRotationPath( true );

    Ogre::TransformKeyFrame* mCamKey;
   
    mCamKey= mCamTrack->createNodeKeyFrame( 0 );
    mCamKey->setTranslate( Ogre::Vector3(0, 0, 100) );
  
   mCamKey= mCamTrack->createNodeKeyFrame( 10 );
   mCamKey->setTranslate( Ogre::Vector3(0, 0, 150) );

    //mCamKey->setRotation( Ogre::Quaternion(0.1,0.1,0.1,0.1) );

    mCamAnimState = m_pSceneMgr->createAnimationState( "Camera Animation" );
}
and then when i want to start the animation im doing :

Code: Select all

mCamAnimState ->setEnabled( true );

the effect im getting is that the animation is happening but immediately!
not during the 10 seconds i entered.

what could the problem be?

thanks alot !
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: help animating the camera

Post by Mind Calamity »

dowi wrote:hi all

i'm using ogre 1.8 on the iphone xcode4

i'm trying to animate the camera from point A to point B.
for start all i want is to move the camera say from 0,0,100 to 0,0,150 within x seconds.

i looked at the forum and the sample and did the following:

Code: Select all

void OgreFramework::InitCameraAnimations()
{

    mCamNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("camera node");
    mCamNode->attachObject(m_pCamera);

    Ogre::Animation* mCamAnim = m_pSceneMgr->createAnimation( "Camera Animation", 10 );
    mCamAnim ->setInterpolationMode( Ogre::Animation::IM_SPLINE );
   // mCamAnim->setRotationInterpolationMode(Animation::RIM_SPHERICAL);

    Ogre::NodeAnimationTrack* mCamTrack = mCamAnim->createNodeTrack( 0, mCamNode );

   // mCamTrack->setUseShortestRotationPath( true );

    Ogre::TransformKeyFrame* mCamKey;
   
    mCamKey= mCamTrack->createNodeKeyFrame( 0 );
    mCamKey->setTranslate( Ogre::Vector3(0, 0, 100) );
  
   mCamKey= mCamTrack->createNodeKeyFrame( 10 );
   mCamKey->setTranslate( Ogre::Vector3(0, 0, 150) );

    //mCamKey->setRotation( Ogre::Quaternion(0.1,0.1,0.1,0.1) );

    mCamAnimState = m_pSceneMgr->createAnimationState( "Camera Animation" );
}
and then when i want to start the animation im doing :

Code: Select all

mCamAnimState ->setEnabled( true );

the effect im getting is that the animation is happening but immediately!
not during the 10 seconds i entered.

what could the problem be?

thanks alot !
I haven't gotten this far with using OGRE, but, it's worth to try what I'm about to say.

I think this:

Code: Select all

mCamKey= mCamTrack->createNodeKeyFrame( 10 );
is wrong, I don't think that createNodeKeyFrame(Ogre::Real timePos)'s argument is time in seconds, but the keyframe's position in the timeline of the animation you are creating, so when you specify 10 as the argument, let's say your application runs at 200 FPS, since that frame is 10th in the timeline, it's translation is going to be executed in a fraction of a second, giving you the impression it happens immediately, try setting it to something like 200, or at least 100, for testing purposes.

Also, try limiting your application's framerate, by turning on VSync, it will by default limit the FPS to 60, and then, if timePos = 60, that key frame's translation would be executed from frame 0 to frame 60 in a time span of 1 second. (or timePos = 600 for 10 seconds).

This is just theory, I haven't tried manual animation with OGRE yet. Sorry if I accidentally confused you, I can't explain this really well :( .
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: help animating the camera

Post by masterfalcon »

As a note, the vsync key doesn't do anything on iOS. But if you set it up with a display link(see the sample browser) then it will attempt to sync it up with the displays refresh rate, which is 60.

But you're right about it not being counted in seconds. The terminology is a tip off, key frame.
dowi
Halfling
Posts: 48
Joined: Wed Sep 07, 2011 3:37 am

Re: help animating the camera

Post by dowi »

thanks guys!

what if i want the animation to be x seconds no matter what the FPS is ?
can i do this using the method above?

does the function

Code: Select all

createAnimation( "Camera Animation", 10 );
also takes frames and not seconds?


unrelated Q:
regarding masterfalfon's post, is it better to use displayLink rather than NSTimer on iphones?

thanks
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: help animating the camera

Post by Mind Calamity »

dowi wrote:thanks guys!

what if i want the animation to be x seconds no matter what the FPS is ?
can i do this using the method above?

does the function

Code: Select all

createAnimation( "Camera Animation", 10 );
also takes frames and not seconds?


unrelated Q:
regarding masterfalfon's post, is it better to use displayLink rather than NSTimer on iphones?

thanks
Well, you can manually limit the FPS of your application, no matter the system, that way you can calculate the exact frame which will be rendered at x seconds.

As for that function, it's more likely to take frames, rather than seconds.

Try it, and share the results ;)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
dowi
Halfling
Posts: 48
Joined: Wed Sep 07, 2011 3:37 am

Re: help animating the camera

Post by dowi »

hi again

i tried a lot of different settings for the FPS and played with

setEnabled
setLoop
setTimePosition
addTime

divided timeSinceLastFrame by 1000 to make it [sec]

and non of the above worked for me : (

if still get the animation i want but it happens immediately
from keyFrame(0) to keyFrame(last)

do you guys can think of a way to solve this or work around it?
thanks in advance
dowi
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: help animating the camera

Post by Mind Calamity »

dowi wrote:hi again

i tried a lot of different settings for the FPS and played with

setEnabled
setLoop
setTimePosition
addTime

divided timeSinceLastFrame by 1000 to make it [sec]

and non of the above worked for me : (

if still get the animation i want but it happens immediately
from keyFrame(0) to keyFrame(last)

do you guys can think of a way to solve this or work around it?
thanks in advance
dowi

Nothing in particular comes to mind right now, but I'm going to have to play with animation soon, if I find anything that can help you, I'll share it with you.

Also, I think this thread has nothing to do with Mobile Devices in particular, but with OGRE in general, so I think it belongs to the "Help" forum.

Good luck! :)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
dowi
Halfling
Posts: 48
Joined: Wed Sep 07, 2011 3:37 am

Re: help animating the camera

Post by dowi »

hi

thanks alot for trying to help!

i thought it had something to do with the iphone port
i'll try that in windows too as soon as i have time

thanks
dowi
Halfling
Posts: 48
Joined: Wed Sep 07, 2011 3:37 am

Re: help animating the camera

Post by dowi »

ok, problem solved.

the numbers are in seconds..

the problem was that i had:

Code: Select all

mCamKey= mCamTrack->createNodeKeyFrame( 0 );
mCamKey->setTranslate( Ogre::Vector3(0, 0, 100) );
now, it is setTranslate and not position and i did that on time zero...
so immediately the model moved

thanks alot everyone