How to rotate a node around its central axis?

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
Tonytonytang
Posts: 7
Joined: Tue May 31, 2016 9:01 am

How to rotate a node around its central axis?

Post by Tonytonytang »

I added a node to the scene, and changed its position, then I added a rotation animator(vector(0, 1.5, 0)) to the node, but the node feels like rotating around the center of the scene. How to rotate a node around its central axis? Thanks.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: How to rotate a node around its central axis?

Post by mongoose7 »

Translate the node to the centre, rotate it, translate it back. If this is too hard, rotate it as you have done then translate it back to its initial position. Or, centre the entire scene on the node.
Tonytonytang
Posts: 7
Joined: Tue May 31, 2016 9:01 am

Re: How to rotate a node around its central axis?

Post by Tonytonytang »

mongoose7 wrote:Translate the node to the centre, rotate it, translate it back. If this is too hard, rotate it as you have done then translate it back to its initial position. Or, centre the entire scene on the node.
I found my problem, the model was exported from 3D max and saved its relative position in 3D max scene, I added to the irrlicht scene the relative position was reserved but its actual position is (0,0,0), so when rotating it feels like rotating arround (0,0,0). Thanks anyway
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to rotate a node around its central axis?

Post by CuteAlien »

Ok. Just when I was done testing if there's a problem ^^ (found none).

Code: Select all

 
#include <irrlicht.h>
#include <iostream>
#include <cassert>
 
using namespace irr;
using namespace core;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
int main(int argc, char* argv[])
{
    IrrlichtDevice *  device = createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::u32>(800,600));
    if (!device)
        return 0;
   
    scene::ISceneManager* smgr = device->getSceneManager();
    video::IVideoDriver * videoDriver = device->getVideoDriver ();
   
    scene::IAnimatedMesh* aniMesh = smgr->getMesh( "../../media/ninja.b3d" );
    if (!aniMesh)
        return 0;
    aniMesh->getMeshBuffer(0)->getMaterial().Lighting = false;
 
    scene::ISceneNodeAnimator * ani1 = smgr->createRotationAnimator (core::vector3df(0,1.5,0)); 
    scene::ISceneNodeAnimator * ani2 = smgr->createRotationAnimator (core::vector3df(0,1.5,0)); 
    scene::ISceneNodeAnimator * ani3 = smgr->createRotationAnimator (core::vector3df(0,1.5,0)); 
    scene::IMeshSceneNode * node1 = smgr->addMeshSceneNode (aniMesh, NULL, -1, vector3df(0, 0, 0) );
    node1->addAnimator(ani1);
    scene::IMeshSceneNode * node2 = smgr->addMeshSceneNode (aniMesh, NULL, -1, vector3df(-10, 0, 0) );
    node2->addAnimator(ani2);
    scene::IMeshSceneNode * node3 = smgr->addMeshSceneNode (aniMesh, NULL, -1, vector3df(0, 0, 10) );
    node3->addAnimator(ani3);
    ani1->drop();
    ani2->drop();
    ani3->drop();
 
 
    irr::scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 20.f, 0.1f );
    camera->updateAbsolutePosition();
    camera->setTarget( vector3df(0,0,0) );
    camera->updateAbsolutePosition();
    camera->setPosition(irr::core::vector3df(30, 0, -30));
    camera->updateAbsolutePosition();
 
    while ( device->run() )
    {
        if ( device->isWindowActive() )
        {
            videoDriver->beginScene(true, true);
 
            smgr->drawAll();
 
            videoDriver->endScene();
        }
 
        device->sleep( 5 );
    }
 
    device->closeDevice();
    device->drop();
    device = NULL;
 
    return 0;
}
 
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
Post Reply