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
Rotating a node...
-
- Posts: 92
- Joined: Sat Nov 29, 2003 8:30 pm
- Contact:
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;
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)
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
-
- Posts: 3
- Joined: Sat Jan 24, 2004 1:00 pm
- Location: Wimbledon, England
Rotation
Thanks for the help. Now my model can turn and look in different directions.
Eric
Eric
We like the moon