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)

add 32768 to your input getting a value 0-65535

from here you can get your multiplier which is 90/65535 = 0.00137

then to get your rotation distance you can simply multiply your input by your multiplier

(this goes in code)

32767 * 0.00137 = ~45 (may want to do some rounding)

• Thanks, but this is the part I already know. Currently I am more interested in how I can set the absolute rotation values :) – Matthias May 9 '13 at 22:58
• Right, but you already have a question about that here: gamedev.stackexchange.com/questions/55234/… – UnderscoreZero May 10 '13 at 15:40
• Indeed. I had the impression that maybe I phrased that question incorrectly or misleading, so I tried it with a different question. – Matthias May 10 '13 at 19:36