I simply want to know how to use the ISceneNodeAnimator for animating an existing camera in my scene.
I have a GUIButton and when I click it the SceneNodeAnimator should animate the camera's target to the position of a specific scene node.
I think I didn't find this in the tutorials the last time I read them (about one month ago)
In the forums I found just one topic about this which was declared solved by the author whith an explanation that didn't help me at all.
What I want to create is a feature like the zoom & pan in Google Earth but much simpler. It would be nice if the camera target would move smoothly.
I don't know what possibilities I have with irrlicht engine, so tell me!
Thanks for any answers. I would be very happy to see some example code of how to use the ISceneNodeAnimator
That attaches both a FollowSplineAnimator and a FlyStraightAnimator to an existing camera. Both of these only move a scene node though; they won't change the LookAt position or up vector of a camera scene node. AFAICT, there's no built-in support for that, but if you're feeling frisky, you could add your own and maybe even submit a patch for it.
Can you assign a parent node to the Camera Target which the Target automatically follows?
What I need is a way to animate the changing of the camera's Target position.
The Animators work but as you said, there's no way to directly solve my problem.
What you could do is have this 'parent node' which the camera would change its target to follow and on that node you'd attach the required followspline or flystraight animator so that the camera would rotate as you wanted.
What you'd have to do is, each frame, reset the camera's target to be the position of the 'parent node' and you'd get the behaviour you're after.
('parent node' does not bear any relationship to the parent/child relationship you can have between nodes, it's just the node you named yourself in the original post, basically it's a dummy node which would not be visible, unless you wanted it to be visible of course!)
That could basically then be turned into an animator and submitted as a patch and you could tell the animator the node that wants to follow and the node to be followed and it could work it all for you.
What you'd have to do is, each frame, reset the camera's target to be the position of the 'parent node' and you'd get the behaviour you're after.
Cool! But how can I tell the target position to update EVERY FRAME?
How can I do that?
If I am able to, I would like to submit it as a patch. Well, I try.
Thanks for your help. If there's another way, please post it here!
ISceneNode* dummyNode = smgr->addCubeSceneNode(10);
dummyNode->setVisible(false);
// Create the required animator and add it to dummyNode
while (device->run()) {
camera->setTarget(dummyNode->getPosition());
// Render code
}
In fact i believe that there's an actual dummy scene node you can create with the scene manager for these sorts of purposes so check that out in the API.
Thanks JP! Another question that I know has been answered in the forums already. But I think it fits in here very well. How to animate just once and not all the way back and forth?
virtual ISceneNodeAnimator* irr::scene::ISceneManager::createFollowSplineAnimator ( s32 startTime,
const core::array< core::vector3df > & points,
f32 speed = 1.0f,
f32 tightness = 0.5f
) [pure virtual]
Creates a follow spline animator.
The animator modifies the position of the attached scene node to make it follow a hermite spline. The code of the is based on a scene node Matthias Gall sent in. Thanks! I adapted the code just a little bit. Matthias wrote: Uses a subset of hermite splines: either cardinal splines (tightness != 0.5) or catmull-rom-splines (tightness == 0.5) but this is just my understanding of this stuff, I'm not a mathematician, so this might be wrong ;)
From the API.
The continious/one shot option is available in FlyStaightAnimator for example.
I want to disable the "Maya->setTarget(dummy->getPosition());" when the animation has finished. I defined a boolean called TargetAnimation which is set "false" at the beginning. When I press the button which starts the animation, it first sets the TargetAnimation value to true. Otherwise I'd have problems with my camera controls. Now I need to set the value back to "false" when the animation is done, how could I do this? How can indicate that the animation has finished, maybe there is some sort of timer?
Does the follow spline animator actually loop? Isn't it a one shot thing? (not sure as i've never used it myself)
I suppose you might be able to use a timer but you'd have to calculate the distance that the thing is going to travel and then use the speed to work out how long that would take and add it on to the start time to get the end time.
What might work better is to keep checking the dummy node's position against its previous position and if they don't change then you know it's stopped moving so you can stop following it.
// maxDist is the maximal distance the nodes collides
f32 maxDist = 10.0;
.
.
.
if (node_A->getPosition().getDistanceFrom(node_B->getPosition()) < maxDist)
// maxDist is the maximal distance the nodes collides
f32 maxDist = 10.0;
.
.
.
if (node_A->getPosition().getDistanceFrom(node_B->getPosition()) < maxDist)
or you could use distanceSQ to have an even faster check.