# How to map absolute Joystick position to object rotation?

In my (Ogre) 3d scene I have an object that should be rotated locally based on Joystick input. I have a Joystick with min/max values of [-32767, 32767] on both X and Y axes. When the Joystick is in its origin position, the object should not be rotated. When the user moves the Joystick, the object in the 3d scene should follow this movement (or better: orientation) up to a max. of +/- 45 degrees on both axes.

Or in other words: when the user moves the Joystick e.g. fully to the left, the object's orientation in the 3d scene should be set to 45 degrees on the according axis.

Being new to 3d programming I searched on the Internet on how to achieve this. I think to understand that I want to use Quaternions for this task. I found some examples and tutorials on how to use Quaternions for rotating objects. What I don't understand though is how I can map from the Joystick's current absolute axes positions to the absolute, local rotation of an object.

I see that I could use the rotate() method of the object's node to set its rotation, but I understand that this rotates the object relatively to it's current position. But instead I want to map from the Joystick's absolute position to the absolute orientation/rotation of the object in the scene.

Any advice how I should approach this?

• Nice idea, I don't like the relative mapping which is normally used. – danijar May 9 '13 at 17:42

I don't know about the rotation part but for the mapping input to rotation you can do the following:

(this doesn't go in code)