Thread: XNA quanternion multiple axis

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    62

    XNA quanternion multiple axis

    Hey all, I'm working on a static camera class (for my own use, if I ever complete it and have it working ill post here) in XNA.

    I made a working version using absolute vextors being rotated by matrices and keeping relative vecotrs for translations. What I didnt like is that I HAVE TO use the standard XYZ axis for rotation.

    What I decided to do was use quanternions to store current rotation,cthen buffer rotations each time some were done and add it up.

    The way I see it, it should look somewhat like this:
    (in the UpdateRotation part, plz dont mind any typos i make, this isnt the actual current code. Also on a small note I use dictionaries, so dont be surprised xD)
    Code:
    RelativeVectors["Up"] = Vector3.Transform(AbsoluteVectors["Up"], (Quanterion)CurrentRotation);
    //repeat for Look and Right relative vectors
    Quanternion Yaw = Quanternion.CreateFromAxisAngle(RelativeVectors["Up"], RotationBuffer["Yaw"]);
    //repeat for roll and pitch
    CurrentRotation = Quanternion.Contancate(CurrentRotation,(Yaw*Pitch*Roll));
    //clear the rotation buffer
    Whats happening right now tho, is that doing this exactly doesnt actually do anything, so I have to use standard axis anyway. If you need I can copy the whole class into here, but that may not be necessary xD, i hope.

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    62
    Ok all, I managed to find the answer myself!
    Seems that quaternion multiplications work differently then Matrix ones. So I did the combining in matrices then retransformed it. Here is the final content of the UpdateRotation() function:
    Code:
    Quaternion Yaw;
                Quaternion Pitch;
                Quaternion Roll;
                RelativeVectors["Look"] = Vector3.Transform(AbsoluteVectors["Look"], Matrix.CreateFromQuaternion(CameraRotation));
                RelativeVectors["Up"] = Vector3.Transform(AbsoluteVectors["Up"], Matrix.CreateFromQuaternion(CameraRotation));
                RelativeVectors["Right"] = Vector3.Transform(AbsoluteVectors["Right"], Matrix.CreateFromQuaternion(CameraRotation));
                Yaw = Quaternion.CreateFromAxisAngle(RelativeVectors["Up"], MathHelper.ToRadians(RotationBuffer["Yaw"]));
                Pitch = Quaternion.CreateFromAxisAngle(RelativeVectors["Right"], MathHelper.ToRadians(RotationBuffer["Pitch"]));
                Roll = Quaternion.CreateFromAxisAngle(RelativeVectors["Look"], MathHelper.ToRadians(RotationBuffer["Roll"]));
                Matrix temp = Matrix.CreateFromQuaternion(CameraRotation);
                Matrix temp2 = Matrix.CreateFromQuaternion(Yaw * Pitch * Roll);
                CameraRotation = Quaternion.CreateFromRotationMatrix(temp * temp2);
                StablilizeRotation();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving axis
    By Eman500 in forum C Programming
    Replies: 2
    Last Post: 02-25-2011, 06:22 PM
  2. How to move axis !
    By Fatima Rizwan in forum Windows Programming
    Replies: 3
    Last Post: 01-24-2010, 08:57 AM
  3. AXIS and C++
    By bman1176 in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2006, 11:00 AM
  4. Graph axis
    By fkheng in forum C Programming
    Replies: 2
    Last Post: 07-25-2003, 07:03 AM
  5. Rotation on Y axis?
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 01-13-2002, 12:22 PM

Tags for this Thread