Page 1 of 1

help animating the camera

Posted: Sun Sep 18, 2011 10:44 pm
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 !

Re: help animating the camera

Posted: Sun Sep 18, 2011 11:20 pm
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 :( .

Re: help animating the camera

Posted: Mon Sep 19, 2011 4:32 am
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.

Re: help animating the camera

Posted: Mon Sep 19, 2011 5:46 am
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

Re: help animating the camera

Posted: Mon Sep 19, 2011 6:13 am
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 ;)

Re: help animating the camera

Posted: Mon Sep 19, 2011 9:16 pm
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

Re: help animating the camera

Posted: Tue Sep 20, 2011 7:11 am
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! :)

Re: help animating the camera

Posted: Tue Sep 20, 2011 7:56 am
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

Re: help animating the camera

Posted: Sun Oct 09, 2011 9:39 pm
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