Moving node in 3D World

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.
Post Reply
MarKuz
Posts: 3
Joined: Mon Dec 24, 2007 9:40 am

Moving node in 3D World

Post by MarKuz »

Hello! I am totally new with Irrlicht.

I am trying to move a node in 3D world using FollowSplineAnimator.

However my node doesn't face tha direction it moves.

I have searched the forum but I can't make it work.

I would be grateful if you could help me.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Not sure about this but you would have to implement it yourself.

- You will surely have to check how the code is made in that animator
- Find a way to generate a directional vector (Could take the last position with the new position of your mesh at each frame)
- Align your node to that directional vector. (If it's a camera then you use that directional vector add some distance to it then use it as your camera target. If it's a mesh, then you will have to take that vector, and get the angle from the direction vector. After that apply the angle to the mesh)

This require good knowledge of math's and C++. I'm good for figuring out how to do it, but giving you the code like that. I can't. I would have to check the source code and check how they do the 3 steps mentioned above. (Lots of IRRlicht functions source have most of the code for doing this. But you have to dig in and search, unless your very good in math and C++ as I mentioned above.)
Last edited by christianclavet on Mon Dec 24, 2007 10:17 pm, edited 1 time in total.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

i think you may have to normalize the camera to the object you want to look at.

it could be a static point or a point in the walk path.

hope that made sense. i'm just a newbie (learner) at this, though.

or you can get the vector of the spline at the point where the camera is standing on and then use that to set your camera.
Image
MarKuz
Posts: 3
Joined: Mon Dec 24, 2007 9:40 am

Post by MarKuz »

christianclavet wrote:Not sure about this but you would have to implement it yourself.

- You will surely have to check how the code is made in that animator
- Find a way to generate a directional vector (Could take the last position with the new position of your mesh at each frame)
- Align your node to that directional vector. (If it's a camera then you use that directional vector add some distance to it then use it as your camera target. If it's a mesh, then you will have to take that vector, and get the angle from the direction vector. After that apply the angle to the mesh)

This require good knowledge of math's and C++. I'm good for figuring out how to do it, but giving you the code like that. I can't. I would have to check the source code and check how they do the 3 steps mentioned above. (Lots of IRRlicht functions source have most of the code for doing this. But you have to dig in and search, unless your very good in math and C++ as I mentioned above.)
I think I can find the directional vector.

I added a cubeSceneNode and I attached to it the same animator.I added the animatior to my node 50 ms after the cube.

So in device loop I can get the difference between the positions and it's the directional vector.Right?

Then I used getHorizontalAngle(directionVector) and used it with node's setRotation.

It doesn't work! :oops:

What's my mistake?

Thanks for help!
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Quick trick, courtesy of JP: create an empty scene node, then either attach the same spline animator to it but start it off a little earlier, or create a new spline animator just for the look at position. Every frame, have your camera look at the empty scene node.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MarKuz
Posts: 3
Joined: Mon Dec 24, 2007 9:40 am

Post by MarKuz »

rogerborg wrote:Quick trick, courtesy of JP: create an empty scene node, then either attach the same spline animator to it but start it off a little earlier, or create a new spline animator just for the look at position. Every frame, have your camera look at the empty scene node.
Thanks for help but I don't want to use the camera...it has another look at position. :wink:
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Post by aungsithu »

Not very sure it's the way.
But when I wanted to make my node face the direction it's moving, I modified the CSceneNodeAnimatorFollowSpline::animateNode function as follow:

Code: Select all

//hermite polynomials
....

//added this 2 lines
const core::vector3df r = (p2 - p1).getHorizontalAngle();
node->setRotation(r);

//interpolated point
....
Then I compiled a new Irrlicht.dll then used it for my project.

Hope it might be helpful to someone.

Let me know if there's a better way also.

Thanks
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Thanks, that's an interesting suggestion. I've put it in the tracker so that we don't forget it.

If you're interested in getting it in, then we'd need:

An implementation for all animators...
...that deals with gimbal lock...
...and arbitrary "forwards" directions...
...and a simple test app that exercises and demonstrates all of the above functionality.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Wouldn't work for cameras would it....
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

...and that sets camera targets as well.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply