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 have an existing quaternion (Java Quat4f). I would like to rotate this quaternion around an axis (i.e. 90 degrees around the x axis, 25 degrees around the y axis, 10 degrees around the z axis, 180 degrees around the y axis, etc.)

How can I rotate the existing quaternion around an axis?

Thank you!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

To combine rotations, I believe you canjust multiply that quaternion with a quaternion for each of the other axis rotations you require.

For example, in this simple (extension) method I wrote, I get the final quaternion by combining 3 quaternions for X, Y and Z rotations.

    //Takes in angles in degrees
    //Useful wiki page: http://www.ogre3d.org/tikiwiki/Euler+Angle+Class and http://www.ogre3d.org/tikiwiki/Euler+Angle+Class+Mogre
    public static Quaternion ToOrientation(this Vector3 vec)
    {
        Quaternion xRot = new Quaternion(Math.DegreesToRadians(vec.x), Vector3.UNIT_X);
        Quaternion yRot = new Quaternion(Math.DegreesToRadians(vec.y), Vector3.UNIT_Y);
        Quaternion zRot = new Quaternion(Math.DegreesToRadians(vec.z), Vector3.UNIT_Z);
        return xRot * yRot * zRot;
    }

I must admit my knowledge of quaternions is not amazing, so any expansions on this answer would be appreciated.

Good luck! :)

share|improve this answer

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.