Jump to content
  • Advertisement

Archived

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

Drzzden

view matrix quaternion rotation

This topic is 5342 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

i want to rotate the view with quaternions...but somethings wrong with my code: -------------------------------------------------------- public void RotateCamera(float xAngle, float yAngle) { device.Transform.View = initialMatrix; Vector3 rightAxis = new Vector3(initialMatrix.M11, initialMatrix.M21, initialMatrix.M31); rightAxis.Normalize(); Vector3 upAxis = new Vector3(initialMatrix.M12, initialMatrix.M22, initialMatrix.M32); upAxis.Normalize(); Quaternion rotationRight = new Quaternion(rightAxis.X, rightAxis.Y, rightAxis.Z, xAngle); Quaternion rotationUp = new Quaternion(upAxis.X, upAxis.Y, upAxis.Z, yAngle); Quaternion rotation = Quaternion.Multiply(rotationRight, rotationUp); device.Transform.View *= Matrix.RotationQuaternion(rotation); } ------------------------------------------------- my idea: from the current view matrix, get the right vector (m11, m21, m31) and the up vector (m12, m22, m32)...just yaw and pitch, no roll...now i want to use quaternions to rotate about the right vector and the upvector and finally the view matrix about the product of both quaternions... language is c#...

Share this post


Link to post
Share on other sites
Advertisement
Why not do this?

Use the matrix to quaternion function to get the quaternion.

Create a rotation quaternion using the yawPitchRoll function.

Multiply them

and then convert it back to the rotation matrix.

That should do what you are looking for.

Share this post


Link to post
Share on other sites
If you''re multiplying the view matrix in place, couldn''t you just multiply it directly by the matrix generated by the quaternion?


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
@ataru

which matrix should i convert to a quaternion?...my problem ist the update of the view matrix: th camera rotates as long as the user presses the right mouse button...when he releases the mouse button, i have to update the view matrix, so i set the initialmatrix from the code to the actual view matrix...but: the control "flips" when i press the right mouse button again...so before for a left to right rotation i moved the mouse from left to right...now from right to left...and, after the update, the view "jumps" to another position...everything works fine as long as i rotate the view...

is the general concept right?...

Share this post


Link to post
Share on other sites
You convert your view matrix to a quaternion. And for each mouse press, multiply the rotation quaternion by the one obtained from the view.

Then convert it back into a matrix, and set that matrix as your view.

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!