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.
Moving node in 3D World
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
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.)
- 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.
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.
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.
I think I can find the directional vector.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 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!
What's my mistake?
Thanks for help!
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
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
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Thanks for help but I don't want to use the camera...it has another look at position.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.
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:
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
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
....
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
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
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.
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
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
...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
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way