Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How do you use Quaternions to do rotations

This topic is 5371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I wan't to do rotations with quaternions, but I do not understand quaternions. What I want to do is rotate a given amount, but only rotate a little portion of it at a time. I also want to be able to get the angle of a rotation. Here is some of the code I am using (however, I have little clue as to what I am doing in the main part):
void DirectionalCameraRotator::updateCamera(const FrameEvent &evt)
    long tmp;
    Real rotateFactor = rotationDegreesPerSecond * evt.timeSinceLastFrame;

    //update the camera on the Y axis

    tmp = input->getMouseRelativeX();
    if (invertRotations)
        //invert the sign if we ARE inverting rotations

        tmp ^= 0x80000000;
    if (tmp < 0)
        yaw(-rotateFactor); //cameraNode->yaw(-rotateFactor);

    if (tmp > 0)
        yaw(rotateFactor); //cameraNode->yaw(rotateFactor);

    //update the camera on the X axis

    tmp = input->getMouseRelativeY();
    if (!invertRotations)
        //invert the sign if we ARE NOT inverting rotations

        tmp ^= 0x80000000;
    if (tmp < 0)
        pitch(-rotateFactor); //cameraNode->pitch(-rotateFactor);

    if (tmp > 0)
        pitch(rotateFactor); //cameraNode->pitch(rotateFactor);



    //(so to speak)


    Real theta;
    Vector3 axis;
    Quaternion deltaRotation;

    //get the rotation

    rotations.ToAngleAxis(theta, axis);

    //restrict the rotation to the maximum

    if (Math::Abs(theta) > rotateFactor) {
        Real factor = rotateFactor / rotationDegreesPerSecond;
        deltaRotation = Quaternion::Slerp(factor, Quaternion::IDENTITY, rotations);
        rotations = rotations * deltaRotation.Inverse();
    } else {
        deltaRotation = rotations;
        rotations = Quaternion::IDENTITY;

    //set new rotation


u r what u bcome
[edited by - bcome on February 5, 2004 9:13:52 PM] [edited by - bcome on February 5, 2004 9:18:13 PM]

Share this post

Link to post
Share on other sites
yeah, start by reading the articles in the "Articles & Resources" section of this site on quaternions. there's enough there to get you understanding them farily well. Particularly the gamasutra article on quaterions is a great introductory article. Other than that, google for "quaternion tutorial" or something and read about it. you'll break your brain trying to just use quaternions in a zen way without any understanding of the math behind them. they are quirky and the only way to make your quaternion class work is to understand WHY they are quirky. things like order of operations are crucial in quaternions as is how modify them to represent new rotational states, etc. So read up.


[edited by - Palidine on February 5, 2004 11:45:50 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!