Moving a SceneNode smoothly (linear interpolation) question

paddy3k

29-09-2008 06:08:51

Hi everyone!

I spend the whole yesterday in find out how to move a SceneNode smoothly.
But didn't made any progress. Can anybody post a simple example of moving a Node using linear interpolation ?

I think there a 2 ways to do it. One is using Animation (SceneNodeTrack?) and the other is to interpolate by myself.

May we have

Object Car

Start Position : (0,0,0)

End Position : (100, 0, 150)

this movement shall be done in 1 second. How would the corresponding sourcecode look like ?

I read something, that I should get first the velocity vector, which would be (100, 0, 150) in my case. Later on some multiplying with the timeSinceLastFrame... but I didn't got it at all. May somebody can help :-)

Thanks very much !!

bye
paddy

paddy3k

29-09-2008 18:24:12

Hi again...

I found a first solution... and it looks like the following :
(like already posted in the main ogre practice forum)



public void CreateAnimationPath()
{
Animation anim = base.SceneManager.CreateAnimation("move", log.StepCount);

anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);

NodeAnimationTrack track = anim.CreateNodeTrack(0, (SceneNode)entityTable.SceneNodes[1]);

TransformKeyFrame key;

for (int i = 0; i < log.StepCount; i++)
{
key = track.CreateNodeKeyFrame(i);
key.Scale = new Vector3(0.05f);
key.Translate = log.Entities.AgentPath[1][i];
}

animState = base.SceneManager.CreateAnimationState("move");
animState.Enabled = true;
}


and this in the FrameStartedEvent :



bool FrameStarted(FrameEvent evt)
{
animState.AddTime(evt.timeSinceLastFrame);

return true;
}


works quite well. Just have to put it in seperate classes for easier animation handling of all entities.

Do you think I can use it this way for a serious project ?

greets
paddy

Bekas

30-09-2008 01:32:35

It looks perfect to me!

And it was a good idea to post on the main Ogre forums, something like this leans on the "how to use Ogre" side, it's not Mogre-specific.

paddy3k

01-10-2008 13:29:02

amazing to here that from you :)
I'm a bit proud now :wink:

I think that will help many other neewbies addicted by ogre who want to do simple animations (not only mesh specific / bone / submesh animations).

I will continue working on that, to encapsulate it in a seperate class which's
able to do these 3 animation (discrete, spline & linear).

If I'm done, I will post this class for free use :)

thanks 2 all
bye
paddy