Rotating a node...

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
Eric the half a bee

Rotating a node...

Post by Eric the half a bee »

Hi.

I am trying to rotate a scene node upon user input (A or D keys)

I already have forward and backwards movement as follows...

switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node1->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? 4.0f : -4.0f;
node1->setPosition(v);
}
return true;

What I want to do is a similar thing with rotation with A and D. I thought that this might work...

case KEY_KEY_A:
case KEY_KEY_D:
{
core::vector3df r = node1->getRotation();
r.rotateXZBy(event.KeyInput.Key == KEY_KEY_A ? 4.0f : -4.0f, r);
}
return true;
}

but it doesn't. :? The Docs for Irrlicht say rotateXZBy() takes 2 parameters. The first is 64bit float for the degree of rotation. The second is vector3df. Could someone please reply with what 45 degs and 90 degs looks like in 64bit float form, and also what the second parameter (the vector3df) refers to.

Many thanks...

Eric the half a bee
madinitaly
Posts: 92
Joined: Sat Nov 29, 2003 8:30 pm
Contact:

Post by madinitaly »

I guess that vector parameter is the position of the center of rotation. That's because you need an axis around wich to rotate. That vector should be the origin of that axis.
NecromanX
Posts: 16
Joined: Sat Jan 24, 2004 6:01 pm

Post by NecromanX »

Try this code mate i allready wrote the same stuff:

Code: Select all

case KEY_KEY_A: 
case KEY_KEY_D: 

				{
					core::vector3df v = node->getRotation();
					v.Y += event.KeyInput.Key == KEY_KEY_A ?  -4.0f : 4.0f;
					node->setRotation(v);
				
				}
				return true;
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

necro's code should work. otherwise, to do it your way:
r.rotateXZBy(event.KeyInput.Key == KEY_KEY_A ? 4.0f : -4.0f, irr::core::vector3df(0,0,0) );

the vector in that parameter is what axis you want to rotate around (so if you wanted to rotate around some random point that wasnt your axis, you could put its position there)
a screen cap is worth 0x100000 DWORDS
Eric the half a bee
Posts: 3
Joined: Sat Jan 24, 2004 1:00 pm
Location: Wimbledon, England

Rotation

Post by Eric the half a bee »

Thanks for the help. Now my model can turn and look in different directions. :lol:

Eric
We like the moon
Post Reply