Hi,
How can I rotate a node around it's Y-axis based on the position of the mouse?
For example, if I mouse the mouse to the left, I want the node rotate on it's Y-axis to the right.
Thanks in advance!
rotate node based on mouse pos
In node's constructor:
In node's update method (or animation method, w/e you want to call it)
And your rotate function (thanks arras) is this:
Hope that helps. There are plenty other ways to do this too... this is just how I do it.[/code]
Code: Select all
cursor = device->getCursorControl();
cursor->grab();
cursor->setVisible(false);
cursorCenterPos = cursor->getRelativePosition();
In node's update method (or animation method, w/e you want to call it)
Code: Select all
if (cursor)
{
position2d<f32> cursorDelta = cursor->getRelativePosition() - cursorCenterPos;
if (cursorDelta.X || cursorDelta.Y)
{
deltaYaw = cursorDelta.X * cMouseSensitivity;
deltaPitch = -cursorDelta.Y * cMouseSensitivity;
cursor->setPosition(cursorCenterPos);
cursorCenterPos = cursor->getRelativePosition();
}
}
rotate(vector3df(0, deltaYaw, 0));
rotate(vector3df(deltaPitch, 0, 0));
Code: Select all
void rotate(vector3df rot)
{
matrix4 m;
m.setRotationDegrees(node->getRotation());
matrix4 n;
n.setRotationDegrees(rot);
m *= n;
node->setRotation( m.getRotationDegrees());
node->updateAbsolutePosition();
}