How can I make a node turn arround an axis?
I can just rotate it around him self

Code: Select all
scene::ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(core::vector3df(0,1,0),20.0f,0.0005f,core::vector3df(1,0,0));
box1_node->addAnimator(anim);
anim->drop();
Code: Select all
void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
{
if ( 0 == node )
return;
const f32 t = (timeMs-StartTime) * Speed;
//the problem is here
[b]core::vector3df circle(Radius * sinf(t), 0, Radius * cosf(t));[/b]
circle = circle.crossProduct ( Direction );
node->setPosition(Center + circle);
}
Code: Select all
f32 gradius = 1.0f;
//Current rotation
matrix4 currentRotation;
currentRotation= node1->getRelativeTransformation();
//Constant rotation1
matrix4 constRotation1;
//SUN Axis
constRotation1.setRotationDegrees(core::vector3df (0 ,1 , 0) );
//Next rotation
matrix4 nextRotation;
nextRotation = constRotation1 * currentRotation;
//Constant rotation2
matrix4 constRotation2;
// Earth Axis
constRotation2.setRotationDegrees(core::vector3df (50 ,50 , 0));
//relative rotation
matrix4 relativeRotation;
relativeRotation=currentRotation * constRotation2;
core::vector3df dir = core::vector3df(0,gradius,0);
nextRotation.rotateVect(dir);
rot = relativeRotation.getRotationDegrees();
//node1 is earth
node1->setRotation(rot);
node1->setPosition(dir);
Code: Select all
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice *device = createDevice( video::EDT_OPENGL,
core::dimension2d<s32>(640, 480), 32, false, false, false, 0);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, core::vector3df(0,10,-30), core::vector3df(0,0,0));
scene::ISceneNode *star = smgr->addSphereSceneNode();
star->setMaterialFlag(video::EMF_LIGHTING ,false);
star->setRotation(core::vector3df(-5,1,10));
scene::ISceneNode *planet = smgr->addSphereSceneNode(3.0f);
planet->setMaterialFlag(video::EMF_LIGHTING ,false);
f32 radius = 20.0f;
f32 rotationSpeed = 0.1f;
f32 rotation = 0.0f;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,100,101,140));
rotation += rotationSpeed;
core::vector3df pos= core::vector3df(0,0,radius);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0 ,rotation , 0) );
matrix.rotateVect(pos);
matrix = star->getAbsoluteTransformation();
matrix.rotateVect(pos);
planet->setPosition(pos+ star->getPosition());
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Code: Select all
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice *device = createDevice( video::EDT_OPENGL,
core::dimension2d<s32>(640, 480), 32, false, false, false, 0);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, core::vector3df(0,10,-30), core::vector3df(0,0,0));
scene::ISceneNode *star = smgr->addSphereSceneNode();
star->setMaterialFlag(video::EMF_LIGHTING ,false);
star->setRotation(core::vector3df(-5,1,10));
scene::ISceneNode *planet = smgr->addSphereSceneNode(3.0f, 16, star);
planet->setMaterialFlag(video::EMF_LIGHTING ,false);
f32 radius = 20.0f;
f32 rotationSpeed = 0.1f;
f32 rotation = 0.0f;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,100,101,140));
rotation += rotationSpeed;
core::vector3df pos = core::vector3df(0,0,radius);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0 ,rotation , 0) );
matrix.rotateVect(pos);
planet->setPosition(pos);
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}