Page 1 of 2

[SOLVED] Turn arround an Axis?

Posted: Mon Aug 27, 2007 2:15 pm
by USE.IRR
Hi All;

How can I make a node turn arround an axis?

I can just rotate it around him self

:?

Posted: Mon Aug 27, 2007 2:59 pm
by Acki
If you just want an orbiting object (like the moon around the earth) you can use the createFlyCircleAnimator(...) function...

If you want to controll the object, a little bit trigonometry would help... ;)
look at this thread and just use the cameras target for positioning your object: http://irrlicht.sourceforge.net/phpBB2/ ... 75f608d2c6

Posted: Mon Aug 27, 2007 3:39 pm
by USE.IRR
I can not have a correct animation with this:

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();
is there a bug in createFlyCircleAnimator?

Posted: Mon Aug 27, 2007 4:06 pm
by Acki
hmm, yes it seems it can only rotate around the Y axis !?!?! :shock:

Posted: Mon Aug 27, 2007 4:12 pm
by arras
Try this topic, may be you can find there something usefull:
http://irrlicht.sourceforge.net/phpBB2/ ... ht=#128212

Posted: Mon Aug 27, 2007 4:18 pm
by USE.IRR

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);
}
Are there any other solution, or how can i change this code to make it work for any axis (not just (1,0,0) or (0,1,0) or (0,0,1)).

Posted: Mon Aug 27, 2007 4:35 pm
by USE.IRR
arras >> mmmmmmmmmmmeeeh (a kiss)

Others thanks. :D

Posted: Mon Aug 27, 2007 4:52 pm
by arras
:oops:

Posted: Mon Aug 27, 2007 5:10 pm
by Acki
so it's really a bug with createFlyCircleAnimator ??? :shock:

Posted: Mon Aug 27, 2007 7:34 pm
by sfncook
I'm not especially familiar with the fly circle animator, but it seems like this code:
[code]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]
is specifying an upvector along the x-axis. Wouldn't that make it orbit around the x-axis and not the y-axis?

Nobody kiss me, please. :D

Posted: Mon Aug 27, 2007 8:02 pm
by Acki
well, it should, but it doesn't, the node only moves up and down (that's the bug)... ;)

Posted: Tue Aug 28, 2007 10:23 am
by USE.IRR
Hi all, I am using this code to have the animation shown in the picture. But I can not see the correct animation.

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);

Image

What is the problem with my code :?

Posted: Wed Aug 29, 2007 7:43 am
by USE.IRR
Is this impossible? :(

Posted: Wed Aug 29, 2007 8:18 am
by arras

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;
}
You can skip that AbsoluteTransformation part by making planet to be child of star:

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;
}

Posted: Wed Aug 29, 2007 8:52 am
by USE.IRR
arras >> thank you,:D

but I want the make the planet turn around its axis like in the picture.