ISceneNodeAnimator

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

ISceneNodeAnimator

Post by Namek Kural »

Hello! :D

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! :wink:

Thanks for any answers. I would be very happy to see some example code of how to use the ISceneNodeAnimator
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Have a look in examples/Demo/CDemo.cpp

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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

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.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

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.
Image Image Image
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

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. :lol:

Thanks for your help. If there's another way, please post it here! :D
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Simple, you know how to update the camera target right? You just do that in the while(device->run()) loop, something like this:

Code: Select all

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.
Image Image Image
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

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?

PS: The animation look great!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

There's a boolean parameter in the function when you create the animator which lets you choose between one shot or continuous isn't there?

Check the API, as you should have already ;)
Image Image Image
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

Nope! There isn't:

Code: Select all

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? :?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

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.
Image Image Image
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

It's like ping pong ^^

How can I compare two positions of one node? :?:
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Code: Select all

if (node_A.getPosition() == node_B.getPosition())...?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

MasterGod wrote:

Code: Select all

if (node_A.getPosition() == node_B.getPosition())...?
I don't think this is a good solution...
How possible it is that both nodes are at the exact same position ??? ;)

I would prefere something like this:

Code: Select all

// maxDist is the maximal distance the nodes collides
f32 maxDist = 10.0;
.
.
.
if (node_A->getPosition().getDistanceFrom(node_B->getPosition()) < maxDist)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Acki wrote:
MasterGod wrote:

Code: Select all

if (node_A.getPosition() == node_B.getPosition())...?
I don't think this is a good solution...
How possible it is that both nodes are at the exact same position ??? ;)

I would prefere something like this:

Code: Select all

// 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. ;)
TheQuestion = 2B || !2B
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Halifax wrote:or you could use distanceSQ to have an even faster check. ;)
but this is not an Irrlicht function, isn't it?
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply