Page 1 of 1

Moving node in 3D World

Posted: Mon Dec 24, 2007 9:42 am
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.

Posted: Mon Dec 24, 2007 9:59 pm
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.)

Posted: Mon Dec 24, 2007 10:12 pm
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.

Posted: Mon Dec 24, 2007 10:40 pm
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!

Posted: Tue Dec 25, 2007 9:50 pm
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.

Posted: Thu Dec 27, 2007 5:37 pm
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:

Posted: Fri Nov 14, 2008 8:11 am
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

Posted: Fri Nov 14, 2008 10:47 am
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.

Posted: Fri Nov 14, 2008 10:50 am
by JP
Wouldn't work for cameras would it....

Posted: Fri Nov 14, 2008 10:51 am
by rogerborg
...and that sets camera targets as well.