[SOLVED] Turn arround an 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.
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

[SOLVED] Turn arround an Axis?

Post by USE.IRR »

Hi All;

How can I make a node turn arround an axis?

I can just rotate it around him self

:?
Last edited by USE.IRR on Wed Aug 29, 2007 9:33 am, edited 2 times in total.
Image
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post 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?
Image
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmm, yes it seems it can only rotate around the Y axis !?!?! :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Try this topic, may be you can find there something usefull:
http://irrlicht.sourceforge.net/phpBB2/ ... ht=#128212
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post 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)).
Image
Image
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post by USE.IRR »

arras >> mmmmmmmmmmmeeeh (a kiss)

Others thanks. :D
Image
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

:oops:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

so it's really a bug with createFlyCircleAnimator ??? :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sfncook
Posts: 36
Joined: Sun Jul 01, 2007 6:32 pm

Post 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
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, it should, but it doesn't, the node only moves up and down (that's the bug)... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post 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 :?
Image
Image
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post by USE.IRR »

Is this impossible? :(
Image
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post 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;
}
USE.IRR
Posts: 32
Joined: Sat Jul 28, 2007 12:24 pm

Post by USE.IRR »

arras >> thank you,:D

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