how to make a smooth rotation?

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
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

how to make a smooth rotation?

Post by easy163 »

Hi all, how to make a smooth turn node in the direction of the other node? For example, every second, rotate the node 10 degrees until the node will not be turned completely to the desired point?
Now there is such a code, it instantly turns the node to the point.

Code: Select all

 
    void rotationToNode(IAnimatedMeshSceneNode *node, vector3df toNode, f32 speed) 
    {
 
        vector3df nodePosition = node->getPosition();
        vector3df rotationNeed;
 
        float X = nodePosition.X - toNode.X;
        float Y = nodePosition.Z - toNode.Z;
        rotationNeed.Y = (f32)((atan2(X, Y) * 180 / PI) + 180);
 
        node->setRotation(rotationNeed);
 
    }
 
How to change it? Can you share the code?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: how to make a smooth rotation?

Post by smso »

You may be interested in this:

http://irrlicht.sourceforge.net/forum/v ... =9&t=47304

Regards,
smso
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Re: how to make a smooth rotation?

Post by easy163 »

And are there other ways?
easy163
Posts: 24
Joined: Wed Jul 10, 2013 12:50 pm

Re: how to make a smooth rotation?

Post by easy163 »

need a normal rotation with constant speed, is there one?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: how to make a smooth rotation?

Post by CuteAlien »

ISceneManager::createRotationAnimator might do what you want.

Otherwise you need to save the your full rotation vector (rotationNeed), rotation time (how long it should take) and the last time step (init with time on first call, update on each update). Then you need an update function which is called each frame. It increases the rotation by full_rotation * time_for_last_update/rotation_time. You can derive from Irrlicht's irr::scene::ISceneNodeAnimator and add it to your node. That will call the animatedNode function of your derived class each frame. Or you can use any custom updater class/function system which you write yourself.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
jiangcaiyang
Posts: 9
Joined: Tue Nov 12, 2013 3:24 pm

Re: how to make a smooth rotation?

Post by jiangcaiyang »

Although I am a beginner for Irrlicht, I think you need a sphere interpolation solution.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: how to make a smooth rotation?

Post by mongoose7 »

Not if the axis remains fixed.
Post Reply