Page 1 of 1

Rotating a node...

Posted: Sat Jan 24, 2004 12:57 pm
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

Posted: Sat Jan 24, 2004 1:56 pm
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.

Posted: Sat Jan 24, 2004 6:20 pm
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;

Posted: Sat Jan 24, 2004 9:48 pm
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)

Rotation

Posted: Sun Jan 25, 2004 11:18 am
by Eric the half a bee
Thanks for the help. Now my model can turn and look in different directions. :lol:

Eric