How to rotate a node around its central axis?
-
- Posts: 7
- Joined: Tue May 31, 2016 9:01 am
How to rotate a node around its central axis?
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.
Re: How to rotate a node around its central axis?
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.
-
- Posts: 7
- Joined: Tue May 31, 2016 9:01 am
Re: How to rotate a node around its central axis?
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 anywaymongoose7 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.
Re: How to rotate a node around its central axis?
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm