Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I came up with some cube rotating, but I could not make it smooth and easy to use because as the cube turned - the keys that handle the turning changed their purpose. Link to demo. The demo rotation is done by increasing euler angles and using Quaternion.Euler() to get a quaternion for Quaternion.Slerp().

The ideal rotating would be like below: the keys stay the same, no matter how the cube is rotated. A/D turn the cube from "left/right". W/S turn the cube "up/down". Q/E turns the cube's current face. enter image description here

But I have no idea where to start when making the above. How could the above be achieved?

EDIT Rioki's answer solved this question. I was previously using local rotation but changing it to world rotation fixed this. Link to demo.

share|improve this question
    
Looks like you're very close. Why not describe exactly what's not working? –  Byte56 Apr 23 '13 at 14:03
add comment

1 Answer 1

up vote 2 down vote accepted

This is somewhat simple. When working with quaternions, to alter the rotation you multiply the current orientation with the change you want to apply. Now there are two ways to to do it:

result = orig * change

and

result = change * orig

The nice thing about this is that the one rotates it in the local coordinate system and the other rotates it in the global coordinate system. (As Esa points out, the first rotates around the local coordinate system and the second rotates around the global one.)

I am not sure what you are trying to do, but slerp may be overkill, since it interpolates between two states. The way you describe the problem, is you check what keys are pressed and how much time elapsed since the last tick and then do something like:

if (is_pressed('W'))
    orientation = orientation * Quaternion.Euler(dt, 0, 0);
if (is_pressed('S'))
    orientation = orientation * Quaternion.Euler(-dt, 0, 0);
if (is_pressed('A'))
    orientation = orientation * Quaternion.Euler(0, dt, 0);
if (is_pressed('D'))
    orientation = orientation * Quaternion.Euler(0, -dt, 0);
share|improve this answer
    
<ul> -Local rotation => orientation * Quaternion.Euler<ul/> World rotation => Quaternion.Euler * orientation –  Esa Apr 24 '13 at 7:13
    
Battling with the formatting, but I think people can see what I meant :). –  Esa Apr 24 '13 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.